forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNNViewControllerPresenterTest.m
214 lines (169 loc) · 8.82 KB
/
RNNViewControllerPresenterTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import "RNNViewControllerPresenter.h"
#import "UIViewController+RNNOptions.h"
#import "RNNReactView.h"
#import "RNNRootViewController.h"
@interface RNNViewControllerPresenterTest : XCTestCase
@property (nonatomic, strong) RNNViewControllerPresenter *uut;
@property (nonatomic, strong) RNNNavigationOptions *options;
@property (nonatomic, strong) UIViewController *bindedViewController;
@property (nonatomic, strong) RNNReactComponentRegistry *componentRegistry;
@end
@implementation RNNViewControllerPresenterTest
- (void)setUp {
[super setUp];
self.componentRegistry = [OCMockObject partialMockForObject:[RNNReactComponentRegistry new]];
self.uut = [[RNNViewControllerPresenter alloc] initWithComponentRegistry:self.componentRegistry];
self.bindedViewController = [OCMockObject partialMockForObject:[RNNRootViewController new]];
[self.uut bindViewController:self.bindedViewController];
self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
}
- (void)testApplyOptions_backgroundImageDefaultNilShouldNotAddSubview {
[self.uut applyOptions:self.options];
XCTAssertTrue((self.bindedViewController.view.subviews.count) == 0);
}
- (void)testApplyOptions_topBarPrefersLargeTitleDefaultFalse {
[self.uut applyOptions:self.options];
XCTAssertTrue(self.bindedViewController.navigationItem.largeTitleDisplayMode == UINavigationItemLargeTitleDisplayModeNever);
}
- (void)testApplyOptions_layoutBackgroundColorDefaultWhiteColor {
[self.uut applyOptions:self.options];
XCTAssertNil(self.bindedViewController.view.backgroundColor);
}
- (void)testApplyOptions_statusBarBlurDefaultFalse {
[self.uut applyOptions:self.options];
XCTAssertNil([self.bindedViewController.view viewWithTag:BLUR_STATUS_TAG]);
}
- (void)testApplyOptions_statusBarStyleDefaultStyle {
[self.uut applyOptions:self.options];
XCTAssertTrue([self.bindedViewController preferredStatusBarStyle] == UIStatusBarStyleDefault);
}
- (void)testApplyOptions_backButtonVisibleDefaultTrue {
[self.uut applyOptions:self.options];
XCTAssertFalse(self.bindedViewController.navigationItem.hidesBackButton);
}
- (void)testApplyOptions_drawBehindTabBarTrueWhenVisibleFalse {
self.options.bottomTabs.visible = [[Bool alloc] initWithValue:@(0)];
[[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:YES];
[self.uut applyOptionsOnInit:self.options];
[(id)self.bindedViewController verify];
}
- (void)testApplyOptions_setOverlayTouchOutsideIfHasValue {
self.options.overlay.interceptTouchOutside = [[Bool alloc] initWithBOOL:YES];
[[(id)self.bindedViewController expect] rnn_setInterceptTouchOutside:YES];
[self.uut applyOptions:self.options];
[(id)self.bindedViewController verify];
}
- (void)testBindViewControllerShouldCreateNavigationButtonsCreator {
RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
[presenter bindViewController:self.bindedViewController];
XCTAssertNotNil(presenter.navigationButtons);
}
- (void)testApplyOptionsOnInit_shouldSetModalPresentetionStyleWithDefault {
[[(id)self.bindedViewController expect] rnn_setModalPresentationStyle:UIModalPresentationFullScreen];
[self.uut applyOptionsOnInit:self.options];
[(id)self.bindedViewController verify];
}
- (void)testApplyOptionsOnInit_shouldSetModalTransitionStyleWithDefault {
[[(id)self.bindedViewController expect] rnn_setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self.uut applyOptionsOnInit:self.options];
[(id)self.bindedViewController verify];
}
- (void)testApplyOptionsOnInit_shouldSetModalPresentetionStyleWithValue {
self.options.modalPresentationStyle = [[Text alloc] initWithValue:@"overCurrentContext"];
[[(id)self.bindedViewController expect] rnn_setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[self.uut applyOptionsOnInit:self.options];
[(id)self.bindedViewController verify];
}
- (void)testApplyOptionsOnInit_shouldSetModalTransitionStyleWithValue {
self.options.modalTransitionStyle = [[Text alloc] initWithValue:@"crossDissolve"];
[[(id)self.bindedViewController expect] rnn_setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self.uut applyOptionsOnInit:self.options];
[(id)self.bindedViewController verify];
}
-(void)testApplyOptionsOnInit_TopBarDrawUnder_true {
self.options.topBar.drawBehind = [[Bool alloc] initWithValue:@(1)];
[[(id)self.bindedViewController expect] rnn_setDrawBehindTopBar:YES];
[self.uut applyOptionsOnInit:self.options];
[(id)self.bindedViewController verify];
}
-(void)testApplyOptionsOnInit_TopBarDrawUnder_false {
self.options.topBar.drawBehind = [[Bool alloc] initWithValue:@(0)];
[[(id)self.bindedViewController expect] rnn_setDrawBehindTopBar:NO];
[self.uut applyOptionsOnInit:self.options];
[(id)self.bindedViewController verify];
}
-(void)testApplyOptionsOnInit_BottomTabsDrawUnder_true {
self.options.bottomTabs.drawBehind = [[Bool alloc] initWithValue:@(1)];
[[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:YES];
[self.uut applyOptionsOnInit:self.options];
[(id)self.bindedViewController verify];
}
-(void)testApplyOptionsOnInit_BottomTabsDrawUnder_false {
self.options.bottomTabs.drawBehind = [[Bool alloc] initWithValue:@(0)];
[[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:NO];
[self.uut applyOptionsOnInit:self.options];
[(id)self.bindedViewController verify];
}
- (void)testReactViewShouldBeReleasedOnDealloc {
RNNRootViewController* bindViewController = [RNNRootViewController new];
bindViewController.layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"];
[self.uut bindViewController:bindViewController];
self.options.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"componentName"}];
[[(id)self.componentRegistry expect] clearComponentsForParentId:self.uut.bindedComponentId];
self.uut = nil;
[(id)self.componentRegistry verify];
}
- (void)testBindViewControllerShouldSetBindedComponentId {
RNNRootViewController* bindViewController = [RNNRootViewController new];
RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
layoutInfo.componentId = @"componentId";
bindViewController.layoutInfo = layoutInfo;
[self.uut bindViewController:bindViewController];
XCTAssertEqual(self.uut.bindedComponentId, @"componentId");
}
- (void)testRenderComponentsCreateReactViewWithBindedComponentId {
RNNRootViewController* bindedViewController = [RNNRootViewController new];
RNNLayoutInfo* layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"];
bindedViewController.layoutInfo = layoutInfo;
[self.uut bindViewController:bindedViewController];
self.options.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"titleComponent"}];
[[(id)self.componentRegistry expect] createComponentIfNotExists:self.options.topBar.title.component parentComponentId:self.uut.bindedComponentId reactViewReadyBlock:[OCMArg any]];
[self.uut renderComponents:self.options perform:nil];
[(id)self.componentRegistry verify];
XCTAssertEqual(self.uut.bindedComponentId, @"componentId");
}
- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withTitle {
Text* title = [[Text alloc] initWithValue:@"Title"];
self.options.topBar.backButton.title = title;
[[(id)self.bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:title.get];
[self.uut applyOptionsOnWillMoveToParentViewController:self.options];
[(id)self.bindedViewController verify];
}
- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withHideTitle {
Text* title = [[Text alloc] initWithValue:@"Title"];
self.options.topBar.backButton.title = title;
self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)];
[[(id)self.bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:@""];
[self.uut applyOptionsOnWillMoveToParentViewController:self.options];
[(id)self.bindedViewController verify];
}
- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withIcon {
Image* image = [[Image alloc] initWithValue:[UIImage new]];
self.options.topBar.backButton.icon = image;
[[(id)self.bindedViewController expect] rnn_setBackButtonIcon:image.get withColor:nil title:nil];
[self.uut applyOptionsOnWillMoveToParentViewController:self.options];
[(id)self.bindedViewController verify];
}
- (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withDefaultValues {
[[(id)self.bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:nil];
[self.uut applyOptionsOnWillMoveToParentViewController:self.options];
[(id)self.bindedViewController verify];
}
- (RNNLayoutInfo *)createLayoutInfoWithComponentId:(NSString *)componentId {
RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
layoutInfo.componentId = @"componentId";
return layoutInfo;
}
@end