react-native-navigation的迁移库

RNNNavigationStackManagerTest.m 2.7KB

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