react-native-navigation的迁移库

RNNControllerFactoryTest.m 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. [super tearDown];
  24. }
  25. - (void)testCreateLayout_EmptyLayout {
  26. XCTAssertThrows([self.factory createLayoutAndSaveToStore:@{}]);
  27. }
  28. - (void)testCreateLayout_ContainerLayout {
  29. id ans = [self.factory createLayoutAndSaveToStore:
  30. @{@"id": @"cntId",
  31. @"type": @"Container",
  32. @"data": @{},
  33. @"children": @[]}];
  34. XCTAssertTrue([ans isMemberOfClass:[RNNRootViewController class]]);
  35. }
  36. - (void)testCreateLayout_ContainerStackLayout {
  37. id ans = [self.factory createLayoutAndSaveToStore:
  38. @{@"id": @"cntId",
  39. @"type": @"ContainerStack",
  40. @"data": @{},
  41. @"children": @[]}];
  42. XCTAssertTrue([ans isMemberOfClass:[UINavigationController class]]);
  43. }
  44. - (void)testCreateLayout_ContainerStackLayoutRecursive {
  45. UINavigationController* ans = (UINavigationController*) [self.factory createLayoutAndSaveToStore:
  46. @{@"id": @"cntId",
  47. @"type": @"ContainerStack",
  48. @"data": @{},
  49. @"children": @[
  50. @{@"id": @"cntId_2",
  51. @"type": @"Container",
  52. @"data": @{},
  53. @"children": @[]}]}];
  54. XCTAssertTrue([ans isMemberOfClass:[UINavigationController class]]);
  55. XCTAssertTrue(ans.childViewControllers.count == 1);
  56. XCTAssertTrue([ans.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  57. }
  58. - (void)testCreateLayout_BottomTabsLayout {
  59. UITabBarController* tabBar = (UITabBarController*) [self.factory createLayoutAndSaveToStore:
  60. @{
  61. @"id": @"cntId",
  62. @"type": @"BottomTabs",
  63. @"data": @{},
  64. @"children": @[
  65. @{@"id": @"cntId_2",
  66. @"type": @"ContainerStack",
  67. @"data": @{},
  68. @"children": @[
  69. @{@"id": @"cntId_3",
  70. @"type": @"Container",
  71. @"data": @{},
  72. @"children": @[]}]}]}];
  73. XCTAssertTrue([tabBar isMemberOfClass:[UITabBarController class]]);
  74. XCTAssertTrue(tabBar.childViewControllers.count == 1);
  75. XCTAssertTrue([tabBar.childViewControllers[0] isMemberOfClass:[UINavigationController class]]);
  76. UINavigationController *navController = tabBar.childViewControllers[0];
  77. XCTAssertTrue(navController.childViewControllers.count == 1);
  78. XCTAssertTrue([navController.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  79. }
  80. - (void)testCreateLayout_ContainerSideMenuLayoutCenterLeftRight {
  81. RNNSideMenuController *ans = (RNNSideMenuController*) [self.factory createLayoutAndSaveToStore:
  82. @{@"id": @"cntId",
  83. @"type": @"SideMenuRoot",
  84. @"data": @{},
  85. @"children": @[
  86. @{@"id": @"cntI_2",
  87. @"type": @"SideMenuCenter",
  88. @"data": @{},
  89. @"children": @[
  90. @{@"id": @"cntId_3",
  91. @"type": @"Container",
  92. @"data": @{},
  93. @"children": @[]}]},
  94. @{@"id": @"cntI_4",
  95. @"type": @"SideMenuLeft",
  96. @"data": @{},
  97. @"children": @[
  98. @{@"id": @"cntId_5",
  99. @"type": @"Container",
  100. @"data": @{},
  101. @"children": @[]}]},
  102. @{@"id": @"cntI_6",
  103. @"type": @"SideMenuRight",
  104. @"data": @{},
  105. @"children": @[
  106. @{@"id": @"cntId_7",
  107. @"type": @"Container",
  108. @"data": @{},
  109. @"children": @[]}]}]}];
  110. XCTAssertTrue([ans isMemberOfClass:[RNNSideMenuController class]]);
  111. XCTAssertTrue([ans isKindOfClass:[UIViewController class]]);
  112. XCTAssertTrue([ans.center isMemberOfClass:[RNNSideMenuChildVC class]]);
  113. RNNSideMenuChildVC *center = (RNNSideMenuChildVC*)ans.center;
  114. XCTAssertTrue(center.type == RNNSideMenuChildTypeCenter);
  115. XCTAssertTrue([center.child isMemberOfClass:[RNNRootViewController class]]);
  116. RNNSideMenuChildVC *left = (RNNSideMenuChildVC*)ans.left;
  117. XCTAssertTrue(left.type == RNNSideMenuChildTypeLeft);
  118. XCTAssertTrue([left.child isMemberOfClass:[RNNRootViewController class]]);
  119. RNNSideMenuChildVC *right = (RNNSideMenuChildVC*)ans.right;
  120. XCTAssertTrue(right.type == RNNSideMenuChildTypeRight);
  121. XCTAssertTrue([right.child isMemberOfClass:[RNNRootViewController class]]);
  122. }
  123. - (void)testCreateLayout_ContainerSideMenuLayoutCenterTabBar {
  124. RNNSideMenuController *ans = (RNNSideMenuController*) [self.factory createLayoutAndSaveToStore:
  125. @{@"id": @"cntId",
  126. @"type": @"SideMenuRoot",
  127. @"data": @{},
  128. @"children": @[
  129. @{@"id": @"cntI_2",
  130. @"type": @"SideMenuCenter",
  131. @"data": @{},
  132. @"children": @[
  133. @{@"id": @"cntId_3",
  134. @"type": @"BottomTabs",
  135. @"data": @{},
  136. @"children": @[
  137. @{@"id": @"cntId_4",
  138. @"type": @"ContainerStack",
  139. @"data": @{},
  140. @"children": @[
  141. @{@"id": @"cntId_2",
  142. @"type": @"Container",
  143. @"data": @{},
  144. @"children": @[]}]}]}]}]}
  145. ];
  146. XCTAssertTrue([ans isMemberOfClass:[RNNSideMenuController class]]);
  147. XCTAssertTrue([ans isKindOfClass:[UIViewController class]]);
  148. XCTAssertTrue([ans.center isMemberOfClass:[RNNSideMenuChildVC class]]);
  149. RNNSideMenuChildVC *center = (RNNSideMenuChildVC*)ans.center;
  150. XCTAssertTrue(center.type == RNNSideMenuChildTypeCenter);
  151. XCTAssertTrue([center.child isMemberOfClass:[UITabBarController class]]);
  152. UITabBarController *tabbBar = (UITabBarController*)center.child;
  153. XCTAssertTrue(tabbBar.viewControllers.count == 1);
  154. UINavigationController *navController = (UINavigationController*)(tabbBar.viewControllers[0]);
  155. XCTAssertTrue([navController isMemberOfClass:[UINavigationController class]]);
  156. XCTAssertTrue(navController.viewControllers.count == 1);
  157. RNNRootViewController *rootViewController = (RNNRootViewController*)navController.viewControllers[0];
  158. XCTAssertTrue([rootViewController isMemberOfClass:[RNNRootViewController class]]);
  159. }
  160. - (void)testCreateLayout_addContainerToStore {
  161. NSString *containerId = @"cntId";
  162. UIViewController *ans = [self.factory createLayoutAndSaveToStore:
  163. @{@"id": containerId,
  164. @"type": @"Container",
  165. @"data": @{},
  166. @"children": @[]}];
  167. UIViewController *storeAns = [self.store findContainerForId:containerId];
  168. XCTAssertEqualObjects(ans, storeAns);
  169. }
  170. @end