react-native-navigation的迁移库

RNNNavigationStackManagerTest.m 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #import <XCTest/XCTest.h>
  2. #import "RNNStore.h"
  3. #import "RNNNavigationStackManager.h"
  4. @interface RNNNavigationStackManagerTest : XCTestCase
  5. @property (nonatomic, strong) RNNStore *store;
  6. @property (nonatomic, strong) UINavigationController *nvc;
  7. @property (nonatomic, strong) UIViewController *vc1;
  8. @property (nonatomic, strong) UIViewController *vc2;
  9. @property (nonatomic, strong) UIViewController *vc3;
  10. @property (nonatomic, strong) RNNNavigationStackManager *stackManager;
  11. @end
  12. @implementation RNNNavigationStackManagerTest
  13. - (void)setUp {
  14. [super setUp];
  15. self.store = [RNNStore new];
  16. self.nvc = [[UINavigationController 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 setStackRoot: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