react-native-navigation的迁移库

RNNNavigationStackManagerTest.m 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #import <XCTest/XCTest.h>
  2. #import "RNNStore.h"
  3. #import "RNNNavigationStackManager.h"
  4. @interface MockUINavigationController : UINavigationController
  5. @property (nonatomic, strong) NSArray* willReturnVCs;
  6. @end
  7. @implementation MockUINavigationController
  8. -(NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
  9. return self.willReturnVCs;
  10. }
  11. -(NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
  12. return self.willReturnVCs;
  13. }
  14. @end
  15. @interface RNNNavigationStackManagerTest : XCTestCase
  16. @property (nonatomic, strong) RNNStore *store;
  17. @property (nonatomic, strong) RNNNavigationStackManager *uut;
  18. @property (nonatomic, strong) MockUINavigationController *nvc;
  19. @property (nonatomic, strong) UIViewController *vc1;
  20. @property (nonatomic, strong) UIViewController *vc2;
  21. @property (nonatomic, strong) UIViewController *vc3;
  22. @end
  23. @implementation RNNNavigationStackManagerTest
  24. - (void)setUp {
  25. [super setUp];
  26. self.store = [RNNStore new];
  27. self.uut = [[RNNNavigationStackManager alloc] initWithStore:self.store];
  28. self.nvc = [[MockUINavigationController alloc] init];
  29. self.vc1 = [UIViewController new];
  30. self.vc2 = [UIViewController new];
  31. self.vc3 = [UIViewController new];
  32. NSArray *vcArray = @[self.vc1, self.vc2, self.vc3];
  33. [self.nvc setViewControllers:vcArray];
  34. [self.store setContainer:self.vc1 containerId:@"vc1"];
  35. [self.store setContainer:self.vc2 containerId:@"vc2"];
  36. [self.store setContainer:self.vc3 containerId:@"vc3"];
  37. }
  38. - (void)testPop_removeTopVCFromStore {
  39. [self.uut pop:@"vc3"];
  40. XCTAssertNil([self.store findContainerForId:@"vc3"]);
  41. XCTAssertNotNil([self.store findContainerForId:@"vc2"]);
  42. XCTAssertNotNil([self.store findContainerForId:@"vc1"]);
  43. }
  44. - (void)testPopToSpecificVC_removeAllPopedVCFromStore {
  45. self.nvc.willReturnVCs = @[self.vc2, self.vc3];
  46. [self.uut popTo:@"vc1"];
  47. XCTAssertNil([self.store findContainerForId:@"vc2"]);
  48. XCTAssertNil([self.store findContainerForId:@"vc3"]);
  49. XCTAssertNotNil([self.store findContainerForId:@"vc1"]);
  50. }
  51. - (void)testPopToRoot_removeAllTopVCsFromStore {
  52. self.nvc.willReturnVCs = @[self.vc2, self.vc3];
  53. [self.uut popToRoot:@"vc3"];
  54. XCTAssertNil([self.store findContainerForId:@"vc2"]);
  55. XCTAssertNil([self.store findContainerForId:@"vc3"]);
  56. XCTAssertNotNil([self.store findContainerForId:@"vc1"]);
  57. }
  58. @end