react-native-navigation的迁移库

RNNNavigationControllerTest.m 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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)testGetLeafViewController_shouldReturnTopViewController {
  41. XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
  42. }
  43. - (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle {
  44. self.uut.getCurrentChild.resolveOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
  45. XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getCurrentChild.preferredStatusBarStyle);
  46. }
  47. - (void)testPopGestureEnabled_false {
  48. NSNumber* popGestureEnabled = @(0);
  49. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  50. options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled];
  51. self.uut = [self createNavigationControllerWithOptions:options];
  52. [self.uut viewWillAppear:false];
  53. XCTAssertFalse(self.uut.interactivePopGestureRecognizer.enabled);
  54. }
  55. - (void)testPopGestureEnabled_true {
  56. NSNumber* popGestureEnabled = @(1);
  57. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  58. options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled];
  59. self.uut = [self createNavigationControllerWithOptions:options];
  60. [self.uut onChildWillAppear];
  61. XCTAssertTrue(self.uut.interactivePopGestureRecognizer.enabled);
  62. }
  63. - (void)testRootBackgroundImage {
  64. UIImage* rootBackgroundImage = [[UIImage alloc] init];
  65. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  66. options.rootBackgroundImage = [[Image alloc] initWithValue:rootBackgroundImage];
  67. self.uut = [self createNavigationControllerWithOptions:options];
  68. [self.uut onChildWillAppear];
  69. XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:rootBackgroundImage]);
  70. }
  71. - (void)testTopBarBackgroundClipToBounds_true {
  72. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  73. options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(1)];
  74. self.uut = [self createNavigationControllerWithOptions:options];
  75. [self.uut onChildWillAppear];
  76. XCTAssertTrue(self.uut.navigationBar.clipsToBounds);
  77. }
  78. - (void)testTopBarBackgroundClipToBounds_false {
  79. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  80. options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(0)];
  81. self.uut = [self createNavigationControllerWithOptions:options];
  82. XCTAssertFalse(self.uut.navigationController.navigationBar.clipsToBounds);
  83. }
  84. - (void)testSupportedOrientationsShouldReturnCurrentChildSupportedOrientations {
  85. XCTAssertEqual(self.uut.supportedInterfaceOrientations, self.uut.getCurrentChild.supportedInterfaceOrientations);
  86. }
  87. - (void)testPopViewControllerReturnLastChildViewController {
  88. RNNNavigationController* uut = [RNNNavigationController new];
  89. [uut setViewControllers:@[_vc1, _vc2]];
  90. XCTAssertEqual([uut popViewControllerAnimated:NO], _vc2);
  91. }
  92. - (void)testPopViewControllerSetTopBarBackgroundForPoppingViewController {
  93. _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
  94. [_vc1 overrideOptions:_options];
  95. [self.uut popViewControllerAnimated:NO];
  96. XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.barTintColor);
  97. }
  98. - (void)testPopViewControllerSetDefaultTopBarBackgroundForPoppingViewController {
  99. _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
  100. [_vc1 setDefaultOptions:_options];
  101. [self.uut popViewControllerAnimated:NO];
  102. XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.barTintColor);
  103. }
  104. - (void)testPopViewControllerShouldInvokeApplyOptionsBeforePoppingForDestinationViewController {
  105. RNNNavigationController* uut = [RNNNavigationController new];
  106. [uut setViewControllers:@[_vc1, _vc2]];
  107. [[(id)uut.presenter expect] applyOptionsBeforePopping:[OCMArg any]];
  108. [uut popViewControllerAnimated:NO];
  109. [(id)uut.presenter verify];
  110. }
  111. - (void)testOverrideOptionsShouldOverrideOptionsState {
  112. RNNNavigationOptions* overrideOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  113. [(RNNNavigationOptions*)[(id)self.uut.options expect] overrideOptions:overrideOptions];
  114. [self.uut overrideOptions:overrideOptions];
  115. [(id)self.uut.options verify];
  116. }
  117. - (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
  118. return [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator childViewControllers:@[_vc1] options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init]];
  119. }
  120. @end