react-native-navigation的迁移库

RNNControllerFactoryTest.m 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 "RNNTopTabsViewController.h"
  9. #import "RNNSplitViewController.h"
  10. @interface RNNControllerFactoryTest : XCTestCase
  11. @property (nonatomic, strong) id<RNNRootViewCreator> creator;
  12. @property (nonatomic, strong) RNNControllerFactory *factory;
  13. @property (nonatomic, strong) RNNExternalComponentStore *store;
  14. @end
  15. @implementation RNNControllerFactoryTest
  16. - (void)setUp {
  17. [super setUp];
  18. self.creator = nil;
  19. self.store = [RNNExternalComponentStore new];
  20. self.factory = [[RNNControllerFactory alloc] initWithRootViewCreator:self.creator eventEmitter:nil store:self.store componentRegistry:nil andBridge:nil];
  21. }
  22. - (void)tearDown {
  23. [super tearDown];
  24. }
  25. - (void)testCreateLayout_EmptyLayout {
  26. XCTAssertThrows([self.factory createLayout:@{}]);
  27. }
  28. - (void)testCreateLayout_ComponentLayout {
  29. NSDictionary* layout = @{@"id": @"cntId",
  30. @"type": @"Component",
  31. @"data": @{},
  32. @"children": @[]};
  33. id ans = [self.factory createLayout:layout];
  34. XCTAssertTrue([ans isMemberOfClass:[RNNRootViewController class]]);
  35. }
  36. - (void)testCreateLayout_ExternalComponentLayout {
  37. [_store registerExternalComponent:@"externalComponent" callback:^UIViewController *(NSDictionary *props, RCTBridge *bridge) {
  38. return [UIViewController new];
  39. }];
  40. NSDictionary* layout = @{@"id": @"cntId",
  41. @"type": @"ExternalComponent",
  42. @"data": @{@"name": @"externalComponent"},
  43. @"children": @[]};
  44. id ans = [self.factory createLayout:layout];
  45. XCTAssertTrue([ans isMemberOfClass:[RNNRootViewController class]]);
  46. }
  47. - (void)testCreateLayout_ComponentStackLayout {
  48. NSDictionary* layout = @{@"id": @"cntId",
  49. @"type": @"Stack",
  50. @"data": @{},
  51. @"children": @[]};
  52. id ans = [self.factory createLayout:layout];
  53. XCTAssertTrue([ans isMemberOfClass:[RNNNavigationController class]]);
  54. }
  55. - (void)testCreateLayout_SplitViewLayout {
  56. NSDictionary* layout = @{@"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. id ans = [self.factory createLayout:layout];
  69. XCTAssertTrue([ans isMemberOfClass:[RNNSplitViewController class]]);
  70. }
  71. - (void)testCreateLayout_ComponentStackLayoutRecursive {
  72. NSDictionary* layout = @{@"id": @"cntId",
  73. @"type": @"Stack",
  74. @"data": @{},
  75. @"children": @[
  76. @{@"id": @"cntId_2",
  77. @"type": @"Component",
  78. @"data": @{},
  79. @"children": @[]}]};
  80. RNNNavigationController* ans = (RNNNavigationController*) [self.factory createLayout:layout];
  81. XCTAssertTrue([ans isMemberOfClass:[RNNNavigationController class]]);
  82. XCTAssertTrue(ans.childViewControllers.count == 1);
  83. XCTAssertTrue([ans.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  84. }
  85. - (void)testCreateLayout_BottomTabsLayout {
  86. NSDictionary* layout = @{
  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. RNNTabBarController* tabBar = (RNNTabBarController*) [self.factory createLayout:layout];
  100. XCTAssertTrue([tabBar isMemberOfClass:[RNNTabBarController class]]);
  101. XCTAssertTrue(tabBar.childViewControllers.count == 1);
  102. XCTAssertTrue([tabBar.childViewControllers[0] isMemberOfClass:[RNNNavigationController class]]);
  103. UINavigationController *navController = tabBar.childViewControllers[0];
  104. XCTAssertTrue(navController.childViewControllers.count == 1);
  105. XCTAssertTrue([navController.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  106. }
  107. - (void)testCreateLayout_TopTabsLayout {
  108. NSDictionary* layout = @{
  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. RNNTopTabsViewController* tabBar = (RNNTopTabsViewController*) [self.factory createLayout:layout];
  122. XCTAssertTrue([tabBar isMemberOfClass:[RNNTopTabsViewController class]]);
  123. }
  124. - (void)testCreateLayout_ComponentSideMenuLayoutCenterLeftRight {
  125. NSDictionary* layout = @{@"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. RNNSideMenuController *ans = (RNNSideMenuController*) [self.factory createLayout:layout];
  154. XCTAssertTrue([ans isMemberOfClass:[RNNSideMenuController class]]);
  155. XCTAssertTrue([ans isKindOfClass:[UIViewController class]]);
  156. XCTAssertTrue([ans.center isMemberOfClass:[RNNSideMenuChildVC class]]);
  157. RNNSideMenuChildVC *center = (RNNSideMenuChildVC*)ans.center;
  158. XCTAssertTrue(center.type == RNNSideMenuChildTypeCenter);
  159. XCTAssertTrue([center.child isMemberOfClass:[RNNRootViewController class]]);
  160. RNNSideMenuChildVC *left = (RNNSideMenuChildVC*)ans.left;
  161. XCTAssertTrue(left.type == RNNSideMenuChildTypeLeft);
  162. XCTAssertTrue([left.child isMemberOfClass:[RNNRootViewController class]]);
  163. RNNSideMenuChildVC *right = (RNNSideMenuChildVC*)ans.right;
  164. XCTAssertTrue(right.type == RNNSideMenuChildTypeRight);
  165. XCTAssertTrue([right.child isMemberOfClass:[RNNRootViewController class]]);
  166. }
  167. @end