react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #import <XCTest/XCTest.h>
  2. #import "RNNStore.h"
  3. @interface RNNStoreTest : XCTestCase
  4. @property (nonatomic, strong) RNNStore *store;
  5. @end
  6. @implementation RNNStoreTest
  7. - (void)setUp {
  8. [super setUp];
  9. self.store = [RNNStore new];
  10. }
  11. - (void)testFindComponentForId_setAndGetsimpleComponentId {
  12. NSString *componentId1 = @"cntId1";
  13. NSString *componentId2 = @"cntId2";
  14. UIViewController *vc1 = [UIViewController new];
  15. UIViewController *vc2 = [UIViewController new];
  16. [self.store setComponent:vc1 componentId:componentId1];
  17. [self.store setComponent:vc2 componentId:componentId2];
  18. UIViewController *ans = [self.store findComponentForId:componentId1];
  19. XCTAssertEqualObjects(vc1, ans);
  20. XCTAssertNotEqualObjects(vc2, ans);
  21. }
  22. - (void)testSetComponent_setNilComponentId {
  23. NSString *componentId1 = nil;
  24. UIViewController *vc1 = [UIViewController new];
  25. [self.store setComponent:vc1 componentId:componentId1];
  26. XCTAssertNil([self.store findComponentForId:componentId1]);
  27. }
  28. - (void)testSetComponent_setDoubleComponentId {
  29. NSString *componentId1 = @"cntId1";
  30. UIViewController *vc1 = [UIViewController new];
  31. UIViewController *vc2 = [UIViewController new];
  32. [self.store setComponent:vc1 componentId:componentId1];
  33. UIViewController *ans = [self.store findComponentForId:componentId1];
  34. XCTAssertEqualObjects(vc1, ans);
  35. XCTAssertThrows([self.store setComponent:vc2 componentId:componentId1]);
  36. }
  37. - (void)testRemoveComponent_removeExistComponent {
  38. NSString *componentId1 = @"cntId1";
  39. UIViewController *vc1 = [UIViewController new];
  40. [self.store setComponent:vc1 componentId:componentId1];
  41. UIViewController *ans = [self.store findComponentForId:componentId1];
  42. XCTAssertEqualObjects(vc1, ans);
  43. [self.store removeComponent:componentId1];
  44. XCTAssertNil([self.store findComponentForId:componentId1]);
  45. }
  46. -(void)testPopWillRemoveVcFromStore {
  47. NSString *vcId = @"cnt_vc_2";
  48. [self setComponentAndRelease:vcId];
  49. XCTAssertNil([self.store findComponentForId:vcId]);
  50. }
  51. -(void)testRemoveComponentByInstance {
  52. NSString *componentId1 = @"cntId1";
  53. UIViewController *vc1 = [UIViewController new];
  54. [self.store setComponent:vc1 componentId:componentId1];
  55. [self.store removeComponentByViewControllerInstance:vc1];
  56. XCTAssertNil([self.store findComponentForId:@"cntId1"]);
  57. }
  58. - (void)testGetExternalComponentShouldRetrunSavedComponent {
  59. UIViewController* testVC = [UIViewController new];
  60. RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
  61. layoutInfo.name = @"extId1";
  62. [self.store registerExternalComponent:layoutInfo.name callback:^UIViewController *(NSDictionary *props, RCTBridge *bridge) {
  63. return testVC;
  64. }];
  65. UIViewController* savedComponent = [self.store getExternalComponent:layoutInfo bridge:nil];
  66. XCTAssertEqual(testVC, savedComponent);
  67. }
  68. - (void)testComponentKeyForInstance_UknownComponentShouldReturnNil {
  69. id result = [self.store componentKeyForInstance:[UIViewController new]];
  70. XCTAssertNil(result);
  71. }
  72. -(void)testCleanStore {
  73. [self.store clean];
  74. XCTAssertFalse(self.store.isReadyToReceiveCommands);
  75. }
  76. #pragma mark - private
  77. -(void)setComponentAndRelease:(NSString*)vcId {
  78. @autoreleasepool {
  79. UIViewController *vc2 = [UIViewController new];
  80. [self.store setComponent:vc2 componentId:vcId];
  81. XCTAssertNotNil([self.store findComponentForId:vcId]);
  82. }
  83. }
  84. @end