react-native-navigation的迁移库

RNNNavigationControllerTest.m 6.5KB

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