react-native-navigation的迁移库

RNNModalManagerTest.m 3.4KB

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