react-native-navigation的迁移库

RNNNavigationStackManagerTest.m 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #import <XCTest/XCTest.h>
  2. //#import <objc/runtime.h>
  3. #import "RNNStore.h"
  4. #import "RNNNavigationStackManager.h"
  5. @interface MockUINavigationController : UINavigationController
  6. @property (nonatomic, strong) NSArray* willReturnVCs;
  7. @end
  8. @implementation MockUINavigationController
  9. -(NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
  10. return self.willReturnVCs;
  11. }
  12. @end
  13. @interface RNNNavigationStackManagerTest : XCTestCase
  14. @end
  15. @implementation RNNNavigationStackManagerTest
  16. - (void)setUp {
  17. [super setUp];
  18. }
  19. - (void)testPop {
  20. RNNStore *store = [RNNStore new];
  21. RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
  22. UINavigationController *nvc = [[UINavigationController alloc] init];
  23. UIViewController *vc1 = [UIViewController new];
  24. UIViewController *vc2 = [UIViewController new];
  25. NSArray *vcArray = @[vc1, vc2];
  26. [nvc setViewControllers:vcArray];
  27. [store setContainer:vc1 containerId:@"vc1"];
  28. [store setContainer:vc2 containerId:@"vc2"];
  29. [uut pop:@"vc2"];
  30. XCTAssertNil([store findContainerForId:@"vc2"]);
  31. XCTAssertNotNil([store findContainerForId:@"vc1"]);
  32. }
  33. - (void)testPopTo_singleVc {
  34. RNNStore *store = [RNNStore new];
  35. RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
  36. UIViewController *vc1 = [UIViewController new];
  37. UIViewController *vc2 = [UIViewController new];
  38. UIViewController *vc3 = [UIViewController new];
  39. MockUINavigationController *nvc = [[MockUINavigationController alloc] initWithRootViewController:vc1];
  40. [nvc pushViewController:vc2 animated:NO];
  41. [nvc pushViewController:vc3 animated:NO];
  42. nvc.willReturnVCs = @[vc2, vc3];
  43. [store setContainer:vc1 containerId:@"vc1"];
  44. [store setContainer:vc2 containerId:@"vc2"];
  45. [store setContainer:vc3 containerId:@"vc3"];
  46. [uut popTo:@"vc1" fromContainerId:@"vc3"];
  47. XCTAssertNil([store findContainerForId:@"vc2"]);
  48. XCTAssertNotNil([store findContainerForId:@"vc1"]);
  49. }
  50. //- (void)testPopTo {
  51. // RNNStore *store = [RNNStore new];
  52. // RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
  53. //
  54. // UINavigationController *nvc = [[UINavigationController alloc] init];
  55. //
  56. // UIViewController *vc1 = [UIViewController new];
  57. // UIViewController *vc2 = [UIViewController new];
  58. // UIViewController *vc3 = [UIViewController new];
  59. // UIViewController *vc4 = [UIViewController new];
  60. //
  61. // NSArray *vcArray = @[vc1, vc2, vc3, vc4];
  62. // [nvc setViewControllers:vcArray];
  63. // [store setContainer:vc1 containerId:@"vc1"];
  64. // [store setContainer:vc2 containerId:@"vc2"];
  65. // [store setContainer:vc3 containerId:@"vc3"];
  66. // [store setContainer:vc4 containerId:@"vc4"];
  67. // [store setContainer:nvc containerId:@"nvc"];
  68. //
  69. // [uut popTo:@"vc1" fromContainerId:@"vc4"];
  70. //
  71. // XCTAssertNil([store findContainerForId:@"vc4"]);
  72. // XCTAssertNil([store findContainerForId:@"vc3"]);
  73. // XCTAssertNil([store findContainerForId:@"vc2"]);
  74. //
  75. //}
  76. @end