123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #import <XCTest/XCTest.h>
- #import "RNNModalManager.h"
- #import "RNNComponentViewController.h"
-
- @interface MockViewController : UIViewController
-
- @property CGFloat presentViewControllerCalls;
-
- @end
- @implementation MockViewController
-
- - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
- _presentViewControllerCalls++;
- completion();
- }
-
- @end
-
- @interface MockModalManager : RNNModalManager
- @property (nonatomic, strong) MockViewController* topPresentedVC;
- @end
-
- @implementation MockModalManager
- @end
-
- @interface RNNModalManagerTest : XCTestCase <RNNModalManagerDelegate> {
- CGFloat _modalDismissedCount;
- }
-
- @end
-
- @implementation RNNModalManagerTest {
- RNNComponentViewController* _vc1;
- RNNComponentViewController* _vc2;
- RNNComponentViewController* _vc3;
- MockModalManager* _modalManager;
- }
-
- - (void)setUp {
- [super setUp];
- _vc1 = [RNNComponentViewController new];
- _vc2 = [RNNComponentViewController new];
- _vc3 = [RNNComponentViewController new];
- _modalManager = [[MockModalManager alloc] init];
- _modalManager.topPresentedVC = [MockViewController new];
- }
-
- - (void)testDismissMultipleModalsInvokeDelegateWithCorrectParameters {
- [_modalManager showModal:_vc1 animated:NO completion:nil];
- [_modalManager showModal:_vc2 animated:NO completion:nil];
- [_modalManager showModal:_vc3 animated:NO completion:nil];
-
- _modalManager.delegate = self;
- [_modalManager dismissAllModalsAnimated:NO completion:nil];
-
- XCTAssertTrue(_modalDismissedCount == 3);
- }
-
- - (void)testDismissModal_InvokeDelegateWithCorrectParameters {
- [_modalManager showModal:_vc1 animated:NO completion:nil];
- [_modalManager showModal:_vc2 animated:NO completion:nil];
- [_modalManager showModal:_vc3 animated:NO completion:nil];
-
- _modalManager.delegate = self;
- [_modalManager dismissModal:_vc3 completion:nil];
-
- XCTAssertTrue(_modalDismissedCount == 1);
- }
-
- - (void)testDismissPreviousModal_InvokeDelegateWithCorrectParameters {
- [_modalManager showModal:_vc1 animated:NO completion:nil];
- [_modalManager showModal:_vc2 animated:NO completion:nil];
- [_modalManager showModal:_vc3 animated:NO completion:nil];
-
- _modalManager.delegate = self;
- [_modalManager dismissModal:_vc2 completion:nil];
-
- XCTAssertTrue(_modalDismissedCount == 1);
- }
-
- - (void)testDismissAllModals_AfterDismissingPreviousModal_InvokeDelegateWithCorrectParameters {
- [_modalManager showModal:_vc1 animated:NO completion:nil];
- [_modalManager showModal:_vc2 animated:NO completion:nil];
- [_modalManager showModal:_vc3 animated:NO completion:nil];
-
- _modalManager.delegate = self;
- [_modalManager dismissModal:_vc2 completion:nil];
-
- XCTAssertTrue(_modalDismissedCount == 1);
- [_modalManager dismissAllModalsAnimated:NO completion:nil];
- XCTAssertTrue(_modalDismissedCount == 2);
- }
-
- - (void)testDismissModal_DismissNilModalDoesntCrash {
- _modalManager.delegate = self;
- [_modalManager dismissModal:nil completion:nil];
-
- XCTAssertTrue(_modalDismissedCount == 0);
- }
-
- - (void)testShowModal_NilModalThrows {
- XCTAssertThrows([_modalManager showModal:nil animated:NO completion:nil]);
- }
-
- - (void)testShowModal_CallPresentViewController {
- [_modalManager showModal:_vc1 animated:NO completion:nil];
- XCTAssertTrue(_modalManager.topPresentedVC.presentViewControllerCalls == 1);
- }
-
- #pragma mark RNNModalManagerDelegate
-
- - (void)dismissedMultipleModals:(NSArray *)viewControllers {
- _modalDismissedCount = viewControllers.count;
- }
-
- - (void)dismissedModal:(UIViewController *)viewController {
- _modalDismissedCount = 1;
- }
-
- @end
|