Bladeren bron

Apply modalPresentationStyle and modalTransitionStyle on childWillMov… (#4176)

* Apply modalPresentationStyle and modalTransitionStyle on childWillMoveToParent

* Fixes unit tests

* Fixes flaky unit tests caused by OCMock
Yogev Ben David 6 jaren geleden
bovenliggende
commit
1151587bdf
No account linked to committer's email address

+ 2
- 0
lib/ios/RNNBasePresenter.h Bestand weergeven

@@ -8,6 +8,8 @@
8 8
 
9 9
 - (void)bindViewController:(UIViewController *)bindedViewController;
10 10
 
11
+- (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions;
12
+
11 13
 - (void)applyOptions:(RNNNavigationOptions *)initialOptions;
12 14
 
13 15
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options;

+ 4
- 0
lib/ios/RNNBasePresenter.m Bestand weergeven

@@ -20,6 +20,10 @@
20 20
 	[self.bottomTabPresenter bindViewController:bindedViewController];
21 21
 }
22 22
 
23
+- (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
24
+	
25
+}
26
+
23 27
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
24 28
 	[self.bottomTabPresenter applyOptions:options];
25 29
 }

+ 2
- 1
lib/ios/RNNRootViewController.m Bestand weergeven

@@ -39,6 +39,7 @@
39 39
 	self.presenter = presenter;
40 40
 	[self.presenter bindViewController:self];
41 41
 	self.options = options;
42
+	[self.presenter applyOptionsOnInit:self.options];
42 43
 	
43 44
 	self.animator = [[RNNAnimator alloc] initWithTransitionOptions:self.options.customTransition];
44 45
 	
@@ -47,7 +48,7 @@
47 48
 												 name:RCTJavaScriptWillStartLoadingNotification
48 49
 											   object:nil];
49 50
 	self.navigationController.delegate = self;
50
-
51
+	
51 52
 	return self;
52 53
 }
53 54
 

+ 8
- 2
lib/ios/RNNViewControllerPresenter.m Bestand weergeven

@@ -17,8 +17,6 @@
17 17
 	
18 18
 	UIViewController* viewController = self.bindedViewController;
19 19
 	[viewController rnn_setBackgroundImage:[options.backgroundImage getWithDefaultValue:nil]];
20
-	[viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:[options.modalPresentationStyle getWithDefaultValue:@"fullScreen"]]];
21
-	[viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[options.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
22 20
 	[viewController rnn_setDrawBehindTopBar:[options.topBar.drawBehind getWithDefaultValue:NO]];
23 21
 	[viewController rnn_setNavigationItemTitle:[options.topBar.title.text getWithDefaultValue:nil]];
24 22
 	[viewController rnn_setTopBarPrefersLargeTitle:[options.topBar.largeTitle.visible getWithDefaultValue:NO]];
@@ -43,6 +41,14 @@
43 41
 	
44 42
 }
45 43
 
44
+- (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
45
+	[super applyOptionsOnInit:options];
46
+	
47
+	UIViewController* viewController = self.bindedViewController;
48
+	[viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:[options.modalPresentationStyle getWithDefaultValue:@"fullScreen"]]];
49
+	[viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[options.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
50
+}
51
+
46 52
 - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
47 53
 	[super mergeOptions:options resolvedOptions:resolvedOptions];
48 54
 	

+ 22
- 80
lib/ios/ReactNativeNavigationTests/RNNBottomTabPresenterTest.m Bestand weergeven

@@ -7,7 +7,8 @@
7 7
 
8 8
 @property (nonatomic, strong) RNNBottomTabPresenter *uut;
9 9
 @property (nonatomic, strong) RNNNavigationOptions *options;
10
-@property (nonatomic, strong) id bindedViewController;
10
+@property (nonatomic, strong) UIViewController* bindedViewController;
11
+@property (nonatomic, strong) id mockBindedViewController;
11 12
 
12 13
 @end
13 14
 
@@ -16,104 +17,45 @@
16 17
 - (void)setUp {
17 18
     [super setUp];
18 19
     self.uut = [[RNNBottomTabPresenter alloc] init];
19
-    self.bindedViewController = [OCMockObject partialMockForObject:[UIViewController new]];
20
-    [self.uut bindViewController:self.bindedViewController];
20
+	self.bindedViewController = [UIViewController new];
21
+    self.mockBindedViewController = [OCMockObject partialMockForObject:self.bindedViewController];
22
+    [self.uut bindViewController:self.mockBindedViewController];
21 23
     self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
22 24
 }
23 25
 
26
+- (void)tearDown {
27
+	[super tearDown];
28
+	[self.mockBindedViewController stopMocking];
29
+	self.bindedViewController = nil;
30
+}
31
+
24 32
 - (void)testApplyOptions_shouldSetTabBarItemBadgeWithDefaultWhenParentIsUITabBarController {
25
-	UITabBarController* tabBarController = [[UITabBarController alloc] init];
26
-	[tabBarController setViewControllers:@[self.bindedViewController]];
27
-	[[self.bindedViewController expect] rnn_setTabBarItemBadge:nil];
33
+	OCMStub([self.mockBindedViewController parentViewController]).andReturn([UITabBarController new]);
34
+	[[self.mockBindedViewController expect] rnn_setTabBarItemBadge:nil];
28 35
 	[self.uut applyOptions:self.options];
29
-	[self.bindedViewController verify];
36
+	[self.mockBindedViewController verify];
30 37
 }
31 38
 
32 39
 - (void)testApplyOptions_shouldSetTabBarItemBadgeOnlyWhenParentIsUITabBarController {
33
-	[[self.bindedViewController reject] rnn_setTabBarItemBadge:[OCMArg any]];
40
+	[[self.mockBindedViewController reject] rnn_setTabBarItemBadge:[OCMArg any]];
34 41
 	[self.uut applyOptions:self.options];
35
-	[self.bindedViewController verify];
42
+	[self.mockBindedViewController verify];
36 43
 }
37 44
 
38 45
 - (void)testApplyOptions_shouldSetTabBarItemBadgeWithValue {
39
-	UITabBarController* tabBarController = [[UITabBarController alloc] init];
40
-	[tabBarController setViewControllers:@[self.bindedViewController]];
46
+	OCMStub([self.mockBindedViewController parentViewController]).andReturn([UITabBarController new]);
41 47
 	self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
42
-	[[self.bindedViewController expect] rnn_setTabBarItemBadge:@"badge"];
48
+	[[self.mockBindedViewController expect] rnn_setTabBarItemBadge:@"badge"];
43 49
 	[self.uut applyOptions:self.options];
44
-	[self.bindedViewController verify];
50
+	[self.mockBindedViewController verify];
45 51
 }
46 52
 
47 53
 - (void)testApplyOptions_setTabBarItemBadgeShouldNotCalledOnUITabBarController {
48
-	self.bindedViewController = [OCMockObject partialMockForObject:[UITabBarController new]];
49
-	[self.uut bindViewController:self.bindedViewController];
54
+	[self.uut bindViewController:self.mockBindedViewController];
50 55
 	self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
51
-	[[self.bindedViewController reject] rnn_setTabBarItemBadge:@"badge"];
56
+	[[self.mockBindedViewController reject] rnn_setTabBarItemBadge:@"badge"];
52 57
 	[self.uut applyOptions:self.options];
53
-	[self.bindedViewController verify];
58
+	[self.mockBindedViewController verify];
54 59
 }
55 60
 
56
-//- (void)test_tabBarTextFontFamily_validFont {
57
-//	UIViewController* viewController = [UIViewController new];
58
-//
59
-//	NSString* inputFont = @"HelveticaNeue";
60
-//	UIFont* expectedFont = [UIFont fontWithName:inputFont size:10];
61
-//
62
-//	self.uut.fontFamily = inputFont;
63
-//	self.uut.text = @"Tab 1";
64
-//
65
-//	[self.uut rnn_set];
66
-//
67
-//	NSDictionary* attributes = [viewController.tabBarItem titleTextAttributesForState:UIControlStateNormal];
68
-//	XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
69
-//}
70
-
71
-//- (void)test_tabBarTextFontSize_withoutTextFontFamily_withoutTextColor {
72
-//	UIViewController* viewController = [UIViewController new];
73
-//
74
-//	UIFont* expectedFont = [UIFont systemFontOfSize:15];
75
-//
76
-//	self.uut.fontSize = @(15);
77
-//	self.uut.text = @"Tab 1";
78
-//
79
-//	[self.uut applyOn:viewController];
80
-//
81
-//	NSDictionary* attributes = [viewController.tabBarItem titleTextAttributesForState:UIControlStateNormal];
82
-//	XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
83
-//}
84
-//
85
-//- (void)test_tabBarTextFontSize_withoutTextFontFamily {
86
-//	UIViewController* viewController = [UIViewController new];
87
-//
88
-//	UIFont* expectedFont = [UIFont systemFontOfSize:15];
89
-//
90
-//	self.uut.fontSize = @(15);
91
-//	self.uut.text = @"Tab 1";
92
-//
93
-//	[self.uut applyOn:viewController];
94
-//
95
-//	NSDictionary* attributes = [viewController.tabBarItem titleTextAttributesForState:UIControlStateNormal];
96
-//	XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
97
-//}
98
-//
99
-//- (void)test_tabBarTextFontSize_withTextFontFamily_withTextColor {
100
-//	UIViewController* viewController = [UIViewController new];
101
-//
102
-//	NSString* inputFont = @"HelveticaNeue";
103
-//	UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
104
-//
105
-//	self.uut.fontSize = @(15);
106
-//	self.uut.text = @"Tab 1";
107
-//	self.uut.fontFamily = inputFont;
108
-//	self.uut.textColor = @(4279979127);
109
-//	[self.uut applyOn:viewController];
110
-//
111
-//	NSDictionary* attributes = [viewController.tabBarItem titleTextAttributesForState:UIControlStateNormal];
112
-//	UIColor* color = attributes[NSForegroundColorAttributeName];
113
-//	UIColor* expectedColor = [RCTConvert UIColor:@(4279979127)];
114
-//
115
-//	XCTAssertTrue([color isEqual:expectedColor]);
116
-//	XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
117
-//}
118
-
119 61
 @end

+ 68
- 94
lib/ios/ReactNativeNavigationTests/RNNTabBarControllerTest.m Bestand weergeven

@@ -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 {

+ 26
- 0
lib/ios/ReactNativeNavigationTests/RNNViewControllerPresenterTest.m Bestand weergeven

@@ -59,4 +59,30 @@
59 59
 	[(id)self.bindedViewController verify];
60 60
 }
61 61
 
62
+- (void)testApplyOptionsOnInit_shouldSetModalPresentetionStyleWithDefault {
63
+	[[(id)self.bindedViewController expect] rnn_setModalPresentationStyle:UIModalPresentationFullScreen];
64
+	[self.uut applyOptionsOnInit:self.options];
65
+	[(id)self.bindedViewController verify];
66
+}
67
+
68
+- (void)testApplyOptionsOnInit_shouldSetModalTransitionStyleWithDefault {
69
+	[[(id)self.bindedViewController expect] rnn_setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
70
+	[self.uut applyOptionsOnInit:self.options];
71
+	[(id)self.bindedViewController verify];
72
+}
73
+
74
+- (void)testApplyOptionsOnInit_shouldSetModalPresentetionStyleWithValue {
75
+	self.options.modalPresentationStyle = [[Text alloc] initWithValue:@"overCurrentContext"];
76
+	[[(id)self.bindedViewController expect] rnn_setModalPresentationStyle:UIModalPresentationOverCurrentContext];
77
+	[self.uut applyOptionsOnInit:self.options];
78
+	[(id)self.bindedViewController verify];
79
+}
80
+
81
+- (void)testApplyOptionsOnInit_shouldSetModalTransitionStyleWithValue {
82
+	self.options.modalTransitionStyle = [[Text alloc] initWithValue:@"crossDissolve"];
83
+	[[(id)self.bindedViewController expect] rnn_setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
84
+	[self.uut applyOptionsOnInit:self.options];
85
+	[(id)self.bindedViewController verify];
86
+}
87
+
62 88
 @end