react-native-navigation的迁移库

RNNControllerFactoryTest.m 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // RNNControllerFactoryTest.m
  3. // playground
  4. //
  5. // Created by Ran Greenberg on 08/02/2017.
  6. // Copyright © 2017 Wix. All rights reserved.
  7. //
  8. #import <XCTest/XCTest.h>
  9. #import "RNNControllerFactory.h"
  10. @interface RNNControllerFactoryTest : XCTestCase
  11. @property (nonatomic, strong) id<RNNRootViewCreator> creator;
  12. @property (nonatomic, strong) RNNControllerFactory *factory;
  13. @property (nonatomic, strong) RNNStore *store;
  14. @end
  15. @implementation RNNControllerFactoryTest
  16. - (void)setUp {
  17. [super setUp];
  18. self.creator = nil;
  19. self.store = [RNNStore new];
  20. self.factory = [[RNNControllerFactory alloc] initWithRootViewCreator:self.creator store:self.store];
  21. }
  22. - (void)tearDown {
  23. // Put teardown code here. This method is called after the invocation of each test method in the class.
  24. [super tearDown];
  25. }
  26. - (void)testCreateLayout_EmptyLayout {
  27. XCTAssertThrows([self.factory createLayoutAndSaveToStore:@{}]);
  28. }
  29. - (void)testCreateLayout_ContainerLayout {
  30. id ans = [self.factory createLayoutAndSaveToStore:
  31. @{@"id": @"cntId",
  32. @"type": @"Container",
  33. @"data": @{},
  34. @"children": @[]}];
  35. XCTAssertTrue([ans isMemberOfClass:[RNNRootViewController class]]);
  36. }
  37. - (void)testCreateLayout_ContainerStackLayout {
  38. id ans = [self.factory createLayoutAndSaveToStore:
  39. @{@"id": @"cntId",
  40. @"type": @"ContainerStack",
  41. @"data": @{},
  42. @"children": @[]}];
  43. XCTAssertTrue([ans isMemberOfClass:[UINavigationController class]]);
  44. }
  45. - (void)testCreateLayout_ContainerStackLayoutRecursive {
  46. UINavigationController* ans = (UINavigationController*) [self.factory createLayoutAndSaveToStore:
  47. @{@"id": @"cntId",
  48. @"type": @"ContainerStack",
  49. @"data": @{},
  50. @"children": @[
  51. @{@"id": @"cntId_2",
  52. @"type": @"Container",
  53. @"data": @{},
  54. @"children": @[]}]}];
  55. XCTAssertTrue([ans isMemberOfClass:[UINavigationController class]]);
  56. XCTAssertTrue(ans.childViewControllers.count == 1);
  57. XCTAssertTrue([ans.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  58. }
  59. - (void)testCreateLayout_BottomTabsLayout {
  60. UITabBarController* tabBar = (UITabBarController*) [self.factory createLayoutAndSaveToStore:
  61. @{
  62. @"id": @"cntId",
  63. @"type": @"BottomTabs",
  64. @"data": @{},
  65. @"children": @[
  66. @{@"id": @"cntId_2",
  67. @"type": @"ContainerStack",
  68. @"data": @{},
  69. @"children": @[
  70. @{@"id": @"cntId_3",
  71. @"type": @"Container",
  72. @"data": @{},
  73. @"children": @[]}]}]}];
  74. XCTAssertTrue([tabBar isMemberOfClass:[UITabBarController class]]);
  75. XCTAssertTrue(tabBar.childViewControllers.count == 1);
  76. XCTAssertTrue([tabBar.childViewControllers[0] isMemberOfClass:[UINavigationController class]]);
  77. UINavigationController *navController = tabBar.childViewControllers[0];
  78. XCTAssertTrue(navController.childViewControllers.count == 1);
  79. XCTAssertTrue([navController.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  80. }
  81. - (void)testCreateLayout_ContainerSideMenuLayoutCenterLeftRight {
  82. RNNSideMenuController *ans = (RNNSideMenuController*) [self.factory createLayoutAndSaveToStore:
  83. @{@"id": @"cntId",
  84. @"type": @"SideMenuRoot",
  85. @"data": @{},
  86. @"children": @[
  87. @{@"id": @"cntI_2",
  88. @"type": @"SideMenuCenter",
  89. @"data": @{},
  90. @"children": @[
  91. @{@"id": @"cntId_3",
  92. @"type": @"Container",
  93. @"data": @{},
  94. @"children": @[]}]},
  95. @{@"id": @"cntI_4",
  96. @"type": @"SideMenuLeft",
  97. @"data": @{},
  98. @"children": @[
  99. @{@"id": @"cntId_5",
  100. @"type": @"Container",
  101. @"data": @{},
  102. @"children": @[]}]},
  103. @{@"id": @"cntI_6",
  104. @"type": @"SideMenuRight",
  105. @"data": @{},
  106. @"children": @[
  107. @{@"id": @"cntId_7",
  108. @"type": @"Container",
  109. @"data": @{},
  110. @"children": @[]}]}]}];
  111. XCTAssertTrue([ans isMemberOfClass:[RNNSideMenuController class]]);
  112. XCTAssertTrue([ans isKindOfClass:[UIViewController class]]);
  113. XCTAssertTrue([ans.center isMemberOfClass:[RNNSideMenuChildVC class]]);
  114. RNNSideMenuChildVC *center = (RNNSideMenuChildVC*)ans.center;
  115. XCTAssertTrue(center.type == RNNSideMenuChildTypeCenter);
  116. XCTAssertTrue([center.child isMemberOfClass:[RNNRootViewController class]]);
  117. RNNSideMenuChildVC *left = (RNNSideMenuChildVC*)ans.left;
  118. XCTAssertTrue(left.type == RNNSideMenuChildTypeLeft);
  119. XCTAssertTrue([left.child isMemberOfClass:[RNNRootViewController class]]);
  120. RNNSideMenuChildVC *right = (RNNSideMenuChildVC*)ans.right;
  121. XCTAssertTrue(right.type == RNNSideMenuChildTypeRight);
  122. XCTAssertTrue([right.child isMemberOfClass:[RNNRootViewController class]]);
  123. }
  124. - (void)testCreateLayout_ContainerSideMenuLayoutCenterTabBar {
  125. RNNSideMenuController *ans = (RNNSideMenuController*) [self.factory createLayoutAndSaveToStore:
  126. @{@"id": @"cntId",
  127. @"type": @"SideMenuRoot",
  128. @"data": @{},
  129. @"children": @[
  130. @{@"id": @"cntI_2",
  131. @"type": @"SideMenuCenter",
  132. @"data": @{},
  133. @"children": @[
  134. @{@"id": @"cntId_3",
  135. @"type": @"BottomTabs",
  136. @"data": @{},
  137. @"children": @[
  138. @{@"id": @"cntId_4",
  139. @"type": @"ContainerStack",
  140. @"data": @{},
  141. @"children": @[
  142. @{@"id": @"cntId_2",
  143. @"type": @"Container",
  144. @"data": @{},
  145. @"children": @[]}]}]}]}]}
  146. ];
  147. XCTAssertTrue([ans isMemberOfClass:[RNNSideMenuController class]]);
  148. XCTAssertTrue([ans isKindOfClass:[UIViewController class]]);
  149. XCTAssertTrue([ans.center isMemberOfClass:[RNNSideMenuChildVC class]]);
  150. RNNSideMenuChildVC *center = (RNNSideMenuChildVC*)ans.center;
  151. XCTAssertTrue(center.type == RNNSideMenuChildTypeCenter);
  152. XCTAssertTrue([center.child isMemberOfClass:[UITabBarController class]]);
  153. UITabBarController *tabbBar = (UITabBarController*)center.child;
  154. XCTAssertTrue(tabbBar.viewControllers.count == 1);
  155. UINavigationController *navController = (UINavigationController*)(tabbBar.viewControllers[0]);
  156. XCTAssertTrue([navController isMemberOfClass:[UINavigationController class]]);
  157. XCTAssertTrue(navController.viewControllers.count == 1);
  158. RNNRootViewController *rootViewController = (RNNRootViewController*)navController.viewControllers[0];
  159. XCTAssertTrue([rootViewController isMemberOfClass:[RNNRootViewController class]]);
  160. }
  161. - (void)testCreateLayout_addContainerToStore {
  162. NSString *containerId = @"cntId";
  163. UIViewController *ans = [self.factory createLayoutAndSaveToStore:
  164. @{@"id": containerId,
  165. @"type": @"Container",
  166. @"data": @{},
  167. @"children": @[]}];
  168. UIViewController *storeAns = [self.store findContainerForId:containerId];
  169. XCTAssertEqualObjects(ans, storeAns);
  170. }
  171. @end