react-native-navigation的迁移库

RNNNavigationStackManagerTest.m 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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" withTransitionOptions:nil rejection: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" rejection:nil];
  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" rejection:nil];
  54. XCTAssertNil([self.store findComponentForId:@"vc2"]);
  55. XCTAssertNil([self.store findComponentForId:@"vc3"]);
  56. XCTAssertNotNil([self.store findComponentForId:@"vc1"]);
  57. }
  58. - (void)testStackRoot_shouldUpdateNavigationControllerChildrenViewControllers {
  59. self.nvc.willReturnVCs = @[self.vc1, self.vc2, self.vc3];
  60. [self.uut setStackRoot:self.vc2 fromComponent:@"vc1" completion:nil rejection:nil];
  61. XCTAssertEqual(self.nvc.viewControllers.lastObject, self.vc2);
  62. XCTAssertEqual(self.nvc.viewControllers.count, 1);
  63. }
  64. @end