react-native-navigation的迁移库

RNNNavigationControllerTest.m 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "RNNNavigationController.h"
  4. #import "RNNRootViewController.h"
  5. #import "RNNTestRootViewCreator.h"
  6. @interface RNNNavigationControllerTest : XCTestCase
  7. @property (nonatomic, strong) RNNNavigationController *uut;
  8. @end
  9. @implementation RNNNavigationControllerTest {
  10. RNNRootViewController* _vc1;
  11. id _vc2Mock;
  12. RNNRootViewController* _vc2;
  13. UIViewController* _vc3;
  14. RNNNavigationOptions* _options;
  15. RNNTestRootViewCreator* _creator;
  16. }
  17. - (void)setUp {
  18. [super setUp];
  19. _creator = [[RNNTestRootViewCreator alloc] init];
  20. _vc1 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[OCMockObject partialMockForObject:[[RNNViewControllerPresenter alloc] init]] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
  21. _vc2 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
  22. _vc2Mock = [OCMockObject partialMockForObject:_vc2];
  23. _vc3 = [UIViewController new];
  24. _options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
  25. self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator childViewControllers:@[_vc1, _vc2] options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]]];
  26. }
  27. - (void)testInitWithLayoutInfo_shouldBindPresenter {
  28. XCTAssertNotNil(self.uut.presenter);
  29. }
  30. - (void)testInitWithLayoutInfo_shouldSetMultipleViewControllers {
  31. self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator childViewControllers:@[_vc1, _vc2] options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNViewControllerPresenter alloc] init]];
  32. XCTAssertTrue(self.uut.viewControllers.count == 2);
  33. }
  34. - (void)testChildViewControllerForStatusBarStyle_shouldReturnTopViewController {
  35. XCTAssertTrue(self.uut.childViewControllerForStatusBarStyle == self.uut.topViewController);
  36. }
  37. - (void)testCurrentChild_shouldReturnTopViewController {
  38. XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
  39. }
  40. - (void)testCurrentLeaf_shouldReturnCurrentChildLeaf {
  41. [[_vc2Mock expect] getCurrentLeaf];
  42. [self.uut getCurrentLeaf];
  43. [_vc2Mock verify];
  44. }
  45. - (void)testGetLeafViewController_shouldReturnTopViewController {
  46. XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
  47. }
  48. - (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle {
  49. self.uut.getCurrentChild.resolveOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
  50. XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getCurrentChild.preferredStatusBarStyle);
  51. }
  52. - (void)testPopGestureEnabled_false {
  53. NSNumber* popGestureEnabled = @(0);
  54. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  55. options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled];
  56. self.uut = [self createNavigationControllerWithOptions:options];
  57. [self.uut viewWillAppear:false];
  58. XCTAssertFalse(self.uut.interactivePopGestureRecognizer.enabled);
  59. }
  60. - (void)testPopGestureEnabled_true {
  61. NSNumber* popGestureEnabled = @(1);
  62. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  63. options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled];
  64. self.uut = [self createNavigationControllerWithOptions:options];
  65. [self.uut onChildWillAppear];
  66. XCTAssertTrue(self.uut.interactivePopGestureRecognizer.enabled);
  67. }
  68. - (void)testRootBackgroundImage {
  69. UIImage* rootBackgroundImage = [[UIImage alloc] init];
  70. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  71. options.rootBackgroundImage = [[Image alloc] initWithValue:rootBackgroundImage];
  72. self.uut = [self createNavigationControllerWithOptions:options];
  73. [self.uut onChildWillAppear];
  74. XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:rootBackgroundImage]);
  75. }
  76. - (void)testTopBarBackgroundClipToBounds_true {
  77. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  78. options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(1)];
  79. self.uut = [self createNavigationControllerWithOptions:options];
  80. [self.uut onChildWillAppear];
  81. XCTAssertTrue(self.uut.navigationBar.clipsToBounds);
  82. }
  83. - (void)testTopBarBackgroundClipToBounds_false {
  84. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  85. options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(0)];
  86. self.uut = [self createNavigationControllerWithOptions:options];
  87. XCTAssertFalse(self.uut.navigationController.navigationBar.clipsToBounds);
  88. }
  89. - (void)testSupportedOrientationsShouldReturnCurrentChildSupportedOrientations {
  90. XCTAssertEqual(self.uut.supportedInterfaceOrientations, self.uut.getCurrentChild.supportedInterfaceOrientations);
  91. }
  92. - (void)testPopViewControllerReturnLastChildViewController {
  93. RNNNavigationController* uut = [RNNNavigationController new];
  94. [uut setViewControllers:@[_vc1, _vc2]];
  95. XCTAssertEqual([uut popViewControllerAnimated:NO], _vc2);
  96. }
  97. - (void)testPopViewControllerSetTopBarBackgroundForPoppingViewController {
  98. _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
  99. [_vc1 overrideOptions:_options];
  100. [self.uut popViewControllerAnimated:NO];
  101. XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.barTintColor);
  102. }
  103. - (void)testPopViewControllerSetDefaultTopBarBackgroundForPoppingViewController {
  104. _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
  105. [_vc1 setDefaultOptions:_options];
  106. [self.uut popViewControllerAnimated:NO];
  107. XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.barTintColor);
  108. }
  109. - (void)testPopViewControllerShouldInvokeApplyOptionsBeforePoppingForDestinationViewController {
  110. RNNNavigationController* uut = [RNNNavigationController new];
  111. [uut setViewControllers:@[_vc1, _vc2]];
  112. [[(id)uut.presenter expect] applyOptionsBeforePopping:[OCMArg any]];
  113. [uut popViewControllerAnimated:NO];
  114. [(id)uut.presenter verify];
  115. }
  116. - (void)testOverrideOptionsShouldOverrideOptionsState {
  117. RNNNavigationOptions* overrideOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  118. [(RNNNavigationOptions*)[(id)self.uut.options expect] overrideOptions:overrideOptions];
  119. [self.uut overrideOptions:overrideOptions];
  120. [(id)self.uut.options verify];
  121. }
  122. - (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
  123. return [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator childViewControllers:@[_vc1] options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init]];
  124. }
  125. @end