react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // RNNStoreTest.m
  3. // playground
  4. //
  5. // Created by Ran Greenberg on 12/02/2017.
  6. // Copyright © 2017 Wix. All rights reserved.
  7. //
  8. #import <XCTest/XCTest.h>
  9. #import "RNNStore.m"
  10. @interface RNNStoreTest : XCTestCase
  11. @property (nonatomic, strong) RNNStore *store;
  12. @end
  13. @implementation RNNStoreTest
  14. - (void)setUp {
  15. [super setUp];
  16. self.store = [RNNStore new];
  17. }
  18. - (void)testFindContainerForId_setAndGetsimpleContainerId {
  19. NSString *containerId1 = @"cntId1";
  20. NSString *containerId2 = @"cntId2";
  21. UIViewController *vc1 = [UIViewController new];
  22. UIViewController *vc2 = [UIViewController new];
  23. [self.store setContainer:vc1 containerId:containerId1];
  24. [self.store setContainer:vc2 containerId:containerId2];
  25. UIViewController *ans = [self.store findContainerForId:containerId1];
  26. XCTAssertEqualObjects(vc1, ans);
  27. XCTAssertNotEqualObjects(vc2, ans);
  28. }
  29. - (void)testSetContainer_setNilContainerId {
  30. NSString *containerId1 = nil;
  31. UIViewController *vc1 = [UIViewController new];
  32. [self.store setContainer:vc1 containerId:containerId1];
  33. XCTAssertNil([self.store findContainerForId:containerId1]);
  34. }
  35. - (void)testSetContainer_setDoubleContainerId {
  36. NSString *containerId1 = @"cntId1";
  37. UIViewController *vc1 = [UIViewController new];
  38. UIViewController *vc2 = [UIViewController new];
  39. [self.store setContainer:vc1 containerId:containerId1];
  40. UIViewController *ans = [self.store findContainerForId:containerId1];
  41. XCTAssertEqualObjects(vc1, ans);
  42. XCTAssertThrows([self.store setContainer:vc2 containerId:containerId1]);
  43. }
  44. - (void)testRemoveContainer_removeExistContainer {
  45. NSString *containerId1 = @"cntId1";
  46. UIViewController *vc1 = [UIViewController new];
  47. [self.store setContainer:vc1 containerId:containerId1];
  48. UIViewController *ans = [self.store findContainerForId:containerId1];
  49. XCTAssertEqualObjects(vc1, ans);
  50. [self.store removeContainer:containerId1];
  51. XCTAssertNil([self.store findContainerForId:containerId1]);
  52. }
  53. -(void)testPopWillRemoveVcFromStore {
  54. NSString *vcId = @"cnt_vc_2";
  55. [self setContainerAndRelease:vcId];
  56. XCTAssertNil([self.store findContainerForId:vcId]); // PASS
  57. }
  58. -(void) setContainerAndRelease:(NSString*)vcId {
  59. @autoreleasepool {
  60. UIViewController *vc2 = [UIViewController new];
  61. [self.store setContainer:vc2 containerId:vcId];
  62. XCTAssertNotNil([self.store findContainerForId:vcId]); // PASS
  63. }
  64. }
  65. @end