|
@@ -10,20 +10,8 @@
|
10
|
10
|
#import "RNNLayoutManager.h"
|
11
|
11
|
#import "RNNBottomTabsController.h"
|
12
|
12
|
#import "BottomTabsAttachModeFactory.h"
|
13
|
|
-
|
14
|
|
-@interface MockUIApplication : NSObject
|
15
|
|
-
|
16
|
|
--(UIWindow *)keyWindow;
|
17
|
|
-
|
18
|
|
-@end
|
19
|
|
-
|
20
|
|
-@implementation MockUIApplication
|
21
|
|
-
|
22
|
|
-- (UIWindow *)keyWindow {
|
23
|
|
- return [UIWindow new];
|
24
|
|
-}
|
25
|
|
-
|
26
|
|
-@end
|
|
13
|
+#import <ReactNativeNavigation/BottomTabPresenterCreator.h>
|
|
14
|
+#import "RNNComponentViewController+Utils.h"
|
27
|
15
|
|
28
|
16
|
@interface MockUINavigationController : RNNStackController
|
29
|
17
|
@property (nonatomic, strong) NSArray* willReturnVCs;
|
|
@@ -62,7 +50,6 @@
|
62
|
50
|
|
63
|
51
|
- (void)setUp {
|
64
|
52
|
[super setUp];
|
65
|
|
- self.sharedApplication = [OCMockObject mockForClass:[UIApplication class]];
|
66
|
53
|
self.creator = [OCMockObject partialMockForObject:[RNNTestRootViewCreator new]];
|
67
|
54
|
self.mainWindow = [OCMockObject partialMockForObject:[UIWindow new]];
|
68
|
55
|
self.eventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
|
|
@@ -75,7 +62,12 @@
|
75
|
62
|
self.vc3 = [self generateComponentWithComponentId:@"3"];
|
76
|
63
|
_nvc = [[MockUINavigationController alloc] init];
|
77
|
64
|
[_nvc setViewControllers:@[self.vc1, self.vc2, self.vc3]];
|
78
|
|
- OCMStub([self.sharedApplication keyWindow]).andReturn(self.mainWindow);
|
|
65
|
+
|
|
66
|
+ UIApplication* sharedApplication = [OCMockObject niceMockForClass:[UIApplication class]];
|
|
67
|
+ id mockedApplicationClass = OCMClassMock([UIApplication class]);
|
|
68
|
+ OCMStub(ClassMethod([mockedApplicationClass sharedApplication])).andReturn(sharedApplication);
|
|
69
|
+ OCMStub(sharedApplication.keyWindow).andReturn(self.mainWindow);
|
|
70
|
+ OCMStub([sharedApplication windows]).andReturn(@[self.mainWindow]);
|
79
|
71
|
}
|
80
|
72
|
|
81
|
73
|
- (RNNComponentViewController *)generateComponentWithComponentId:(NSString *)componentId {
|
|
@@ -129,14 +121,11 @@
|
129
|
121
|
-(void)testDynamicStylesMergeWithStaticStyles {
|
130
|
122
|
RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initWithDict:@{}];
|
131
|
123
|
initialOptions.topBar.title.text = [[Text alloc] initWithValue:@"the title"];
|
132
|
|
- RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
|
133
|
124
|
RNNTestRootViewCreator* creator = [[RNNTestRootViewCreator alloc] init];
|
134
|
|
-
|
135
|
|
- RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil];
|
136
|
|
- RNNComponentViewController* vc = [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:creator eventEmitter:nil presenter:presenter options:initialOptions defaultOptions:nil];
|
|
125
|
+ RNNComponentViewController* vc = [RNNComponentViewController createWithComponentId:@"componentId" initialOptions:initialOptions];
|
137
|
126
|
|
138
|
127
|
RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:creator options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNStackPresenter alloc] init] eventEmitter:nil childViewControllers:@[vc]];
|
139
|
|
-
|
|
128
|
+ [self.mainWindow setRootViewController:nav];
|
140
|
129
|
[vc viewWillAppear:false];
|
141
|
130
|
XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
|
142
|
131
|
|
|
@@ -146,9 +135,11 @@
|
146
|
135
|
UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
|
147
|
136
|
|
148
|
137
|
[self.uut mergeOptions:@"componentId" options:dictFromJs completion:^{
|
149
|
|
- XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
|
150
|
|
- XCTAssertTrue([nav.navigationBar.barTintColor isEqual:expectedColor]);
|
|
138
|
+
|
151
|
139
|
}];
|
|
140
|
+
|
|
141
|
+ XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
|
|
142
|
+ XCTAssertTrue([vc.navigationItem.standardAppearance.backgroundColor isEqual:expectedColor]);
|
152
|
143
|
}
|
153
|
144
|
|
154
|
145
|
- (void)testMergeOptions_shouldOverrideOptions {
|
|
@@ -420,6 +411,34 @@
|
420
|
411
|
XCTAssertTrue(_vc2.isViewLoaded);
|
421
|
412
|
}
|
422
|
413
|
|
|
414
|
+- (void)testMergeOptions_shouldMergeWithChildOnly {
|
|
415
|
+ [self.uut setReadyToReceiveCommands:true];
|
|
416
|
+ NSDictionary* mergeOptions = @{@"bottomTab": @{@"badge": @"Badge"}};
|
|
417
|
+
|
|
418
|
+ RNNNavigationOptions* firstChildOptions = [RNNNavigationOptions emptyOptions];
|
|
419
|
+ firstChildOptions.bottomTab.text = [Text withValue:@"First"];
|
|
420
|
+ RNNNavigationOptions* secondChildOptions = [RNNNavigationOptions emptyOptions];
|
|
421
|
+ secondChildOptions.bottomTab.text = [Text withValue:@"Second"];
|
|
422
|
+
|
|
423
|
+ RNNComponentViewController* firstChild = [RNNComponentViewController createWithComponentId:@"first" initialOptions:firstChildOptions];
|
|
424
|
+ RNNComponentViewController* secondChild = [RNNComponentViewController createWithComponentId:@"second" initialOptions:secondChildOptions];
|
|
425
|
+
|
|
426
|
+ RNNBottomTabsController* tabBarController = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:[RNNBasePresenter new] bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:[RNNNavigationOptions emptyOptions]] dotIndicatorPresenter:nil eventEmitter:_eventEmmiter childViewControllers:@[firstChild, secondChild] bottomTabsAttacher:nil];
|
|
427
|
+
|
|
428
|
+ OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController);
|
|
429
|
+ [self.mainWindow setRootViewController:tabBarController];
|
|
430
|
+ [secondChild viewWillAppear:YES];
|
|
431
|
+
|
|
432
|
+ [self.uut mergeOptions:secondChild.layoutInfo.componentId options:mergeOptions completion:^{
|
|
433
|
+
|
|
434
|
+ }];
|
|
435
|
+
|
|
436
|
+ XCTAssertTrue([secondChild.tabBarItem.badgeValue isEqualToString:@"Badge"]);
|
|
437
|
+ XCTAssertNil(firstChild.tabBarItem.badgeValue);
|
|
438
|
+ XCTAssertTrue([firstChild.tabBarItem.title isEqualToString:@"First"]);
|
|
439
|
+ XCTAssertTrue([secondChild.tabBarItem.title isEqualToString:@"Second"]);
|
|
440
|
+}
|
|
441
|
+
|
423
|
442
|
- (void)testShowModal_shouldShowAnimated {
|
424
|
443
|
[self.uut setReadyToReceiveCommands:true];
|
425
|
444
|
self.vc1.options = [[RNNNavigationOptions alloc] initEmptyOptions];
|