Skip to content

Commit

Permalink
Merge pull request nytimes#253 from jamesstout/fix-tests
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
craighowarth authored Apr 19, 2018
2 parents 64445c7 + 6caf4eb commit 5c4cf7f
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 68 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changes for users of the library currently on `develop`:
- A data source no longer has to handle out-of-bounds indexes ([#227](https://github.com/NYTimes/NYTPhotoViewer/pull/227))
- The data source is not retained ([#227](https://github.com/NYTimes/NYTPhotoViewer/pull/227))
- Respect safe areas for iOS 11 support
- Fixed some tests, added tests for NYTPhotoViewerSinglePhotoDataSource
- Fixed a strict warning and a subscripting bug in NYTPhotoViewerArrayDataSource.m

## [1.2.0](https://github.com/NYTimes/NYTPhotoViewer/releases/tag/1.2.0)

Expand Down
12 changes: 8 additions & 4 deletions NYTPhotoViewer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
1110840A1C875B5000699670 /* NYTPhotoViewer.h in Headers */ = {isa = PBXBuildFile; fileRef = 111084091C875B5000699670 /* NYTPhotoViewer.h */; settings = {ATTRIBUTES = (Public, ); }; };
111084111C875B5000699670 /* NYTPhotoViewer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 111084061C875B5000699670 /* NYTPhotoViewer.framework */; };
1110842D1C8767BA00699670 /* NYTPhotoCaptionViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 111084261C8767BA00699670 /* NYTPhotoCaptionViewTests.m */; };
1110842E1C8767BA00699670 /* NYTPhotosDataSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 111084271C8767BA00699670 /* NYTPhotosDataSourceTests.m */; };
1110842F1C8767BA00699670 /* NYTPhotosOverlayViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 111084281C8767BA00699670 /* NYTPhotosOverlayViewTests.m */; };
111084301C8767BA00699670 /* NYTPhotosViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 111084291C8767BA00699670 /* NYTPhotosViewControllerTests.m */; };
111084311C8767BA00699670 /* NYTPhotoTransitionAnimatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1110842A1C8767BA00699670 /* NYTPhotoTransitionAnimatorTests.m */; };
Expand Down Expand Up @@ -94,6 +93,8 @@
11FBDAFD1C877D9A00018169 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 11FBDAFB1C877D9A00018169 /* LaunchScreen.xib */; };
11FBDAFE1C877F5500018169 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 111084781C876A2B00699670 /* Assets.xcassets */; };
11FBDAFF1C877F8000018169 /* giphy.gif in Resources */ = {isa = PBXBuildFile; fileRef = 111084851C876B0400699670 /* giphy.gif */; };
1AFC4D301FE01B9000FDF949 /* NYTPhotoViewerArrayDataSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 111084271C8767BA00699670 /* NYTPhotoViewerArrayDataSourceTests.m */; };
1AFC4D321FE01EFA00FDF949 /* NYTPhotoViewerSinglePhotoDataSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AFC4D311FE01EFA00FDF949 /* NYTPhotoViewerSinglePhotoDataSourceTests.m */; };
9371A73C1E438B9C00A8F2EF /* Photo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9371A73B1E438B9C00A8F2EF /* Photo.swift */; };
9371A7441E438BCE00A8F2EF /* PhotoBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9371A7431E438BCE00A8F2EF /* PhotoBox.swift */; };
9371A7461E43D61E00A8F2EF /* PhotoViewerCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9371A7451E43D61E00A8F2EF /* PhotoViewerCoordinator.swift */; };
Expand Down Expand Up @@ -238,7 +239,7 @@
111084101C875B5000699670 /* NYTPhotoViewerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NYTPhotoViewerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
111084171C875B5000699670 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
111084261C8767BA00699670 /* NYTPhotoCaptionViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYTPhotoCaptionViewTests.m; sourceTree = "<group>"; };
111084271C8767BA00699670 /* NYTPhotosDataSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYTPhotosDataSourceTests.m; sourceTree = "<group>"; };
111084271C8767BA00699670 /* NYTPhotoViewerArrayDataSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYTPhotoViewerArrayDataSourceTests.m; sourceTree = "<group>"; };
111084281C8767BA00699670 /* NYTPhotosOverlayViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYTPhotosOverlayViewTests.m; sourceTree = "<group>"; };
111084291C8767BA00699670 /* NYTPhotosViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYTPhotosViewControllerTests.m; sourceTree = "<group>"; };
1110842A1C8767BA00699670 /* NYTPhotoTransitionAnimatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYTPhotoTransitionAnimatorTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -293,6 +294,7 @@
11FBDAEA1C877BD600018169 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
11FBDAF01C877C8B00018169 /* PhotosProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosProvider.swift; sourceTree = "<group>"; };
11FBDAFC1C877D9A00018169 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
1AFC4D311FE01EFA00FDF949 /* NYTPhotoViewerSinglePhotoDataSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYTPhotoViewerSinglePhotoDataSourceTests.m; sourceTree = "<group>"; };
9371A73B1E438B9C00A8F2EF /* Photo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Photo.swift; sourceTree = "<group>"; };
9371A7431E438BCE00A8F2EF /* PhotoBox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoBox.swift; sourceTree = "<group>"; };
9371A7451E43D61E00A8F2EF /* PhotoViewerCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoViewerCoordinator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -406,7 +408,8 @@
isa = PBXGroup;
children = (
111084261C8767BA00699670 /* NYTPhotoCaptionViewTests.m */,
111084271C8767BA00699670 /* NYTPhotosDataSourceTests.m */,
111084271C8767BA00699670 /* NYTPhotoViewerArrayDataSourceTests.m */,
1AFC4D311FE01EFA00FDF949 /* NYTPhotoViewerSinglePhotoDataSourceTests.m */,
111084281C8767BA00699670 /* NYTPhotosOverlayViewTests.m */,
111084291C8767BA00699670 /* NYTPhotosViewControllerTests.m */,
1110842A1C8767BA00699670 /* NYTPhotoTransitionAnimatorTests.m */,
Expand Down Expand Up @@ -843,14 +846,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1AFC4D301FE01B9000FDF949 /* NYTPhotoViewerArrayDataSourceTests.m in Sources */,
1110842D1C8767BA00699670 /* NYTPhotoCaptionViewTests.m in Sources */,
1110842F1C8767BA00699670 /* NYTPhotosOverlayViewTests.m in Sources */,
1110842E1C8767BA00699670 /* NYTPhotosDataSourceTests.m in Sources */,
111084311C8767BA00699670 /* NYTPhotoTransitionAnimatorTests.m in Sources */,
111084301C8767BA00699670 /* NYTPhotosViewControllerTests.m in Sources */,
111084841C876AAD00699670 /* NYTExamplePhoto.m in Sources */,
111084331C8767BA00699670 /* NYTScalingImageViewTests.m in Sources */,
111084321C8767BA00699670 /* NYTPhotoViewControllerTests.m in Sources */,
1AFC4D321FE01EFA00FDF949 /* NYTPhotoViewerSinglePhotoDataSourceTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion NYTPhotoViewer/NYTPhotoCaptionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ - (void)didMoveToSuperview {
- (void)layoutSubviews {
[super layoutSubviews];

void (^updateGradientFrame)() = ^{
void (^updateGradientFrame)(void) = ^{
self.gradientLayer.frame = self.layer.bounds;
};

Expand Down
2 changes: 1 addition & 1 deletion NYTPhotoViewer/NYTPhotoViewerArrayDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ - (NSInteger)indexOfPhoto:(id <NYTPhoto>)photo {
#pragma mark - Subscripting

- (id<NYTPhoto>)objectAtIndexedSubscript:(NSUInteger)idx {
return self.photos[idx];
return [self photoAtIndex:idx];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@
@import UIKit;
@import XCTest;

#import <NYTPhotoViewer/NYTPhotosDataSource.h>
#import "NYTExamplePhoto.h"
#import "NYTPhotoViewerArrayDataSource.h"

@interface NYTPhotosDataSourceTests : XCTestCase
@interface NYTPhotoViewerArrayDataSourceTests : XCTestCase

@end

@implementation NYTPhotosDataSourceTests
@implementation NYTPhotoViewerArrayDataSourceTests

- (void)testInitializerAcceptsNil {
XCTAssertNoThrow([[NYTPhotosDataSource alloc] initWithPhotos:nil]);
XCTAssertNoThrow([[NYTPhotoViewerArrayDataSource alloc] initWithPhotos:nil]);
}

- (void)testOutOfBoundsDoesNotCrash {
NYTPhotosDataSource *dataSource = [[NYTPhotosDataSource alloc] initWithPhotos:nil];
NYTPhotoViewerArrayDataSource *dataSource = [[NYTPhotoViewerArrayDataSource alloc] initWithPhotos:nil];
XCTAssertNoThrow(dataSource[1]);
}

- (void)testOutOfBoundsReturnsNil {
NYTPhotosDataSource *dataSource = [[NYTPhotosDataSource alloc] initWithPhotos:nil];
NYTPhotoViewerArrayDataSource *dataSource = [[NYTPhotoViewerArrayDataSource alloc] initWithPhotos:nil];
XCTAssertNil(dataSource[1]);
}

- (void)testValidIndexReturnsPhoto {
NYTPhotosDataSource *dataSource = [[NYTPhotosDataSource alloc] initWithPhotos:[self newTestPhotos]];
NYTPhotoViewerArrayDataSource *dataSource = [[NYTPhotoViewerArrayDataSource alloc] initWithPhotos:[self newTestPhotos]];
XCTAssertNotNil(dataSource[1]);
}

- (void)testValidIndexReturnsCorrectPhoto {
NSArray *photos = [self newTestPhotos];
NYTPhotosDataSource *dataSource = [[NYTPhotosDataSource alloc] initWithPhotos:photos];
NYTPhotoViewerArrayDataSource *dataSource = [[NYTPhotoViewerArrayDataSource alloc] initWithPhotos:photos];
XCTAssertEqualObjects(photos.firstObject, dataSource[0]);
}

Expand Down
64 changes: 64 additions & 0 deletions NYTPhotoViewerTests/NYTPhotoViewerSinglePhotoDataSourceTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// NYTPhotosDataSourceTests.m
// NYTPhotoViewer
//
// Created by Brian Capps on 2/26/15.
// Copyright (c) 2015 NYTimes. All rights reserved.
//

@import UIKit;
@import XCTest;

#import "NYTExamplePhoto.h"
#import "NYTPhotoViewerSinglePhotoDataSource.h"

@interface NYTPhotoViewerSinglePhotoDataSourceTests : XCTestCase

@end

@implementation NYTPhotoViewerSinglePhotoDataSourceTests

- (void)testInitializerAcceptsNil {
XCTAssertNoThrow([[NYTPhotoViewerSinglePhotoDataSource alloc] initWithPhoto:nil]);
}

- (void)testOutOfBoundsDoesNotCrash {
NYTPhotoViewerSinglePhotoDataSource *dataSource = [[NYTPhotoViewerSinglePhotoDataSource alloc] initWithPhoto:nil];
XCTAssertNoThrow([dataSource photoAtIndex:1]);
}

- (void)testOutOfBoundsReturnsNil {
NYTPhotoViewerSinglePhotoDataSource *dataSource = [[NYTPhotoViewerSinglePhotoDataSource alloc] initWithPhoto:nil];
XCTAssertNil([dataSource photoAtIndex:1]);
}

- (void)testValidIndexReturnsPhotoAtIndex {
NYTExamplePhoto *photo = [[NYTExamplePhoto alloc] init];
NYTPhotoViewerSinglePhotoDataSource *dataSource = [[NYTPhotoViewerSinglePhotoDataSource alloc] initWithPhoto:photo];
XCTAssertEqual(0, [dataSource indexOfPhoto:photo]);
}

- (void)testValidIndexReturnsPhoto {
NYTExamplePhoto *photo = [[NYTExamplePhoto alloc] init];
NYTPhotoViewerSinglePhotoDataSource *dataSource = [[NYTPhotoViewerSinglePhotoDataSource alloc] initWithPhoto:photo];
XCTAssertNotNil([dataSource photoAtIndex:1]);
}

- (void)testValidIndexReturnsCorrectPhoto {
NSArray *photos = [self newTestPhotos];
NYTPhotoViewerSinglePhotoDataSource *dataSource = [[NYTPhotoViewerSinglePhotoDataSource alloc] initWithPhoto:photos.firstObject];
XCTAssertEqualObjects(photos.firstObject, [dataSource photoAtIndex:0]);
}

- (NSArray *)newTestPhotos {
NSMutableArray *photos = [NSMutableArray array];

for (int i = 0; i < 5; i++) {
NYTExamplePhoto *photo = [[NYTExamplePhoto alloc] init];
[photos addObject:photo];
}

return photos;
}

@end
Loading

0 comments on commit 5c4cf7f

Please sign in to comment.