react-native-navigation的迁移库

RNNModalManagerTest.m 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #import <XCTest/XCTest.h>
  2. #import "RNNModalManager.h"
  3. @interface MockViewController : UIViewController
  4. @end
  5. @implementation MockViewController
  6. - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
  7. completion();
  8. }
  9. @end
  10. @interface MockModalManager : RNNModalManager
  11. @end
  12. @implementation MockModalManager
  13. -(UIViewController*)topPresentedVC {
  14. MockViewController* vc = [MockViewController new];
  15. return vc;
  16. }
  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. }
  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 dismissAllModals];
  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)testDismissAllModalsAfterDismissingPreviousModal_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 dismissAllModals];
  67. XCTAssertTrue(_modalDismissedCount == 2);
  68. }
  69. - (void)testDismissNilModal_doesntCrash {
  70. _modalManager.delegate = self;
  71. [_modalManager dismissModal:nil completion:nil];
  72. XCTAssertTrue(_modalDismissedCount == 0);
  73. }
  74. #pragma mark RNNModalManagerDelegate
  75. - (void)dismissedMultipleModals:(NSArray *)viewControllers {
  76. _modalDismissedCount = viewControllers.count;
  77. }
  78. - (void)dismissedModal:(UIViewController *)viewController {
  79. _modalDismissedCount = 1;
  80. }
  81. @end