Skip to content

Commit

Permalink
Add basic tests for dismissal user-initiated flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cdzombak committed Jan 26, 2016
1 parent f41d2dc commit 2b5ccdd
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Example/Tests/NYTPhotosViewControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@
@import UIKit;
@import XCTest;

#import <OCMock/OCMock.h>

#import <NYTPhotoViewer/NYTPhotosViewController.h>
#import "NYTExamplePhoto.h"

@interface NYTPhotosViewControllerTests : XCTestCase
@end

@interface NYTPhotosViewController (Testing)

- (void)dismissViewControllerAnimated:(BOOL)animated userInitiated:(BOOL)isUserInitiated completion:(void (^)(void))completion;
- (void)didPanWithGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer;
- (void)doneButtonTapped:(id)sender;

@end

@implementation NYTPhotosViewControllerTests

- (void)testPanGestureRecognizerExistsAfterInitialization {
Expand Down Expand Up @@ -211,6 +221,45 @@ - (void)testPageViewIsntLoadedAfterInit {
XCTAssertFalse(photosViewController.pageViewController.isViewLoaded);
}

- (void)testDoneButtonDismissalUserInitiatedFlagIsTrue {
NSArray *photos = [self newTestPhotos];
NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:photos];

id photosVCMock = OCMPartialMock(photosViewController);
OCMExpect([photosVCMock dismissViewControllerAnimated:[OCMArg isEqual:OCMOCK_VALUE(YES)] userInitiated:[OCMArg isEqual:OCMOCK_VALUE(YES)] completion:[OCMArg isNil]]);

[photosViewController doneButtonTapped:nil];

OCMVerifyAll(photosVCMock);
}

- (void)testGestureBasedDismissalUserInitiatedFlagIsTrue {
NSArray *photos = [self newTestPhotos];
NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:photos];

id photosVCMock = OCMPartialMock(photosViewController);
OCMExpect([photosVCMock dismissViewControllerAnimated:[OCMArg isEqual:OCMOCK_VALUE(YES)] userInitiated:[OCMArg isEqual:OCMOCK_VALUE(YES)] completion:[OCMArg isNil]]);

id gestureRecognizerMock = OCMClassMock([UIPanGestureRecognizer class]);
OCMStub([gestureRecognizerMock state]).andReturn(UIGestureRecognizerStateBegan);

[photosViewController didPanWithGestureRecognizer:gestureRecognizerMock];

OCMVerifyAll(photosVCMock);
}

- (void)testProgrammaticDismissalUserInitiatedFlagIsFalse {
NSArray *photos = [self newTestPhotos];
NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:photos];

id photosVCMock = OCMPartialMock(photosViewController);
OCMExpect([photosVCMock dismissViewControllerAnimated:[OCMArg isEqual:OCMOCK_VALUE(YES)] userInitiated:[OCMArg isEqual:OCMOCK_VALUE(NO)] completion:[OCMArg isNil]]);

[photosViewController dismissViewControllerAnimated:YES completion:nil];

OCMVerifyAll(photosVCMock);
}

#pragma mark - Helpers

- (NSArray *)newTestPhotos {
Expand Down

0 comments on commit 2b5ccdd

Please sign in to comment.