forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNNNavigationControllerTest.m
160 lines (121 loc) · 6.79 KB
/
RNNNavigationControllerTest.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
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import "RNNNavigationController.h"
#import "RNNRootViewController.h"
#import "RNNTestRootViewCreator.h"
@interface RNNNavigationControllerTest : XCTestCase
@property (nonatomic, strong) RNNNavigationController *uut;
@end
@implementation RNNNavigationControllerTest {
RNNRootViewController* _vc1;
id _vc2Mock;
RNNRootViewController* _vc2;
UIViewController* _vc3;
RNNNavigationOptions* _options;
RNNTestRootViewCreator* _creator;
}
- (void)setUp {
[super setUp];
_creator = [[RNNTestRootViewCreator alloc] init];
_vc1 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[OCMockObject partialMockForObject:[[RNNViewControllerPresenter alloc] init]] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
_vc2 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
_vc2Mock = [OCMockObject partialMockForObject:_vc2];
_vc3 = [UIViewController new];
_options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]] eventEmitter:nil childViewControllers:@[_vc1, _vc2]];
}
- (void)testInitWithLayoutInfo_shouldBindPresenter {
XCTAssertNotNil(self.uut.presenter);
}
- (void)testInitWithLayoutInfo_shouldSetMultipleViewControllers {
self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNViewControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[_vc1, _vc2]];
XCTAssertTrue(self.uut.viewControllers.count == 2);
}
- (void)testChildViewControllerForStatusBarStyle_shouldReturnTopViewController {
XCTAssertTrue(self.uut.childViewControllerForStatusBarStyle == self.uut.topViewController);
}
- (void)testCurrentChild_shouldReturnTopViewController {
XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
}
- (void)testGetLeafViewController_shouldReturnTopViewController {
XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
}
- (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle {
self.uut.getCurrentChild.resolveOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getCurrentChild.preferredStatusBarStyle);
}
- (void)testPopGestureEnabled_false {
NSNumber* popGestureEnabled = @(0);
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled];
self.uut = [self createNavigationControllerWithOptions:options];
[self.uut viewWillAppear:false];
XCTAssertFalse(self.uut.interactivePopGestureRecognizer.enabled);
}
- (void)testPopGestureEnabled_true {
NSNumber* popGestureEnabled = @(1);
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled];
self.uut = [self createNavigationControllerWithOptions:options];
[self.uut onChildWillAppear];
XCTAssertTrue(self.uut.interactivePopGestureRecognizer.enabled);
}
- (void)testRootBackgroundImage {
UIImage* rootBackgroundImage = [[UIImage alloc] init];
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
options.rootBackgroundImage = [[Image alloc] initWithValue:rootBackgroundImage];
self.uut = [self createNavigationControllerWithOptions:options];
[self.uut onChildWillAppear];
XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:rootBackgroundImage]);
}
- (void)testTopBarBackgroundClipToBounds_true {
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(1)];
self.uut = [self createNavigationControllerWithOptions:options];
[self.uut onChildWillAppear];
XCTAssertTrue(self.uut.navigationBar.clipsToBounds);
}
- (void)testTopBarBackgroundClipToBounds_false {
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(0)];
self.uut = [self createNavigationControllerWithOptions:options];
XCTAssertFalse(self.uut.navigationController.navigationBar.clipsToBounds);
}
- (void)testSupportedOrientationsShouldReturnCurrentChildSupportedOrientations {
XCTAssertEqual(self.uut.supportedInterfaceOrientations, self.uut.getCurrentChild.supportedInterfaceOrientations);
}
- (void)testPopViewControllerReturnLastChildViewController {
RNNNavigationController* uut = [RNNNavigationController new];
[uut setViewControllers:@[_vc1, _vc2]];
XCTAssertEqual([uut popViewControllerAnimated:NO], _vc2);
}
- (void)testPopViewControllerSetTopBarBackgroundForPoppingViewController {
_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
[_vc1 overrideOptions:_options];
[self.uut popViewControllerAnimated:NO];
XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.barTintColor);
}
- (void)testPopViewControllerSetDefaultTopBarBackgroundForPoppingViewController {
_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
[_vc1 setDefaultOptions:_options];
[self.uut popViewControllerAnimated:NO];
XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.barTintColor);
}
- (void)testPopViewControllerShouldInvokeApplyOptionsBeforePoppingForDestinationViewController {
RNNNavigationController* uut = [RNNNavigationController new];
[uut setViewControllers:@[_vc1, _vc2]];
[[(id)uut.presenter expect] applyOptionsBeforePopping:[OCMArg any]];
[uut popViewControllerAnimated:NO];
[(id)uut.presenter verify];
}
- (void)testOverrideOptionsShouldOverrideOptionsState {
RNNNavigationOptions* overrideOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
[(RNNNavigationOptions*)[(id)self.uut.options expect] overrideOptions:overrideOptions];
[self.uut overrideOptions:overrideOptions];
[(id)self.uut.options verify];
}
- (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[_vc1]];
return nav;
}
@end