react-native-navigation的迁移库

RNNStoreTest.m 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #import <XCTest/XCTest.h>
  2. #import "RNNStore.m"
  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)testFindContainerForId_setAndGetsimpleContainerId {
  12. NSString *containerId1 = @"cntId1";
  13. NSString *containerId2 = @"cntId2";
  14. UIViewController *vc1 = [UIViewController new];
  15. UIViewController *vc2 = [UIViewController new];
  16. [self.store setContainer:vc1 containerId:containerId1];
  17. [self.store setContainer:vc2 containerId:containerId2];
  18. UIViewController *ans = [self.store findContainerForId:containerId1];
  19. XCTAssertEqualObjects(vc1, ans);
  20. XCTAssertNotEqualObjects(vc2, ans);
  21. }
  22. - (void)testSetContainer_setNilContainerId {
  23. NSString *containerId1 = nil;
  24. UIViewController *vc1 = [UIViewController new];
  25. [self.store setContainer:vc1 containerId:containerId1];
  26. XCTAssertNil([self.store findContainerForId:containerId1]);
  27. }
  28. - (void)testSetContainer_setDoubleContainerId {
  29. NSString *containerId1 = @"cntId1";
  30. UIViewController *vc1 = [UIViewController new];
  31. UIViewController *vc2 = [UIViewController new];
  32. [self.store setContainer:vc1 containerId:containerId1];
  33. UIViewController *ans = [self.store findContainerForId:containerId1];
  34. XCTAssertEqualObjects(vc1, ans);
  35. XCTAssertThrows([self.store setContainer:vc2 containerId:containerId1]);
  36. }
  37. - (void)testRemoveContainer_removeExistContainer {
  38. NSString *containerId1 = @"cntId1";
  39. UIViewController *vc1 = [UIViewController new];
  40. [self.store setContainer:vc1 containerId:containerId1];
  41. UIViewController *ans = [self.store findContainerForId:containerId1];
  42. XCTAssertEqualObjects(vc1, ans);
  43. [self.store removeContainer:containerId1];
  44. XCTAssertNil([self.store findContainerForId:containerId1]);
  45. }
  46. -(void)testPopWillRemoveVcFromStore {
  47. NSString *vcId = @"cnt_vc_2";
  48. [self setContainerAndRelease:vcId];
  49. XCTAssertNil([self.store findContainerForId:vcId]);
  50. }
  51. -(void)setContainerAndRelease:(NSString*)vcId {
  52. @autoreleasepool {
  53. UIViewController *vc2 = [UIViewController new];
  54. [self.store setContainer:vc2 containerId:vcId];
  55. XCTAssertNotNil([self.store findContainerForId:vcId]);
  56. }
  57. }
  58. @end