react-native-navigation的迁移库

RNNControllerFactoryTest.m 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. @interface RNNControllerFactoryTest : XCTestCase
  9. @property (nonatomic, strong) id<RNNRootViewCreator> creator;
  10. @property (nonatomic, strong) RNNControllerFactory *factory;
  11. @property (nonatomic, strong) RNNStore *store;
  12. @end
  13. @implementation RNNControllerFactoryTest
  14. - (void)setUp {
  15. [super setUp];
  16. self.creator = nil;
  17. self.store = [RNNStore new];
  18. self.factory = [[RNNControllerFactory alloc] initWithRootViewCreator:self.creator store:self.store eventEmitter:nil andBridge:nil];
  19. }
  20. - (void)tearDown {
  21. [super tearDown];
  22. }
  23. - (void)testCreateLayout_EmptyLayout {
  24. XCTAssertThrows([self.factory createLayoutAndSaveToStore:@{}]);
  25. }
  26. - (void)testCreateLayout_ContainerLayout {
  27. id ans = [self.factory createLayoutAndSaveToStore:
  28. @{@"id": @"cntId",
  29. @"type": @"Container",
  30. @"data": @{},
  31. @"children": @[]}];
  32. XCTAssertTrue([ans isMemberOfClass:[RNNRootViewController class]]);
  33. }
  34. - (void)testCreateLayout_ContainerStackLayout {
  35. id ans = [self.factory createLayoutAndSaveToStore:
  36. @{@"id": @"cntId",
  37. @"type": @"ContainerStack",
  38. @"data": @{},
  39. @"children": @[]}];
  40. XCTAssertTrue([ans isMemberOfClass:[RNNNavigationController class]]);
  41. }
  42. - (void)testCreateLayout_ContainerStackLayoutRecursive {
  43. RNNNavigationController* ans = (RNNNavigationController*) [self.factory createLayoutAndSaveToStore:
  44. @{@"id": @"cntId",
  45. @"type": @"ContainerStack",
  46. @"data": @{},
  47. @"children": @[
  48. @{@"id": @"cntId_2",
  49. @"type": @"Container",
  50. @"data": @{},
  51. @"children": @[]}]}];
  52. XCTAssertTrue([ans isMemberOfClass:[RNNNavigationController class]]);
  53. XCTAssertTrue(ans.childViewControllers.count == 1);
  54. XCTAssertTrue([ans.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  55. }
  56. - (void)testCreateLayout_BottomTabsLayout {
  57. RNNTabBarController* tabBar = (RNNTabBarController*) [self.factory createLayoutAndSaveToStore:
  58. @{
  59. @"id": @"cntId",
  60. @"type": @"BottomTabs",
  61. @"data": @{},
  62. @"children": @[
  63. @{@"id": @"cntId_2",
  64. @"type": @"ContainerStack",
  65. @"data": @{},
  66. @"children": @[
  67. @{@"id": @"cntId_3",
  68. @"type": @"Container",
  69. @"data": @{},
  70. @"children": @[]}]}]}];
  71. XCTAssertTrue([tabBar isMemberOfClass:[RNNTabBarController class]]);
  72. XCTAssertTrue(tabBar.childViewControllers.count == 1);
  73. XCTAssertTrue([tabBar.childViewControllers[0] isMemberOfClass:[RNNNavigationController class]]);
  74. UINavigationController *navController = tabBar.childViewControllers[0];
  75. XCTAssertTrue(navController.childViewControllers.count == 1);
  76. XCTAssertTrue([navController.childViewControllers[0] isMemberOfClass:[RNNRootViewController class]]);
  77. }
  78. - (void)testCreateLayout_ContainerSideMenuLayoutCenterLeftRight {
  79. RNNSideMenuController *ans = (RNNSideMenuController*) [self.factory createLayoutAndSaveToStore:
  80. @{@"id": @"cntId",
  81. @"type": @"SideMenuRoot",
  82. @"data": @{},
  83. @"children": @[
  84. @{@"id": @"cntI_2",
  85. @"type": @"SideMenuCenter",
  86. @"data": @{},
  87. @"children": @[
  88. @{@"id": @"cntId_3",
  89. @"type": @"Container",
  90. @"data": @{},
  91. @"children": @[]}]},
  92. @{@"id": @"cntI_4",
  93. @"type": @"SideMenuLeft",
  94. @"data": @{},
  95. @"children": @[
  96. @{@"id": @"cntId_5",
  97. @"type": @"Container",
  98. @"data": @{},
  99. @"children": @[]}]},
  100. @{@"id": @"cntI_6",
  101. @"type": @"SideMenuRight",
  102. @"data": @{},
  103. @"children": @[
  104. @{@"id": @"cntId_7",
  105. @"type": @"Container",
  106. @"data": @{},
  107. @"children": @[]}]}]}];
  108. XCTAssertTrue([ans isMemberOfClass:[RNNSideMenuController class]]);
  109. XCTAssertTrue([ans isKindOfClass:[UIViewController class]]);
  110. XCTAssertTrue([ans.center isMemberOfClass:[RNNSideMenuChildVC class]]);
  111. RNNSideMenuChildVC *center = (RNNSideMenuChildVC*)ans.center;
  112. XCTAssertTrue(center.type == RNNSideMenuChildTypeCenter);
  113. XCTAssertTrue([center.child isMemberOfClass:[RNNRootViewController class]]);
  114. RNNSideMenuChildVC *left = (RNNSideMenuChildVC*)ans.left;
  115. XCTAssertTrue(left.type == RNNSideMenuChildTypeLeft);
  116. XCTAssertTrue([left.child isMemberOfClass:[RNNRootViewController class]]);
  117. RNNSideMenuChildVC *right = (RNNSideMenuChildVC*)ans.right;
  118. XCTAssertTrue(right.type == RNNSideMenuChildTypeRight);
  119. XCTAssertTrue([right.child isMemberOfClass:[RNNRootViewController class]]);
  120. }
  121. - (void)testCreateLayout_addContainerToStore {
  122. NSString *containerId = @"cntId";
  123. UIViewController *ans = [self.factory createLayoutAndSaveToStore:
  124. @{@"id": containerId,
  125. @"type": @"Container",
  126. @"data": @{},
  127. @"children": @[]}];
  128. UIViewController *storeAns = [self.store findContainerForId:containerId];
  129. XCTAssertEqualObjects(ans, storeAns);
  130. }
  131. @end