react-native-navigation的迁移库

RNNNavigationStackManagerTest.m 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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];
  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. - (void)testStackRoot_navigationControllerNilShouldThrow {
  59. [self.nvc setViewControllers:@[self.vc1]];
  60. self.nvc.willReturnVCs = @[self.vc1];
  61. XCTAssertThrowsSpecificNamed([self.uut setRoot:self.vc2 fromComponent:nil completion:nil], NSException, @"StackNotFound");
  62. }
  63. - (void)testStackRoot_shouldUpdateNavigationControllerChildrenViewControllers {
  64. self.nvc.willReturnVCs = @[self.vc1, self.vc2, self.vc3];
  65. [self.uut setRoot:self.vc2 fromComponent:@"vc1" completion:nil];
  66. XCTAssertEqual(self.nvc.viewControllers.lastObject, self.vc2);
  67. XCTAssertEqual(self.nvc.viewControllers.count, 1);
  68. }
  69. @end