react-native-navigation的迁移库

RNNStoreTest.m 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #pragma mark - private
  59. -(void)setComponentAndRelease:(NSString*)vcId {
  60. @autoreleasepool {
  61. UIViewController *vc2 = [UIViewController new];
  62. [self.store setComponent:vc2 componentId:vcId];
  63. XCTAssertNotNil([self.store findComponentForId:vcId]);
  64. }
  65. }
  66. @end