react-native-navigation的迁移库

RNNNavigationStackManagerTest.m 2.7KB

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