react-native-navigation的迁移库

RNNControllerFactoryTest.m 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. @end
  14. @implementation RNNControllerFactoryTest
  15. - (void)setUp {
  16. [super setUp];
  17. self.creator = nil;
  18. self.factory = [[RNNControllerFactory alloc] initWithRootViewCreator:self.creator];
  19. }
  20. - (void)tearDown {
  21. // Put teardown code here. This method is called after the invocation of each test method in the class.
  22. [super tearDown];
  23. }
  24. - (void)testCreateLayout_EmptyLayout {
  25. XCTAssertThrows([self.factory createLayout:@{}]);
  26. }
  27. - (void)testCreateLayout_ContainerLayout {
  28. id ans = [self.factory createLayout:
  29. @{@"id": @"cntId",
  30. @"type": @"Container",
  31. @"data": @{},
  32. @"children": @[]}];
  33. XCTAssertTrue([ans isMemberOfClass:[RNNRootViewController class]]);
  34. }
  35. - (void)testCreateLayout_ContainerStackLayout {
  36. id ans = [self.factory createLayout:
  37. @{@"id": @"cntId",
  38. @"type": @"ContainerStack",
  39. @"data": @{},
  40. @"children": @[]}];
  41. XCTAssertTrue([ans isMemberOfClass:[UINavigationController class]]);
  42. }
  43. - (void)testCreateLayout_ContainerStackLayoutRecursive {
  44. UINavigationController* ans = (UINavigationController*) [self.factory createLayout:
  45. @{@"id": @"cntId",
  46. @"type": @"ContainerStack",
  47. @"data": @{},
  48. @"children": @[
  49. @{@"id": @"cntId_2",
  50. @"type": @"Container",
  51. @"data": @{},
  52. @"children": @[]}]}];
  53. XCTAssertTrue([ans isMemberOfClass:[UINavigationController class]]);
  54. XCTAssertTrue(ans.childViewControllers.count == 1);
  55. XCTAssertTrue([ans.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  56. }
  57. - (void)testCreateLayout_BottomTabsLayout {
  58. UITabBarController* tabBar = (UITabBarController*) [self.factory createLayout:
  59. @{
  60. @"id": @"cntId",
  61. @"type": @"BottomTabs",
  62. @"data": @{},
  63. @"children": @[
  64. @{@"id": @"cntId_2",
  65. @"type": @"ContainerStack",
  66. @"data": @{},
  67. @"children": @[
  68. @{@"id": @"cntId_3",
  69. @"type": @"Container",
  70. @"data": @{},
  71. @"children": @[]}]}]}];
  72. XCTAssertTrue([tabBar isMemberOfClass:[UITabBarController class]]);
  73. XCTAssertTrue(tabBar.childViewControllers.count == 1);
  74. XCTAssertTrue([tabBar.childViewControllers[0] isMemberOfClass:[UINavigationController class]]);
  75. UINavigationController *navController = tabBar.childViewControllers[0];
  76. XCTAssertTrue(navController.childViewControllers.count == 1);
  77. XCTAssertTrue([navController.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  78. }
  79. - (void)testCreateLayout_ContainerSideMenuLayoutCenterOnly {
  80. RNNSideMenuController *ans = (RNNSideMenuController*) [self.factory createLayout:@{@"id": @"cntId",
  81. @"type": @"SideMenuRoot",
  82. @"data": @{},
  83. @"children": @[@{@"id": @"cntI_2",
  84. @"type": @"SideMenuCenter",
  85. @"data": @{},
  86. @"children": @[
  87. @{@"id": @"cntId_3",
  88. @"type": @"Container",
  89. @"data": @{},
  90. @"children": @[]}]}]}];
  91. XCTAssertTrue([ans isMemberOfClass:[RNNSideMenuController class]]);
  92. XCTAssertTrue([ans isKindOfClass:[UIViewController class]]);
  93. XCTAssertTrue([ans.center isMemberOfClass:[RNNSideMenuCenterVC class]]);
  94. XCTAssertTrue([ans.center.child isMemberOfClass:[RNNRootViewController class]]);
  95. }
  96. - (void)testCreateLayout_ContainerSideMenuLayoutCenterAndLeft {
  97. RNNSideMenuController *ans = (RNNSideMenuController*) [self.factory createLayout:@{@"id": @"cntId",
  98. @"type": @"SideMenuRoot",
  99. @"data": @{},
  100. @"children": @[
  101. @{@"id": @"cntI_2",
  102. @"type": @"SideMenuCenter",
  103. @"data": @{},
  104. @"children": @[
  105. @{@"id": @"cntId_3",
  106. @"type": @"Container",
  107. @"data": @{},
  108. @"children": @[]}]},
  109. @{@"id": @"cntI_4",
  110. @"type": @"SideMenuLeft",
  111. @"data": @{},
  112. @"children": @[
  113. @{@"id": @"cntId_5",
  114. @"type": @"Container",
  115. @"data": @{},
  116. @"children": @[]}]}]}];
  117. XCTAssertTrue([ans isMemberOfClass:[RNNSideMenuController class]]);
  118. XCTAssertTrue([ans isKindOfClass:[UIViewController class]]);
  119. XCTAssertTrue([ans.center isMemberOfClass:[RNNSideMenuCenterVC class]]);
  120. XCTAssertTrue([ans.center.child isMemberOfClass:[RNNRootViewController class]]);
  121. XCTAssertTrue([ans.left isMemberOfClass:[RNNSideMenuLeftVC class]]);
  122. RNNSideMenuLeftVC *left = (RNNSideMenuLeftVC*)ans.left;
  123. XCTAssertTrue([left.child isMemberOfClass:[RNNRootViewController class]]);
  124. }
  125. - (void)testCreateLayout_ContainerSideMenuLayoutCenterLeftRight {
  126. RNNSideMenuController *ans = (RNNSideMenuController*) [self.factory createLayout:@{@"id": @"cntId",
  127. @"type": @"SideMenuRoot",
  128. @"data": @{},
  129. @"children": @[
  130. @{@"id": @"cntI_2",
  131. @"type": @"SideMenuCenter",
  132. @"data": @{},
  133. @"children": @[
  134. @{@"id": @"cntId_3",
  135. @"type": @"Container",
  136. @"data": @{},
  137. @"children": @[]}]},
  138. @{@"id": @"cntI_4",
  139. @"type": @"SideMenuLeft",
  140. @"data": @{},
  141. @"children": @[
  142. @{@"id": @"cntId_5",
  143. @"type": @"Container",
  144. @"data": @{},
  145. @"children": @[]}]},
  146. @{@"id": @"cntI_6",
  147. @"type": @"SideMenuRight",
  148. @"data": @{},
  149. @"children": @[
  150. @{@"id": @"cntId_5",
  151. @"type": @"Container",
  152. @"data": @{},
  153. @"children": @[]}]}]}];
  154. XCTAssertTrue([ans isMemberOfClass:[RNNSideMenuController class]]);
  155. XCTAssertTrue([ans isKindOfClass:[UIViewController class]]);
  156. XCTAssertTrue([ans.center isMemberOfClass:[RNNSideMenuCenterVC class]]);
  157. XCTAssertTrue([ans.center.child isMemberOfClass:[RNNRootViewController class]]);
  158. XCTAssertTrue([ans.left isMemberOfClass:[RNNSideMenuLeftVC class]]);
  159. RNNSideMenuLeftVC *left = (RNNSideMenuLeftVC*)ans.left;
  160. XCTAssertTrue([left.child isMemberOfClass:[RNNRootViewController class]]);
  161. XCTAssertTrue([ans.right isMemberOfClass:[RNNSideMenuRightVC class]]);
  162. RNNSideMenuRightVC *right = (RNNSideMenuRightVC*)ans.right;
  163. XCTAssertTrue([right.child isMemberOfClass:[RNNRootViewController class]]);
  164. }
  165. @end