|
@@ -3,11 +3,15 @@
|
3
|
3
|
#import "RNNNavigationOptions.h"
|
4
|
4
|
#import "RNNTabBarPresenter.h"
|
5
|
5
|
#import "RNNRootViewController.h"
|
|
6
|
+#import "RNNNavigationController.h"
|
6
|
7
|
#import <OCMock/OCMock.h>
|
7
|
8
|
|
8
|
9
|
@interface RNNTabBarControllerTest : XCTestCase
|
9
|
10
|
|
10
|
|
-@property (nonatomic, strong) RNNTabBarController *uut;
|
|
11
|
+@property (nonatomic, strong) id mockUut;
|
|
12
|
+@property (nonatomic, strong) id mockChildViewController;
|
|
13
|
+@property (nonatomic, strong) id mockEventEmmiter;
|
|
14
|
+@property (nonatomic, strong) id mockTabBarPresenter;
|
11
|
15
|
|
12
|
16
|
@end
|
13
|
17
|
|
|
@@ -16,19 +20,26 @@
|
16
|
20
|
- (void)setUp {
|
17
|
21
|
[super setUp];
|
18
|
22
|
|
19
|
|
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[[[UIViewController alloc] init]] options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
|
|
23
|
+ id tabBarClassMock = OCMClassMock([RNNTabBarController class]);
|
|
24
|
+ OCMStub([tabBarClassMock parentViewController]).andReturn([OCMockObject partialMockForObject:[RNNTabBarController new]]);
|
|
25
|
+
|
|
26
|
+ self.mockTabBarPresenter = [OCMockObject partialMockForObject:[[RNNTabBarPresenter alloc] init]];
|
|
27
|
+ self.mockChildViewController = [OCMockObject partialMockForObject:[RNNRootViewController new]];
|
|
28
|
+ self.mockEventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
|
|
29
|
+ self.mockUut = [OCMockObject partialMockForObject:[[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[[[UIViewController alloc] init]] options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:self.mockTabBarPresenter eventEmitter:self.mockEventEmmiter]];
|
|
30
|
+ OCMStub([self.mockUut selectedViewController]).andReturn(self.mockChildViewController);
|
20
|
31
|
}
|
21
|
32
|
|
22
|
33
|
- (void)testInitWithLayoutInfo_shouldBindPresenter {
|
23
|
|
- XCTAssertNotNil(self.uut.presenter);
|
|
34
|
+ XCTAssertNotNil([self.mockUut presenter]);
|
24
|
35
|
}
|
25
|
36
|
|
26
|
37
|
- (void)testInitWithLayoutInfo_shouldSetMultipleViewControllers {
|
27
|
38
|
UIViewController* vc1 = [[UIViewController alloc] init];
|
28
|
39
|
UIViewController* vc2 = [[UIViewController alloc] init];
|
29
|
40
|
|
30
|
|
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[vc1, vc2] options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
|
31
|
|
- XCTAssertTrue(self.uut.viewControllers.count == 2);
|
|
41
|
+ RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[vc1, vc2] options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
|
|
42
|
+ XCTAssertTrue(uut.viewControllers.count == 2);
|
32
|
43
|
}
|
33
|
44
|
|
34
|
45
|
- (void)testInitWithLayoutInfo_shouldInitializeDependencies {
|
|
@@ -37,11 +48,11 @@
|
37
|
48
|
RNNTabBarPresenter* presenter = [[RNNTabBarPresenter alloc] init];
|
38
|
49
|
NSArray* childViewControllers = @[[UIViewController new]];
|
39
|
50
|
|
40
|
|
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options presenter:presenter];
|
41
|
|
- XCTAssertTrue(self.uut.layoutInfo == layoutInfo);
|
42
|
|
- XCTAssertTrue(self.uut.options == options);
|
43
|
|
- XCTAssertTrue(self.uut.presenter == presenter);
|
44
|
|
- XCTAssertTrue(self.uut.childViewControllers.count == childViewControllers.count);
|
|
51
|
+ RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options presenter:presenter];
|
|
52
|
+ XCTAssertTrue(uut.layoutInfo == layoutInfo);
|
|
53
|
+ XCTAssertTrue(uut.options == options);
|
|
54
|
+ XCTAssertTrue(uut.presenter == presenter);
|
|
55
|
+ XCTAssertTrue(uut.childViewControllers.count == childViewControllers.count);
|
45
|
56
|
}
|
46
|
57
|
|
47
|
58
|
- (void)testInitWithEventEmmiter_shouldInitializeDependencies {
|
|
@@ -52,134 +63,97 @@
|
52
|
63
|
|
53
|
64
|
NSArray* childViewControllers = @[[UIViewController new]];
|
54
|
65
|
|
55
|
|
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options presenter:presenter eventEmitter:eventEmmiter];
|
56
|
|
- XCTAssertTrue(self.uut.layoutInfo == layoutInfo);
|
57
|
|
- XCTAssertTrue(self.uut.options == options);
|
58
|
|
- XCTAssertTrue(self.uut.presenter == presenter);
|
59
|
|
- XCTAssertTrue(self.uut.childViewControllers.count == childViewControllers.count);
|
60
|
|
- XCTAssertTrue(self.uut.eventEmitter == eventEmmiter);
|
|
66
|
+ RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options presenter:presenter eventEmitter:eventEmmiter];
|
|
67
|
+ XCTAssertTrue(uut.layoutInfo == layoutInfo);
|
|
68
|
+ XCTAssertTrue(uut.options == options);
|
|
69
|
+ XCTAssertTrue(uut.presenter == presenter);
|
|
70
|
+ XCTAssertTrue(uut.childViewControllers.count == childViewControllers.count);
|
|
71
|
+ XCTAssertTrue(uut.eventEmitter == eventEmmiter);
|
61
|
72
|
}
|
62
|
73
|
|
63
|
74
|
- (void)testInitWithLayoutInfo_shouldSetDelegate {
|
64
|
|
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
|
|
75
|
+ RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
|
65
|
76
|
|
66
|
|
- XCTAssertTrue(self.uut.delegate == self.uut);
|
|
77
|
+ XCTAssertTrue(uut.delegate == uut);
|
67
|
78
|
}
|
68
|
79
|
|
69
|
80
|
- (void)testWillMoveToParent_invokePresenterApplyOptionsOnWillMoveToParent {
|
70
|
|
- id presenterMock = [OCMockObject partialMockForObject:[RNNTabBarPresenter new]];
|
71
|
|
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
72
|
|
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:presenterMock];
|
73
|
|
-
|
74
|
|
- [[presenterMock expect] applyOptionsOnWillMoveToParentViewController:options];
|
75
|
|
- [self.uut willMoveToParentViewController:[UIViewController new]];
|
76
|
|
- [presenterMock verify];
|
|
81
|
+ [[self.mockTabBarPresenter expect] applyOptionsOnWillMoveToParentViewController:[(RNNTabBarController *)self.mockUut options]];
|
|
82
|
+ [self.mockUut willMoveToParentViewController:[UIViewController new]];
|
|
83
|
+ [self.mockTabBarPresenter verify];
|
77
|
84
|
}
|
78
|
85
|
|
79
|
86
|
- (void)testWillMoveToParent_shouldNotInvokePresenterApplyOptionsOnWillMoveToNilParent {
|
80
|
|
- id presenterMock = [OCMockObject partialMockForObject:[RNNTabBarPresenter new]];
|
81
|
|
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
82
|
|
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:presenterMock];
|
83
|
|
-
|
84
|
|
- [[presenterMock reject] applyOptionsOnWillMoveToParentViewController:options];
|
85
|
|
- [self.uut willMoveToParentViewController:nil];
|
86
|
|
- [presenterMock verify];
|
|
87
|
+ [[self.mockTabBarPresenter reject] applyOptionsOnWillMoveToParentViewController:[(RNNTabBarController *)self.mockUut options]];
|
|
88
|
+ [self.mockUut willMoveToParentViewController:nil];
|
|
89
|
+ [self.mockTabBarPresenter verify];
|
87
|
90
|
}
|
88
|
91
|
|
89
|
92
|
- (void)testOnChildAppear_shouldInvokePresenterApplyOptionsWithResolvedOptions {
|
90
|
|
- id presenterMock = [OCMockObject partialMockForObject:[RNNTabBarPresenter new]];
|
91
|
|
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
92
|
|
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:presenterMock];
|
93
|
|
-
|
94
|
|
- [[presenterMock expect] applyOptions:[OCMArg any]];
|
95
|
|
- [uut onChildWillAppear];
|
96
|
|
- [presenterMock verify];
|
|
93
|
+ [[self.mockTabBarPresenter expect] applyOptions:[OCMArg any]];
|
|
94
|
+ [self.mockUut onChildWillAppear];
|
|
95
|
+ [self.mockTabBarPresenter verify];
|
97
|
96
|
}
|
98
|
97
|
|
99
|
98
|
- (void)testMergeOptions_shouldInvokePresenterMergeOptions {
|
100
|
|
- id presenterMock = [OCMockObject partialMockForObject:[RNNTabBarPresenter new]];
|
101
|
99
|
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
102
|
|
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:presenterMock];
|
103
|
100
|
|
104
|
|
- [(RNNTabBarPresenter *)[presenterMock expect] mergeOptions:options resolvedOptions:nil];
|
105
|
|
- [uut mergeOptions:options];
|
106
|
|
- [presenterMock verify];
|
|
101
|
+ [(RNNTabBarPresenter *)[self.mockTabBarPresenter expect] mergeOptions:options resolvedOptions:nil];
|
|
102
|
+ [(RNNTabBarController *)self.mockUut mergeOptions:options];
|
|
103
|
+ [self.mockTabBarPresenter verify];
|
107
|
104
|
}
|
108
|
105
|
|
109
|
106
|
- (void)testMergeOptions_shouldInvokeParentMergeOptions {
|
110
|
|
- id parentMock = [OCMockObject partialMockForObject:[RNNTabBarController new]];
|
|
107
|
+ id parentMock = [OCMockObject partialMockForObject:[RNNRootViewController new]];
|
111
|
108
|
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
112
|
|
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:[RNNTabBarPresenter new]];
|
113
|
|
- [parentMock addChildViewController:uut];
|
114
|
|
-
|
115
|
|
- [(RNNTabBarController *)[parentMock expect] mergeOptions:options];
|
116
|
|
- [uut mergeOptions:options];
|
|
109
|
+
|
|
110
|
+ OCMStub([self.mockUut parentViewController]).andReturn(parentMock);
|
|
111
|
+ [((RNNRootViewController *)[parentMock expect]) mergeOptions:options];
|
|
112
|
+ [(RNNTabBarController *)self.mockUut mergeOptions:options];
|
117
|
113
|
[parentMock verify];
|
118
|
114
|
}
|
119
|
115
|
|
120
|
116
|
- (void)testOnChildAppear_shouldInvokeParentOnChildAppear {
|
121
|
|
- id parentMock = [OCMockObject partialMockForObject:[RNNTabBarController new]];
|
122
|
|
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
123
|
|
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:[RNNTabBarPresenter new]];
|
124
|
|
- [parentMock addChildViewController:uut];
|
|
117
|
+ id parentMock = [OCMockObject partialMockForObject:[RNNNavigationController new]];
|
|
118
|
+
|
|
119
|
+ OCMStub([self.mockUut parentViewController]).andReturn(parentMock);
|
125
|
120
|
|
126
|
121
|
[[parentMock expect] onChildWillAppear];
|
127
|
|
- [uut onChildWillAppear];
|
|
122
|
+ [self.mockUut onChildWillAppear];
|
128
|
123
|
[parentMock verify];
|
129
|
124
|
}
|
130
|
125
|
|
131
|
126
|
- (void)testGetCurrentChild_shouldInvokeSelectedViewControllerGetCurrentChild {
|
132
|
|
- id childMock = [OCMockObject partialMockForObject:[RNNRootViewController new]];
|
133
|
|
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
134
|
|
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[childMock] options:options presenter:[RNNTabBarPresenter new]];
|
135
|
|
-
|
136
|
|
- [[childMock expect] getCurrentChild];
|
137
|
|
- [uut getCurrentChild];
|
138
|
|
- [childMock verify];
|
|
127
|
+ [[self.mockChildViewController expect] getCurrentChild];
|
|
128
|
+ [self.mockUut getCurrentChild];
|
|
129
|
+ [self.mockChildViewController verify];
|
139
|
130
|
}
|
140
|
131
|
|
141
|
132
|
- (void)testGetCurrentChild_shouldInvokeOnSelectedViewController {
|
142
|
|
- id childMock = [OCMockObject partialMockForObject:[RNNRootViewController new]];
|
143
|
|
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
144
|
|
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[[UIViewController new], childMock] options:options presenter:[RNNTabBarPresenter new]];
|
145
|
|
- [uut setSelectedIndex:1];
|
146
|
|
-
|
147
|
|
- [[childMock expect] getCurrentChild];
|
148
|
|
- [uut getCurrentChild];
|
149
|
|
- [childMock verify];
|
|
133
|
+ [[self.mockChildViewController expect] getCurrentChild];
|
|
134
|
+ [self.mockUut getCurrentChild];
|
|
135
|
+ [self.mockChildViewController verify];
|
150
|
136
|
}
|
151
|
137
|
|
152
|
138
|
- (void)testPreferredStatusBarStyle_shouldInvokeSelectedViewControllerPreferredStatusBarStyle {
|
153
|
|
- id childMock = [OCMockObject partialMockForObject:[RNNRootViewController new]];
|
154
|
|
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
155
|
|
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[childMock] options:options presenter:[RNNTabBarPresenter new]];
|
156
|
|
-
|
157
|
|
- [[childMock expect] preferredStatusBarStyle];
|
158
|
|
- [uut preferredStatusBarStyle];
|
159
|
|
- [childMock verify];
|
|
139
|
+ [[self.mockChildViewController expect] preferredStatusBarStyle];
|
|
140
|
+ [self.mockUut preferredStatusBarStyle];
|
|
141
|
+ [self.mockChildViewController verify];
|
160
|
142
|
}
|
161
|
143
|
|
162
|
144
|
- (void)testPreferredStatusBarStyle_shouldInvokeOnSelectedViewController {
|
163
|
|
- id childMock = [OCMockObject partialMockForObject:[RNNRootViewController new]];
|
164
|
|
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
165
|
|
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[[UIViewController new], childMock] options:options presenter:[RNNTabBarPresenter new]];
|
166
|
|
- [uut setSelectedIndex:1];
|
167
|
|
-
|
168
|
|
- [[childMock expect] preferredStatusBarStyle];
|
169
|
|
- [uut preferredStatusBarStyle];
|
170
|
|
- [childMock verify];
|
|
145
|
+ [[self.mockChildViewController expect] preferredStatusBarStyle];
|
|
146
|
+ [self.mockUut preferredStatusBarStyle];
|
|
147
|
+ [self.mockChildViewController verify];
|
171
|
148
|
}
|
172
|
149
|
|
173
|
150
|
- (void)testTabBarControllerDidSelectViewControllerDelegate_shouldInvokeSendBottomTabSelectedEvent {
|
174
|
|
- id eventEmmiterMock = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
|
175
|
|
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
176
|
|
- UIViewController* vc = [UIViewController new];
|
177
|
|
- UIViewController* vc2 = [UIViewController new];
|
178
|
|
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[vc, vc2] options:options presenter:[RNNTabBarPresenter new] eventEmitter:eventEmmiterMock];
|
179
|
|
- [uut setSelectedIndex:1];
|
180
|
|
- [[eventEmmiterMock expect] sendBottomTabSelected:[OCMArg any] unselected:[OCMArg any]];
|
181
|
|
- [uut tabBarController:uut didSelectViewController:vc2];
|
182
|
|
- [eventEmmiterMock verify];
|
|
151
|
+ NSUInteger selectedIndex = 2;
|
|
152
|
+ OCMStub([self.mockUut selectedIndex]).andReturn(selectedIndex);
|
|
153
|
+
|
|
154
|
+ [[self.mockEventEmmiter expect] sendBottomTabSelected:@(selectedIndex) unselected:@(0)];
|
|
155
|
+ [self.mockUut tabBarController:self.mockUut didSelectViewController:[UIViewController new]];
|
|
156
|
+ [self.mockEventEmmiter verify];
|
183
|
157
|
}
|
184
|
158
|
|
185
|
159
|
- (void)testSetSelectedIndexByComponentID_ShouldSetSelectedIndexWithCorrectIndex {
|