react-native-navigation的迁移库

RNNNavigationStackManagerTest.m 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #import <XCTest/XCTest.h>
  2. #import "RNNStore.h"
  3. #import "RNNNavigationStackManager.h"
  4. #import "RNNRootViewController.h"
  5. #import "RNNNavigationController.h"
  6. @interface RNNNavigationStackManagerTest : XCTestCase
  7. @property (nonatomic, strong) RNNNavigationController *nvc;
  8. @property (nonatomic, strong) UIViewController *vc1;
  9. @property (nonatomic, strong) UIViewController *vc2;
  10. @property (nonatomic, strong) UIViewController *vc3;
  11. @property (nonatomic, strong) RNNNavigationStackManager *stackManager;
  12. @end
  13. @implementation RNNNavigationStackManagerTest
  14. - (void)setUp {
  15. [super setUp];
  16. self.nvc = [[RNNNavigationController alloc] init];
  17. self.vc1 = [RNNRootViewController new];
  18. self.vc2 = [RNNRootViewController new];
  19. self.vc3 = [RNNRootViewController new];
  20. self.stackManager = [RNNNavigationStackManager new];
  21. NSArray *vcArray = @[self.vc1, self.vc2, self.vc3];
  22. [self.nvc setViewControllers:vcArray];
  23. }
  24. - (void)testPop_removeTopVCFromStack {
  25. XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"];
  26. XCTAssertTrue([self.nvc.topViewController isEqual:self.vc3]);
  27. [_stackManager popTo:self.vc2 animated:YES completion:^(NSArray *poppedViewControllers) {
  28. XCTAssertTrue([self.nvc.topViewController isEqual:self.vc2]);
  29. [expectation fulfill];
  30. } rejection:nil];
  31. [self waitForExpectationsWithTimeout:1 handler:nil];
  32. }
  33. - (void)testPopToSpecificVC_removeAllPopedVCFromStack {
  34. XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"];
  35. XCTAssertFalse([self.nvc.topViewController isEqual:self.vc1]);
  36. [_stackManager popTo:self.vc1 animated:NO completion:^(NSArray *poppedViewControllers) {
  37. XCTAssertTrue([self.nvc.topViewController isEqual:self.vc1]);
  38. [expectation fulfill];
  39. } rejection:nil];
  40. [self waitForExpectationsWithTimeout:1 handler:nil];
  41. }
  42. - (void)testPopToRoot_removeAllTopVCsFromStack {
  43. XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"];
  44. [_stackManager popToRoot:self.vc3 animated:NO completion:^(NSArray *poppedViewControllers) {
  45. XCTAssertTrue(self.nvc.childViewControllers.count == 1);
  46. XCTAssertTrue([self.nvc.topViewController isEqual:self.vc1]);
  47. [expectation fulfill];
  48. } rejection:nil];
  49. [self waitForExpectationsWithTimeout:1 handler:nil];
  50. }
  51. - (void)testStackRoot_shouldUpdateNavigationControllerChildrenViewControllers {
  52. XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"];
  53. [_stackManager setStackChildren:@[self.vc2] fromViewController:self.vc1 animated:NO completion:^{
  54. XCTAssertTrue(self.nvc.childViewControllers.count == 1);
  55. XCTAssertTrue([self.nvc.topViewController isEqual:self.vc2]);
  56. [expectation fulfill];
  57. } rejection:nil];
  58. [self waitForExpectationsWithTimeout:1 handler:nil];
  59. }
  60. @end