|
@@ -3,8 +3,10 @@
|
3
|
3
|
#import "RNNComponentPresenter.h"
|
4
|
4
|
#import "UIViewController+RNNOptions.h"
|
5
|
5
|
#import "RNNComponentViewController.h"
|
|
6
|
+#import "UIViewController+LayoutProtocol.h"
|
|
7
|
+#import "RNNTitleViewHelper.h"
|
6
|
8
|
|
7
|
|
-@interface RNNViewControllerPresenterTest : XCTestCase
|
|
9
|
+@interface RNNComponentPresenterTest : XCTestCase
|
8
|
10
|
|
9
|
11
|
@property (nonatomic, strong) RNNComponentPresenter *uut;
|
10
|
12
|
@property (nonatomic, strong) RNNNavigationOptions *options;
|
|
@@ -13,14 +15,14 @@
|
13
|
15
|
|
14
|
16
|
@end
|
15
|
17
|
|
16
|
|
-@implementation RNNViewControllerPresenterTest
|
|
18
|
+@implementation RNNComponentPresenterTest
|
17
|
19
|
|
18
|
20
|
- (void)setUp {
|
19
|
21
|
[super setUp];
|
20
|
22
|
self.componentRegistry = [OCMockObject partialMockForObject:[RNNReactComponentRegistry new]];
|
21
|
23
|
self.uut = [[RNNComponentPresenter alloc] initWithComponentRegistry:self.componentRegistry:[[RNNNavigationOptions alloc] initEmptyOptions]];
|
22
|
24
|
self.boundViewController = [OCMockObject partialMockForObject:[RNNComponentViewController new]];
|
23
|
|
- [self.uut bindViewController:self.boundViewController];
|
|
25
|
+ [self.uut boundViewController:self.boundViewController];
|
24
|
26
|
self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
|
25
|
27
|
}
|
26
|
28
|
|
|
@@ -71,7 +73,7 @@
|
71
|
73
|
|
72
|
74
|
- (void)testBindViewControllerShouldCreateNavigationButtonsCreator {
|
73
|
75
|
RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] init];
|
74
|
|
- [presenter bindViewController:self.boundViewController];
|
|
76
|
+ [presenter boundViewController:self.boundViewController];
|
75
|
77
|
XCTAssertNotNil(presenter.navigationButtons);
|
76
|
78
|
}
|
77
|
79
|
|
|
@@ -136,7 +138,7 @@
|
136
|
138
|
- (void)testReactViewShouldBeReleasedOnDealloc {
|
137
|
139
|
RNNComponentViewController* bindViewController = [RNNComponentViewController new];
|
138
|
140
|
bindViewController.layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"];
|
139
|
|
- [self.uut bindViewController:bindViewController];
|
|
141
|
+ [self.uut boundViewController:bindViewController];
|
140
|
142
|
|
141
|
143
|
self.options.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"componentName"}];
|
142
|
144
|
|
|
@@ -145,22 +147,21 @@
|
145
|
147
|
[(id)self.componentRegistry verify];
|
146
|
148
|
}
|
147
|
149
|
|
148
|
|
-- (void)testBindViewControllerShouldSetBindedComponentId {
|
|
150
|
+- (void)testBindViewControllerShouldSetBoundComponentId {
|
149
|
151
|
RNNComponentViewController* bindViewController = [RNNComponentViewController new];
|
150
|
152
|
RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
|
151
|
153
|
layoutInfo.componentId = @"componentId";
|
152
|
154
|
bindViewController.layoutInfo = layoutInfo;
|
153
|
|
-
|
154
|
|
- [self.uut bindViewController:bindViewController];
|
|
155
|
+
|
|
156
|
+ [self.uut boundViewController:bindViewController];
|
155
|
157
|
XCTAssertEqual(self.uut.boundComponentId, @"componentId");
|
156
|
158
|
}
|
157
|
159
|
|
158
|
|
-- (void)testRenderComponentsCreateReactViewWithBindedComponentId {
|
159
|
|
- RNNComponentViewController* bindedViewController = [RNNComponentViewController new];
|
|
160
|
+- (void)testRenderComponentsCreateReactViewWithBoundComponentId {
|
|
161
|
+ RNNComponentViewController* boundViewController = [RNNComponentViewController new];
|
160
|
162
|
RNNLayoutInfo* layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"];
|
161
|
|
- bindedViewController.layoutInfo = layoutInfo;
|
162
|
|
-
|
163
|
|
- [self.uut bindViewController:bindedViewController];
|
|
163
|
+ boundViewController.layoutInfo = layoutInfo;
|
|
164
|
+ [self.uut boundViewController:boundViewController];
|
164
|
165
|
|
165
|
166
|
self.options.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"titleComponent"}];
|
166
|
167
|
|
|
@@ -172,7 +173,7 @@
|
172
|
173
|
XCTAssertEqual(self.uut.boundComponentId, @"componentId");
|
173
|
174
|
}
|
174
|
175
|
|
175
|
|
-- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withTitle {
|
|
176
|
+- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBoundViewController_withTitle {
|
176
|
177
|
Text* title = [[Text alloc] initWithValue:@"Title"];
|
177
|
178
|
self.options.topBar.backButton.title = title;
|
178
|
179
|
[[(id) self.boundViewController expect] setBackButtonIcon:nil withColor:nil title:title.get];
|
|
@@ -180,7 +181,7 @@
|
180
|
181
|
[(id)self.boundViewController verify];
|
181
|
182
|
}
|
182
|
183
|
|
183
|
|
-- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withHideTitle {
|
|
184
|
+- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBoundViewController_withHideTitle {
|
184
|
185
|
Text* title = [[Text alloc] initWithValue:@"Title"];
|
185
|
186
|
self.options.topBar.backButton.title = title;
|
186
|
187
|
self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)];
|
|
@@ -189,7 +190,7 @@
|
189
|
190
|
[(id)self.boundViewController verify];
|
190
|
191
|
}
|
191
|
192
|
|
192
|
|
-- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withIcon {
|
|
193
|
+- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBoundViewController_withIcon {
|
193
|
194
|
Image* image = [[Image alloc] initWithValue:[UIImage new]];
|
194
|
195
|
self.options.topBar.backButton.icon = image;
|
195
|
196
|
[[(id) self.boundViewController expect] setBackButtonIcon:image.get withColor:nil title:nil];
|
|
@@ -197,16 +198,56 @@
|
197
|
198
|
[(id)self.boundViewController verify];
|
198
|
199
|
}
|
199
|
200
|
|
200
|
|
-- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withDefaultValues {
|
|
201
|
+- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBoundViewController_withDefaultValues {
|
201
|
202
|
[[(id) self.boundViewController expect] setBackButtonIcon:nil withColor:nil title:nil];
|
202
|
203
|
[self.uut applyOptionsOnWillMoveToParentViewController:self.options];
|
203
|
204
|
[(id)self.boundViewController verify];
|
204
|
205
|
}
|
205
|
206
|
|
|
207
|
+- (void)testRemoveTitleComponentIfNeeded_componentIsRemovedIfTitleTextIsDefined {
|
|
208
|
+ id mockTitle = [OCMockObject niceMockForClass:[RNNReactView class]];
|
|
209
|
+ OCMStub([self.componentRegistry createComponentIfNotExists:[OCMArg any] parentComponentId:[OCMArg any] reactViewReadyBlock:nil]).andReturn(mockTitle);
|
|
210
|
+
|
|
211
|
+ RNNComponentOptions* component = [RNNComponentOptions new];
|
|
212
|
+ component.name = [[Text alloc] initWithValue:@"componentName"];
|
|
213
|
+ component.componentId = [[Text alloc] initWithValue:@"someId"];
|
|
214
|
+ _options.topBar.title.component = component;
|
|
215
|
+
|
|
216
|
+ [self.uut mergeOptions:_options resolvedOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
|
|
217
|
+ XCTAssertNotNil(self.boundViewController.navigationItem.titleView);
|
|
218
|
+ XCTAssertEqual(self.boundViewController.navigationItem.titleView, mockTitle);
|
|
219
|
+
|
|
220
|
+ [[mockTitle expect] removeFromSuperview];
|
|
221
|
+ _options = [[RNNNavigationOptions alloc] initEmptyOptions];
|
|
222
|
+ _options.topBar.title.text = [[Text alloc] initWithValue:@""];
|
|
223
|
+ [self.uut mergeOptions:_options resolvedOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
|
|
224
|
+ XCTAssertNotEqual(self.boundViewController.navigationItem.titleView, mockTitle);
|
|
225
|
+ [mockTitle verify];
|
|
226
|
+}
|
|
227
|
+
|
|
228
|
+- (void)testRemoveTitleComponentIfNeeded_componentIsNotRemovedIfMergeOptionsIsCalledWithoutTitleText {
|
|
229
|
+ id mockTitle = [OCMockObject niceMockForClass:[RNNReactView class]];
|
|
230
|
+ OCMStub([self.componentRegistry createComponentIfNotExists:[OCMArg any] parentComponentId:[OCMArg any] reactViewReadyBlock:nil]).andReturn(mockTitle);
|
|
231
|
+
|
|
232
|
+ RNNComponentOptions* component = [RNNComponentOptions new];
|
|
233
|
+ component.name = [[Text alloc] initWithValue:@"componentName"];
|
|
234
|
+ component.componentId = [[Text alloc] initWithValue:@"someId"];
|
|
235
|
+ _options.topBar.title.component = component;
|
|
236
|
+
|
|
237
|
+ [self.uut mergeOptions:_options resolvedOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
|
|
238
|
+ XCTAssertNotNil(self.boundViewController.navigationItem.titleView);
|
|
239
|
+ XCTAssertEqual(self.boundViewController.navigationItem.titleView, mockTitle);
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+ _options = [[RNNNavigationOptions alloc] initEmptyOptions];
|
|
243
|
+ _options.bottomTabs.visible = [[Bool alloc] initWithBOOL:NO];
|
|
244
|
+ [self.uut mergeOptions:_options resolvedOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
|
|
245
|
+ XCTAssertEqual(self.boundViewController.navigationItem.titleView, mockTitle);
|
|
246
|
+}
|
206
|
247
|
|
207
|
248
|
- (RNNLayoutInfo *)createLayoutInfoWithComponentId:(NSString *)componentId {
|
208
|
249
|
RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
|
209
|
|
- layoutInfo.componentId = @"componentId";
|
|
250
|
+ layoutInfo.componentId = componentId;
|
210
|
251
|
return layoutInfo;
|
211
|
252
|
}
|
212
|
253
|
|