123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- #import <XCTest/XCTest.h>
- #import <OCMock/OCMock.h>
- #import "RNNNavigationController.h"
- #import "RNNRootViewController.h"
-
- @interface RNNNavigationControllerTest : XCTestCase
-
- @property (nonatomic, strong) RNNNavigationController *uut;
-
- @end
-
- @implementation RNNNavigationControllerTest {
- RNNRootViewController* _vc1;
- id _vc2Mock;
- RNNRootViewController* _vc2;
- UIViewController* _vc3;
- RNNNavigationOptions* _options;
- }
-
- - (void)setUp {
- [super setUp];
-
- _vc1 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[OCMockObject partialMockForObject:[[RNNViewControllerPresenter alloc] init]] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
- _vc2 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
- _vc2Mock = [OCMockObject partialMockForObject:_vc2];
- _vc3 = [UIViewController new];
- _options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
- self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1, _vc2] options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]]];
- }
-
- - (void)testInitWithLayoutInfo_shouldBindPresenter {
- XCTAssertNotNil(self.uut.presenter);
- }
-
- - (void)testInitWithLayoutInfo_shouldSetMultipleViewControllers {
- self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1, _vc2] options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNViewControllerPresenter alloc] init]];
- XCTAssertTrue(self.uut.viewControllers.count == 2);
- }
-
- - (void)testChildViewControllerForStatusBarStyle_shouldReturnTopViewController {
- XCTAssertTrue(self.uut.childViewControllerForStatusBarStyle == self.uut.topViewController);
- }
-
- - (void)testCurrentChild_shouldReturnTopViewController {
- XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
- }
-
- - (void)testCurrentLeaf_shouldReturnCurrentChildLeaf {
- [[_vc2Mock expect] getCurrentLeaf];
- [self.uut getCurrentLeaf];
- [_vc2Mock verify];
- }
-
- - (void)testGetLeafViewController_shouldReturnTopViewController {
- XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
- }
-
- - (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle {
- self.uut.getCurrentChild.resolveOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
- XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getCurrentChild.preferredStatusBarStyle);
- }
-
- - (void)testPopGestureEnabled_false {
- NSNumber* popGestureEnabled = @(0);
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
- options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled];
-
- self.uut = [self createNavigationControllerWithOptions:options];
- [self.uut viewWillAppear:false];
-
- XCTAssertFalse(self.uut.interactivePopGestureRecognizer.enabled);
- }
-
- - (void)testPopGestureEnabled_true {
- NSNumber* popGestureEnabled = @(1);
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
- options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled];
-
- self.uut = [self createNavigationControllerWithOptions:options];
- [self.uut onChildWillAppear];
-
- XCTAssertTrue(self.uut.interactivePopGestureRecognizer.enabled);
- }
-
- - (void)testRootBackgroundImage {
- UIImage* rootBackgroundImage = [[UIImage alloc] init];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
- options.rootBackgroundImage = [[Image alloc] initWithValue:rootBackgroundImage];
-
- self.uut = [self createNavigationControllerWithOptions:options];
- [self.uut onChildWillAppear];
-
- XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:rootBackgroundImage]);
- }
-
- - (void)testTopBarBackgroundClipToBounds_true {
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
- options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(1)];
-
- self.uut = [self createNavigationControllerWithOptions:options];
- [self.uut onChildWillAppear];
-
- XCTAssertTrue(self.uut.navigationBar.clipsToBounds);
- }
-
- - (void)testTopBarBackgroundClipToBounds_false {
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
- options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(0)];
-
- self.uut = [self createNavigationControllerWithOptions:options];
-
- XCTAssertFalse(self.uut.navigationController.navigationBar.clipsToBounds);
- }
-
- - (void)testSupportedOrientationsShouldReturnCurrentChildSupportedOrientations {
- XCTAssertEqual(self.uut.supportedInterfaceOrientations, self.uut.getCurrentChild.supportedInterfaceOrientations);
- }
-
- - (void)testPopViewControllerReturnLastChildViewController {
- RNNNavigationController* uut = [RNNNavigationController new];
- [uut setViewControllers:@[_vc1, _vc2]];
- XCTAssertEqual([uut popViewControllerAnimated:NO], _vc2);
- }
-
- - (void)testPopViewControllerSetTopBarBackgroundForPoppingViewController {
- _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
- [_vc1 overrideOptions:_options];
-
- [self.uut popViewControllerAnimated:NO];
- XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.barTintColor);
- }
-
- - (void)testPopViewControllerSetDefaultTopBarBackgroundForPoppingViewController {
- _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
- [_vc1 setDefaultOptions:_options];
-
- [self.uut popViewControllerAnimated:NO];
- XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.barTintColor);
- }
-
- - (void)testPopViewControllerShouldInvokeApplyOptionsBeforePoppingForDestinationViewController {
- RNNNavigationController* uut = [RNNNavigationController new];
- [uut setViewControllers:@[_vc1, _vc2]];
-
- [[(id)uut.presenter expect] applyOptionsBeforePopping:[OCMArg any]];
-
- [uut popViewControllerAnimated:NO];
-
- [(id)uut.presenter verify];
- }
-
- - (void)testOverrideOptionsShouldOverrideOptionsState {
- RNNNavigationOptions* overrideOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
- [(RNNNavigationOptions*)[(id)self.uut.options expect] overrideOptions:overrideOptions];
- [self.uut overrideOptions:overrideOptions];
- [(id)self.uut.options verify];
- }
-
- - (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
- return [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1] options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init]];
- }
-
- @end
|