react-native-navigation的迁移库

RNNControllerFactoryTest.m 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #import <XCTest/XCTest.h>
  2. #import "RNNControllerFactory.h"
  3. #import "RNNRootViewController.h"
  4. #import "RNNSideMenuController.h"
  5. #import "RNNSideMenuChildVC.h"
  6. #import "RNNNavigationController.h"
  7. #import "RNNTabBarController.h"
  8. #import "RNNSplitViewController.h"
  9. @interface RNNControllerFactoryTest : XCTestCase
  10. @property (nonatomic, strong) id<RNNRootViewCreator> creator;
  11. @property (nonatomic, strong) RNNControllerFactory *factory;
  12. @property (nonatomic, strong) RNNStore *store;
  13. @end
  14. @implementation RNNControllerFactoryTest
  15. - (void)setUp {
  16. [super setUp];
  17. self.creator = nil;
  18. self.store = [RNNStore new];
  19. self.factory = [[RNNControllerFactory alloc] initWithRootViewCreator:self.creator store:self.store eventEmitter:nil andBridge:nil];
  20. }
  21. - (void)tearDown {
  22. [super tearDown];
  23. }
  24. - (void)testCreateLayout_EmptyLayout {
  25. XCTAssertThrows([self.factory createLayoutAndSaveToStore:@{}]);
  26. }
  27. - (void)testCreateLayout_ComponentLayout {
  28. id ans = [self.factory createLayoutAndSaveToStore:
  29. @{@"id": @"cntId",
  30. @"type": @"Component",
  31. @"data": @{},
  32. @"children": @[]}];
  33. XCTAssertTrue([ans isMemberOfClass:[RNNRootViewController class]]);
  34. }
  35. - (void)testCreateLayout_ExternalComponentLayout {
  36. [_store registerExternalComponent:@"externalComponent" callback:^UIViewController *(NSDictionary *props, RCTBridge *bridge) {
  37. return [UIViewController new];
  38. }];
  39. id ans = [self.factory createLayoutAndSaveToStore:
  40. @{@"id": @"cntId",
  41. @"type": @"ExternalComponent",
  42. @"data": @{@"name": @"externalComponent"},
  43. @"children": @[]}];
  44. XCTAssertTrue([ans isMemberOfClass:[RNNRootViewController class]]);
  45. }
  46. - (void)testCreateLayout_ComponentStackLayout {
  47. id ans = [self.factory createLayoutAndSaveToStore:
  48. @{@"id": @"cntId",
  49. @"type": @"Stack",
  50. @"data": @{},
  51. @"children": @[]}];
  52. XCTAssertTrue([ans isMemberOfClass:[RNNNavigationController class]]);
  53. }
  54. - (void)testCreateLayout_SplitViewLayout {
  55. id ans = [self.factory createLayoutAndSaveToStore:
  56. @{@"id": @"cntId",
  57. @"type": @"SplitView",
  58. @"data": @{},
  59. @"children": @[
  60. @{@"id": @"cntId_2",
  61. @"type": @"Component",
  62. @"data": @{},
  63. @"children": @[]},
  64. @{@"id": @"cntId_3",
  65. @"type": @"Component",
  66. @"data": @{},
  67. @"children": @[]}]}];
  68. XCTAssertTrue([ans isMemberOfClass:[RNNSplitViewController class]]);
  69. }
  70. - (void)testCreateLayout_ComponentStackLayoutRecursive {
  71. RNNNavigationController* ans = (RNNNavigationController*) [self.factory createLayoutAndSaveToStore:
  72. @{@"id": @"cntId",
  73. @"type": @"Stack",
  74. @"data": @{},
  75. @"children": @[
  76. @{@"id": @"cntId_2",
  77. @"type": @"Component",
  78. @"data": @{},
  79. @"children": @[]}]}];
  80. XCTAssertTrue([ans isMemberOfClass:[RNNNavigationController class]]);
  81. XCTAssertTrue(ans.childViewControllers.count == 1);
  82. XCTAssertTrue([ans.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  83. }
  84. - (void)testCreateLayout_BottomTabsLayout {
  85. RNNTabBarController* tabBar = (RNNTabBarController*) [self.factory createLayoutAndSaveToStore:
  86. @{
  87. @"id": @"cntId",
  88. @"type": @"BottomTabs",
  89. @"data": @{},
  90. @"children": @[
  91. @{@"id": @"cntId_2",
  92. @"type": @"Stack",
  93. @"data": @{},
  94. @"children": @[
  95. @{@"id": @"cntId_3",
  96. @"type": @"Component",
  97. @"data": @{},
  98. @"children": @[]}]}]}];
  99. XCTAssertTrue([tabBar isMemberOfClass:[RNNTabBarController class]]);
  100. XCTAssertTrue(tabBar.childViewControllers.count == 1);
  101. XCTAssertTrue([tabBar.childViewControllers[0] isMemberOfClass:[RNNNavigationController class]]);
  102. UINavigationController *navController = tabBar.childViewControllers[0];
  103. XCTAssertTrue(navController.childViewControllers.count == 1);
  104. XCTAssertTrue([navController.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  105. }
  106. - (void)testCreateLayout_TopTabsLayout {
  107. RNNTopTabsViewController* tabBar = (RNNTopTabsViewController*) [self.factory createLayoutAndSaveToStore:
  108. @{
  109. @"id": @"cntId",
  110. @"type": @"TopTabs",
  111. @"data": @{},
  112. @"children": @[
  113. @{@"id": @"cntId_2",
  114. @"type": @"Stack",
  115. @"data": @{},
  116. @"children": @[
  117. @{@"id": @"cntId_3",
  118. @"type": @"Component",
  119. @"data": @{},
  120. @"children": @[]}]}]}];
  121. XCTAssertTrue([tabBar isMemberOfClass:[RNNTopTabsViewController class]]);
  122. }
  123. - (void)testCreateLayout_ComponentSideMenuLayoutCenterLeftRight {
  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": @"Component",
  135. @"data": @{},
  136. @"children": @[]}]},
  137. @{@"id": @"cntI_4",
  138. @"type": @"SideMenuLeft",
  139. @"data": @{},
  140. @"children": @[
  141. @{@"id": @"cntId_5",
  142. @"type": @"Component",
  143. @"data": @{},
  144. @"children": @[]}]},
  145. @{@"id": @"cntI_6",
  146. @"type": @"SideMenuRight",
  147. @"data": @{},
  148. @"children": @[
  149. @{@"id": @"cntId_7",
  150. @"type": @"Component",
  151. @"data": @{},
  152. @"children": @[]}]}]}];
  153. XCTAssertTrue([ans isMemberOfClass:[RNNSideMenuController class]]);
  154. XCTAssertTrue([ans isKindOfClass:[UIViewController class]]);
  155. XCTAssertTrue([ans.center isMemberOfClass:[RNNSideMenuChildVC class]]);
  156. RNNSideMenuChildVC *center = (RNNSideMenuChildVC*)ans.center;
  157. XCTAssertTrue(center.type == RNNSideMenuChildTypeCenter);
  158. XCTAssertTrue([center.child isMemberOfClass:[RNNRootViewController class]]);
  159. RNNSideMenuChildVC *left = (RNNSideMenuChildVC*)ans.left;
  160. XCTAssertTrue(left.type == RNNSideMenuChildTypeLeft);
  161. XCTAssertTrue([left.child isMemberOfClass:[RNNRootViewController class]]);
  162. RNNSideMenuChildVC *right = (RNNSideMenuChildVC*)ans.right;
  163. XCTAssertTrue(right.type == RNNSideMenuChildTypeRight);
  164. XCTAssertTrue([right.child isMemberOfClass:[RNNRootViewController class]]);
  165. }
  166. - (void)testCreateLayout_addComponentToStore {
  167. NSString *componentId = @"cntId";
  168. UIViewController *ans = [self.factory createLayoutAndSaveToStore:
  169. @{@"id": componentId,
  170. @"type": @"Component",
  171. @"data": @{},
  172. @"children": @[]}];
  173. UIViewController *storeAns = [self.store findComponentForId:componentId];
  174. XCTAssertEqualObjects(ans, storeAns);
  175. }
  176. @end