react-native-navigation的迁移库

RNNModalManagerTest.m 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #import <XCTest/XCTest.h>
  2. #import "RNNModalManager.h"
  3. #import "RNNRootViewController.h"
  4. @interface MockViewController : UIViewController
  5. @property CGFloat presentViewControllerCalls;
  6. @end
  7. @implementation MockViewController
  8. - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
  9. _presentViewControllerCalls++;
  10. completion();
  11. }
  12. @end
  13. @interface MockModalManager : RNNModalManager
  14. @property (nonatomic, strong) MockViewController* topPresentedVC;
  15. @end
  16. @implementation MockModalManager
  17. @end
  18. @interface RNNModalManagerTest : XCTestCase <RNNModalManagerDelegate> {
  19. CGFloat _modalDismissedCount;
  20. }
  21. @end
  22. @implementation RNNModalManagerTest {
  23. RNNRootViewController* _vc1;
  24. RNNRootViewController* _vc2;
  25. RNNRootViewController* _vc3;
  26. MockModalManager* _modalManager;
  27. }
  28. - (void)setUp {
  29. [super setUp];
  30. _vc1 = [RNNRootViewController new];
  31. _vc2 = [RNNRootViewController new];
  32. _vc3 = [RNNRootViewController new];
  33. _modalManager = [[MockModalManager alloc] init];
  34. _modalManager.topPresentedVC = [MockViewController new];
  35. }
  36. - (void)testDismissMultipleModalsInvokeDelegateWithCorrectParameters {
  37. [_modalManager showModal:_vc1 animated:NO completion:nil];
  38. [_modalManager showModal:_vc2 animated:NO completion:nil];
  39. [_modalManager showModal:_vc3 animated:NO completion:nil];
  40. _modalManager.delegate = self;
  41. [_modalManager dismissAllModalsAnimated:NO];
  42. XCTAssertTrue(_modalDismissedCount == 3);
  43. }
  44. - (void)testDismissModal_InvokeDelegateWithCorrectParameters {
  45. [_modalManager showModal:_vc1 animated:NO completion:nil];
  46. [_modalManager showModal:_vc2 animated:NO completion:nil];
  47. [_modalManager showModal:_vc3 animated:NO completion:nil];
  48. _modalManager.delegate = self;
  49. [_modalManager dismissModal:_vc3 completion:nil];
  50. XCTAssertTrue(_modalDismissedCount == 1);
  51. }
  52. - (void)testDismissPreviousModal_InvokeDelegateWithCorrectParameters {
  53. [_modalManager showModal:_vc1 animated:NO completion:nil];
  54. [_modalManager showModal:_vc2 animated:NO completion:nil];
  55. [_modalManager showModal:_vc3 animated:NO completion:nil];
  56. _modalManager.delegate = self;
  57. [_modalManager dismissModal:_vc2 completion:nil];
  58. XCTAssertTrue(_modalDismissedCount == 1);
  59. }
  60. - (void)testDismissAllModals_AfterDismissingPreviousModal_InvokeDelegateWithCorrectParameters {
  61. [_modalManager showModal:_vc1 animated:NO completion:nil];
  62. [_modalManager showModal:_vc2 animated:NO completion:nil];
  63. [_modalManager showModal:_vc3 animated:NO completion:nil];
  64. _modalManager.delegate = self;
  65. [_modalManager dismissModal:_vc2 completion:nil];
  66. XCTAssertTrue(_modalDismissedCount == 1);
  67. [_modalManager dismissAllModalsAnimated:NO];
  68. XCTAssertTrue(_modalDismissedCount == 2);
  69. }
  70. - (void)testDismissModal_DismissNilModalDoesntCrash {
  71. _modalManager.delegate = self;
  72. [_modalManager dismissModal:nil completion:nil];
  73. XCTAssertTrue(_modalDismissedCount == 0);
  74. }
  75. - (void)testShowModal_NilModalThrows {
  76. XCTAssertThrows([_modalManager showModal:nil animated:NO completion:nil]);
  77. }
  78. - (void)testShowModal_CallPresentViewController {
  79. [_modalManager showModal:_vc1 animated:NO completion:nil];
  80. XCTAssertTrue(_modalManager.topPresentedVC.presentViewControllerCalls == 1);
  81. }
  82. #pragma mark RNNModalManagerDelegate
  83. - (void)dismissedMultipleModals:(NSArray *)viewControllers {
  84. _modalDismissedCount = viewControllers.count;
  85. }
  86. - (void)dismissedModal:(UIViewController *)viewController {
  87. _modalDismissedCount = 1;
  88. }
  89. @end