react-native-navigation的迁移库

RNNNavigationStackManagerTest.m 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 = [RNNRootViewController new];
  30. self.vc2 = [RNNRootViewController new];
  31. self.vc3 = [RNNRootViewController new];
  32. NSArray *vcArray = @[self.vc1, self.vc2, self.vc3];
  33. [self.nvc setViewControllers:vcArray];
  34. [self.store setComponent:self.vc1 componentId:@"vc1"];
  35. [self.store setComponent:self.vc2 componentId:@"vc2"];
  36. [self.store setComponent:self.vc3 componentId:@"vc3"];
  37. }
  38. - (void)testPop_removeTopVCFromStore {
  39. [self.uut pop:@"vc3" withAnimationData:(NSDictionary*)nil];
  40. XCTAssertNil([self.store findComponentForId:@"vc3"]);
  41. XCTAssertNotNil([self.store findComponentForId:@"vc2"]);
  42. XCTAssertNotNil([self.store findComponentForId:@"vc1"]);
  43. }
  44. - (void)testPopToSpecificVC_removeAllPopedVCFromStore {
  45. self.nvc.willReturnVCs = @[self.vc2, self.vc3];
  46. [self.uut popTo:@"vc1"];
  47. XCTAssertNil([self.store findComponentForId:@"vc2"]);
  48. XCTAssertNil([self.store findComponentForId:@"vc3"]);
  49. XCTAssertNotNil([self.store findComponentForId:@"vc1"]);
  50. }
  51. - (void)testPopToRoot_removeAllTopVCsFromStore {
  52. self.nvc.willReturnVCs = @[self.vc2, self.vc3];
  53. [self.uut popToRoot:@"vc3"];
  54. XCTAssertNil([self.store findComponentForId:@"vc2"]);
  55. XCTAssertNil([self.store findComponentForId:@"vc3"]);
  56. XCTAssertNotNil([self.store findComponentForId:@"vc1"]);
  57. }
  58. @end