react-native-navigation的迁移库

RNNControllerFactoryTest.m 6.7KB

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