|
@@ -1,22 +1,109 @@
|
1
|
1
|
#import <XCTest/XCTest.h>
|
2
|
2
|
#import "RNNModalManager.h"
|
3
|
3
|
|
4
|
|
-@interface RNNModalManagerTest : XCTestCase
|
|
4
|
+@interface MockViewController : UIViewController
|
|
5
|
+@end
|
|
6
|
+@implementation MockViewController
|
|
7
|
+
|
|
8
|
+- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
|
|
9
|
+ completion();
|
|
10
|
+}
|
|
11
|
+
|
|
12
|
+@end
|
|
13
|
+
|
|
14
|
+@interface MockModalManager : RNNModalManager
|
|
15
|
+@end
|
|
16
|
+@implementation MockModalManager
|
|
17
|
+
|
|
18
|
+-(UIViewController*)topPresentedVC {
|
|
19
|
+ MockViewController* vc = [MockViewController new];
|
|
20
|
+ return vc;
|
|
21
|
+}
|
5
|
22
|
|
6
|
23
|
@end
|
7
|
24
|
|
8
|
|
-@implementation RNNModalManagerTest
|
|
25
|
+@interface RNNModalManagerTest : XCTestCase <RNNModalManagerDelegate> {
|
|
26
|
+ CGFloat _modalDismissedCount;
|
|
27
|
+}
|
|
28
|
+
|
|
29
|
+@end
|
|
30
|
+
|
|
31
|
+@implementation RNNModalManagerTest {
|
|
32
|
+ RNNRootViewController* _vc1;
|
|
33
|
+ RNNRootViewController* _vc2;
|
|
34
|
+ RNNRootViewController* _vc3;
|
|
35
|
+ MockModalManager* _modalManager;
|
|
36
|
+}
|
|
37
|
+
|
|
38
|
+- (void)setUp {
|
|
39
|
+ [super setUp];
|
|
40
|
+ _vc1 = [RNNRootViewController new];
|
|
41
|
+ _vc2 = [RNNRootViewController new];
|
|
42
|
+ _vc3 = [RNNRootViewController new];
|
|
43
|
+ _modalManager = [[MockModalManager alloc] init];
|
|
44
|
+}
|
|
45
|
+- (void)testDismissMultipleModalsInvokeDelegateWithCorrectParameters {
|
|
46
|
+ [_modalManager showModal:_vc1 animated:NO completion:nil];
|
|
47
|
+ [_modalManager showModal:_vc2 animated:NO completion:nil];
|
|
48
|
+ [_modalManager showModal:_vc3 animated:NO completion:nil];
|
|
49
|
+
|
|
50
|
+ _modalManager.delegate = self;
|
|
51
|
+ [_modalManager dismissAllModals];
|
|
52
|
+
|
|
53
|
+ XCTAssertTrue(_modalDismissedCount == 3);
|
|
54
|
+}
|
|
55
|
+
|
|
56
|
+- (void)testDismissModal_InvokeDelegateWithCorrectParameters {
|
|
57
|
+ [_modalManager showModal:_vc1 animated:NO completion:nil];
|
|
58
|
+ [_modalManager showModal:_vc2 animated:NO completion:nil];
|
|
59
|
+ [_modalManager showModal:_vc3 animated:NO completion:nil];
|
|
60
|
+
|
|
61
|
+ _modalManager.delegate = self;
|
|
62
|
+ [_modalManager dismissModal:_vc3 completion:nil];
|
|
63
|
+
|
|
64
|
+ XCTAssertTrue(_modalDismissedCount == 1);
|
|
65
|
+}
|
|
66
|
+
|
|
67
|
+- (void)testDismissPreviousModal_InvokeDelegateWithCorrectParameters {
|
|
68
|
+ [_modalManager showModal:_vc1 animated:NO completion:nil];
|
|
69
|
+ [_modalManager showModal:_vc2 animated:NO completion:nil];
|
|
70
|
+ [_modalManager showModal:_vc3 animated:NO completion:nil];
|
|
71
|
+
|
|
72
|
+ _modalManager.delegate = self;
|
|
73
|
+ [_modalManager dismissModal:_vc2 completion:nil];
|
|
74
|
+
|
|
75
|
+ XCTAssertTrue(_modalDismissedCount == 1);
|
|
76
|
+}
|
9
|
77
|
|
10
|
|
-- (void)testDismissAllModalsCleansPendingModalsToDismiss {
|
11
|
|
- RNNStore *store = [RNNStore new];
|
12
|
|
- [[store pendingModalIdsToDismiss] addObject:@"modal_id_1"];
|
13
|
|
- [[store pendingModalIdsToDismiss] addObject:@"modal_id_2"];
|
14
|
|
- [[store pendingModalIdsToDismiss] addObject:@"modal_id_3"];
|
|
78
|
+- (void)testDismissAllModalsAfterDismissingPreviousModal_InvokeDelegateWithCorrectParameters {
|
|
79
|
+ [_modalManager showModal:_vc1 animated:NO completion:nil];
|
|
80
|
+ [_modalManager showModal:_vc2 animated:NO completion:nil];
|
|
81
|
+ [_modalManager showModal:_vc3 animated:NO completion:nil];
|
15
|
82
|
|
16
|
|
- RNNModalManager *modalManager = [[RNNModalManager alloc] initWithStore:store];
|
17
|
|
- [modalManager dismissAllModals];
|
|
83
|
+ _modalManager.delegate = self;
|
|
84
|
+ [_modalManager dismissModal:_vc2 completion:nil];
|
18
|
85
|
|
19
|
|
- XCTAssertTrue([[store pendingModalIdsToDismiss] count] == 0);
|
|
86
|
+ XCTAssertTrue(_modalDismissedCount == 1);
|
|
87
|
+ [_modalManager dismissAllModals];
|
|
88
|
+ XCTAssertTrue(_modalDismissedCount == 2);
|
|
89
|
+}
|
|
90
|
+
|
|
91
|
+- (void)testDismissNilModal_doesntCrash {
|
|
92
|
+ _modalManager.delegate = self;
|
|
93
|
+ [_modalManager dismissModal:nil completion:nil];
|
|
94
|
+
|
|
95
|
+ XCTAssertTrue(_modalDismissedCount == 0);
|
|
96
|
+}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+#pragma mark RNNModalManagerDelegate
|
|
100
|
+
|
|
101
|
+- (void)dismissedMultipleModals:(NSArray *)viewControllers {
|
|
102
|
+ _modalDismissedCount = viewControllers.count;
|
|
103
|
+}
|
|
104
|
+
|
|
105
|
+- (void)dismissedModal:(UIViewController *)viewController {
|
|
106
|
+ _modalDismissedCount = 1;
|
20
|
107
|
}
|
21
|
108
|
|
22
|
109
|
@end
|