react-native-navigation的迁移库

RNNViewControllerPresenterTest.m 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "RNNViewControllerPresenter.h"
  4. #import "UIViewController+RNNOptions.h"
  5. #import "RNNRootViewController.h"
  6. @interface RNNViewControllerPresenterTest : XCTestCase
  7. @property (nonatomic, strong) RNNViewControllerPresenter *uut;
  8. @property (nonatomic, strong) RNNNavigationOptions *options;
  9. @property (nonatomic, strong) UIViewController *bindedViewController;
  10. @property (nonatomic, strong) RNNReactComponentRegistry *componentRegistry;
  11. @end
  12. @implementation RNNViewControllerPresenterTest
  13. - (void)setUp {
  14. [super setUp];
  15. self.componentRegistry = [OCMockObject partialMockForObject:[RNNReactComponentRegistry new]];
  16. self.uut = [[RNNViewControllerPresenter alloc] initWithComponentRegistry:self.componentRegistry:[[RNNNavigationOptions alloc] initEmptyOptions]];
  17. self.bindedViewController = [OCMockObject partialMockForObject:[RNNRootViewController new]];
  18. [self.uut bindViewController:self.bindedViewController];
  19. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  20. }
  21. - (void)testApplyOptions_backgroundImageDefaultNilShouldNotAddSubview {
  22. [self.uut applyOptions:self.options];
  23. XCTAssertTrue((self.bindedViewController.view.subviews.count) == 0);
  24. }
  25. - (void)testApplyOptions_topBarPrefersLargeTitleDefaultFalse {
  26. [self.uut applyOptions:self.options];
  27. XCTAssertTrue(self.bindedViewController.navigationItem.largeTitleDisplayMode == UINavigationItemLargeTitleDisplayModeNever);
  28. }
  29. - (void)testApplyOptions_layoutBackgroundColorDefaultWhiteColor {
  30. [self.uut applyOptions:self.options];
  31. XCTAssertNil(self.bindedViewController.view.backgroundColor);
  32. }
  33. - (void)testApplyOptions_statusBarBlurDefaultFalse {
  34. [self.uut applyOptions:self.options];
  35. XCTAssertNil([self.bindedViewController.view viewWithTag:BLUR_STATUS_TAG]);
  36. }
  37. - (void)testApplyOptions_statusBarStyleDefaultStyle {
  38. [self.uut applyOptions:self.options];
  39. XCTAssertTrue([self.bindedViewController preferredStatusBarStyle] == UIStatusBarStyleDefault);
  40. }
  41. - (void)testApplyOptions_backButtonVisibleDefaultTrue {
  42. [self.uut applyOptions:self.options];
  43. XCTAssertFalse(self.bindedViewController.navigationItem.hidesBackButton);
  44. }
  45. - (void)testApplyOptions_drawBehindTabBarTrueWhenVisibleFalse {
  46. self.options.bottomTabs.visible = [[Bool alloc] initWithValue:@(0)];
  47. [[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:YES];
  48. [self.uut applyOptionsOnInit:self.options];
  49. [(id)self.bindedViewController verify];
  50. }
  51. - (void)testApplyOptions_setOverlayTouchOutsideIfHasValue {
  52. self.options.overlay.interceptTouchOutside = [[Bool alloc] initWithBOOL:YES];
  53. [[(id)self.bindedViewController expect] rnn_setInterceptTouchOutside:YES];
  54. [self.uut applyOptions:self.options];
  55. [(id)self.bindedViewController verify];
  56. }
  57. - (void)testBindViewControllerShouldCreateNavigationButtonsCreator {
  58. RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
  59. [presenter bindViewController:self.bindedViewController];
  60. XCTAssertNotNil(presenter.navigationButtons);
  61. }
  62. - (void)testApplyOptionsOnInit_shouldSetModalPresentetionStyleWithDefault {
  63. [[(id)self.bindedViewController expect] rnn_setModalPresentationStyle:UIModalPresentationFullScreen];
  64. [self.uut applyOptionsOnInit:self.options];
  65. [(id)self.bindedViewController verify];
  66. }
  67. - (void)testApplyOptionsOnInit_shouldSetModalTransitionStyleWithDefault {
  68. [[(id)self.bindedViewController expect] rnn_setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
  69. [self.uut applyOptionsOnInit:self.options];
  70. [(id)self.bindedViewController verify];
  71. }
  72. - (void)testApplyOptionsOnInit_shouldSetModalPresentetionStyleWithValue {
  73. self.options.modalPresentationStyle = [[Text alloc] initWithValue:@"overCurrentContext"];
  74. [[(id)self.bindedViewController expect] rnn_setModalPresentationStyle:UIModalPresentationOverCurrentContext];
  75. [self.uut applyOptionsOnInit:self.options];
  76. [(id)self.bindedViewController verify];
  77. }
  78. - (void)testApplyOptionsOnInit_shouldSetModalTransitionStyleWithValue {
  79. self.options.modalTransitionStyle = [[Text alloc] initWithValue:@"crossDissolve"];
  80. [[(id)self.bindedViewController expect] rnn_setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
  81. [self.uut applyOptionsOnInit:self.options];
  82. [(id)self.bindedViewController verify];
  83. }
  84. -(void)testApplyOptionsOnInit_TopBarDrawUnder_true {
  85. self.options.topBar.drawBehind = [[Bool alloc] initWithValue:@(1)];
  86. [[(id)self.bindedViewController expect] rnn_setDrawBehindTopBar:YES];
  87. [self.uut applyOptionsOnInit:self.options];
  88. [(id)self.bindedViewController verify];
  89. }
  90. -(void)testApplyOptionsOnInit_TopBarDrawUnder_false {
  91. self.options.topBar.drawBehind = [[Bool alloc] initWithValue:@(0)];
  92. [[(id)self.bindedViewController expect] rnn_setDrawBehindTopBar:NO];
  93. [self.uut applyOptionsOnInit:self.options];
  94. [(id)self.bindedViewController verify];
  95. }
  96. -(void)testApplyOptionsOnInit_BottomTabsDrawUnder_true {
  97. self.options.bottomTabs.drawBehind = [[Bool alloc] initWithValue:@(1)];
  98. [[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:YES];
  99. [self.uut applyOptionsOnInit:self.options];
  100. [(id)self.bindedViewController verify];
  101. }
  102. -(void)testApplyOptionsOnInit_BottomTabsDrawUnder_false {
  103. self.options.bottomTabs.drawBehind = [[Bool alloc] initWithValue:@(0)];
  104. [[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:NO];
  105. [self.uut applyOptionsOnInit:self.options];
  106. [(id)self.bindedViewController verify];
  107. }
  108. - (void)testReactViewShouldBeReleasedOnDealloc {
  109. RNNRootViewController* bindViewController = [RNNRootViewController new];
  110. bindViewController.layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"];
  111. [self.uut bindViewController:bindViewController];
  112. self.options.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"componentName"}];
  113. [[(id)self.componentRegistry expect] clearComponentsForParentId:self.uut.boundComponentId];
  114. self.uut = nil;
  115. [(id)self.componentRegistry verify];
  116. }
  117. - (void)testBindViewControllerShouldSetBindedComponentId {
  118. RNNRootViewController* bindViewController = [RNNRootViewController new];
  119. RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
  120. layoutInfo.componentId = @"componentId";
  121. bindViewController.layoutInfo = layoutInfo;
  122. [self.uut bindViewController:bindViewController];
  123. XCTAssertEqual(self.uut.boundComponentId, @"componentId");
  124. }
  125. - (void)testRenderComponentsCreateReactViewWithBindedComponentId {
  126. RNNRootViewController* bindedViewController = [RNNRootViewController new];
  127. RNNLayoutInfo* layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"];
  128. bindedViewController.layoutInfo = layoutInfo;
  129. [self.uut bindViewController:bindedViewController];
  130. self.options.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"titleComponent"}];
  131. [[(id)self.componentRegistry expect] createComponentIfNotExists:self.options.topBar.title.component parentComponentId:self.uut.boundComponentId reactViewReadyBlock:[OCMArg any]];
  132. [self.uut renderComponents:self.options perform:nil];
  133. [(id)self.componentRegistry verify];
  134. XCTAssertEqual(self.uut.boundComponentId, @"componentId");
  135. }
  136. - (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withTitle {
  137. Text* title = [[Text alloc] initWithValue:@"Title"];
  138. self.options.topBar.backButton.title = title;
  139. [[(id)self.bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:title.get];
  140. [self.uut applyOptionsOnWillMoveToParentViewController:self.options];
  141. [(id)self.bindedViewController verify];
  142. }
  143. - (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withHideTitle {
  144. Text* title = [[Text alloc] initWithValue:@"Title"];
  145. self.options.topBar.backButton.title = title;
  146. self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)];
  147. [[(id)self.bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:@""];
  148. [self.uut applyOptionsOnWillMoveToParentViewController:self.options];
  149. [(id)self.bindedViewController verify];
  150. }
  151. - (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withIcon {
  152. Image* image = [[Image alloc] initWithValue:[UIImage new]];
  153. self.options.topBar.backButton.icon = image;
  154. [[(id)self.bindedViewController expect] rnn_setBackButtonIcon:image.get withColor:nil title:nil];
  155. [self.uut applyOptionsOnWillMoveToParentViewController:self.options];
  156. [(id)self.bindedViewController verify];
  157. }
  158. - (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withDefaultValues {
  159. [[(id)self.bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:nil];
  160. [self.uut applyOptionsOnWillMoveToParentViewController:self.options];
  161. [(id)self.bindedViewController verify];
  162. }
  163. - (RNNLayoutInfo *)createLayoutInfoWithComponentId:(NSString *)componentId {
  164. RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
  165. layoutInfo.componentId = @"componentId";
  166. return layoutInfo;
  167. }
  168. @end