react-native-navigation的迁移库

RNNControllerFactoryTest.m 7.3KB

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