From 3c38c50a8b53e958a21e6fb7453622463e9870ff Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Mon, 16 Mar 2020 08:56:08 +0200 Subject: [PATCH] Merge options with correct child (#6041) Co-authored-by: Guy Carmeli --- lib/ios/RNNBottomTabsController.m | 4 +- .../NavigationTests/RNNCommandsHandlerTest.m | 65 ++++++++++++------- .../NavigationTests/RNNLayoutManagerTest.m | 2 +- .../utils/RNNComponentViewController+Utils.h | 2 + .../utils/RNNComponentViewController+Utils.m | 9 ++- .../ios/playground.xcodeproj/project.pbxproj | 14 +++- 6 files changed, 65 insertions(+), 31 deletions(-) diff --git a/lib/ios/RNNBottomTabsController.m b/lib/ios/RNNBottomTabsController.m index 0b86a434697..9b56235910e 100644 --- a/lib/ios/RNNBottomTabsController.m +++ b/lib/ios/RNNBottomTabsController.m @@ -38,8 +38,8 @@ - (void)onChildAddToParent:(UIViewController *)child options:(RNNNavigationOptio - (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewController *)child { [super mergeChildOptions:options child:child]; - [_bottomTabPresenter mergeOptions:options resolvedOptions:self.resolveOptions child:[self findViewController:child]]; - [_dotIndicatorPresenter mergeOptions:options resolvedOptions:self.resolveOptions child:[self findViewController:child]]; + [_bottomTabPresenter mergeOptions:options resolvedOptions:child.resolveOptions child:[self findViewController:child]]; + [_dotIndicatorPresenter mergeOptions:options resolvedOptions:child.resolveOptions child:[self findViewController:child]]; } - (id)delegate { diff --git a/playground/ios/NavigationTests/RNNCommandsHandlerTest.m b/playground/ios/NavigationTests/RNNCommandsHandlerTest.m index 85028c04cb9..83129201b15 100644 --- a/playground/ios/NavigationTests/RNNCommandsHandlerTest.m +++ b/playground/ios/NavigationTests/RNNCommandsHandlerTest.m @@ -10,20 +10,8 @@ #import "RNNLayoutManager.h" #import "RNNBottomTabsController.h" #import "BottomTabsAttachModeFactory.h" - -@interface MockUIApplication : NSObject - --(UIWindow *)keyWindow; - -@end - -@implementation MockUIApplication - -- (UIWindow *)keyWindow { - return [UIWindow new]; -} - -@end +#import +#import "RNNComponentViewController+Utils.h" @interface MockUINavigationController : RNNStackController @property (nonatomic, strong) NSArray* willReturnVCs; @@ -62,7 +50,6 @@ @implementation RNNCommandsHandlerTest - (void)setUp { [super setUp]; - self.sharedApplication = [OCMockObject mockForClass:[UIApplication class]]; self.creator = [OCMockObject partialMockForObject:[RNNTestRootViewCreator new]]; self.mainWindow = [OCMockObject partialMockForObject:[UIWindow new]]; self.eventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]]; @@ -75,7 +62,12 @@ - (void)setUp { self.vc3 = [self generateComponentWithComponentId:@"3"]; _nvc = [[MockUINavigationController alloc] init]; [_nvc setViewControllers:@[self.vc1, self.vc2, self.vc3]]; - OCMStub([self.sharedApplication keyWindow]).andReturn(self.mainWindow); + + UIApplication* sharedApplication = [OCMockObject niceMockForClass:[UIApplication class]]; + id mockedApplicationClass = OCMClassMock([UIApplication class]); + OCMStub(ClassMethod([mockedApplicationClass sharedApplication])).andReturn(sharedApplication); + OCMStub(sharedApplication.keyWindow).andReturn(self.mainWindow); + OCMStub([sharedApplication windows]).andReturn(@[self.mainWindow]); } - (RNNComponentViewController *)generateComponentWithComponentId:(NSString *)componentId { @@ -129,14 +121,11 @@ - (NSArray*)getPublicMethodNamesForObject:(NSObject*)obj { -(void)testDynamicStylesMergeWithStaticStyles { RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initWithDict:@{}]; initialOptions.topBar.title.text = [[Text alloc] initWithValue:@"the title"]; - RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new]; RNNTestRootViewCreator* creator = [[RNNTestRootViewCreator alloc] init]; - - RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil]; - RNNComponentViewController* vc = [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:creator eventEmitter:nil presenter:presenter options:initialOptions defaultOptions:nil]; + RNNComponentViewController* vc = [RNNComponentViewController createWithComponentId:@"componentId" initialOptions:initialOptions]; RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:creator options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNStackPresenter alloc] init] eventEmitter:nil childViewControllers:@[vc]]; - + [self.mainWindow setRootViewController:nav]; [vc viewWillAppear:false]; XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]); @@ -146,9 +135,11 @@ -(void)testDynamicStylesMergeWithStaticStyles { UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1]; [self.uut mergeOptions:@"componentId" options:dictFromJs completion:^{ - XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]); - XCTAssertTrue([nav.navigationBar.barTintColor isEqual:expectedColor]); + }]; + + XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]); + XCTAssertTrue([vc.navigationItem.standardAppearance.backgroundColor isEqual:expectedColor]); } - (void)testMergeOptions_shouldOverrideOptions { @@ -420,6 +411,34 @@ - (void)testSetRoot_withBottomTabsAttachModeAfterInitialTab { XCTAssertTrue(_vc2.isViewLoaded); } +- (void)testMergeOptions_shouldMergeWithChildOnly { + [self.uut setReadyToReceiveCommands:true]; + NSDictionary* mergeOptions = @{@"bottomTab": @{@"badge": @"Badge"}}; + + RNNNavigationOptions* firstChildOptions = [RNNNavigationOptions emptyOptions]; + firstChildOptions.bottomTab.text = [Text withValue:@"First"]; + RNNNavigationOptions* secondChildOptions = [RNNNavigationOptions emptyOptions]; + secondChildOptions.bottomTab.text = [Text withValue:@"Second"]; + + RNNComponentViewController* firstChild = [RNNComponentViewController createWithComponentId:@"first" initialOptions:firstChildOptions]; + RNNComponentViewController* secondChild = [RNNComponentViewController createWithComponentId:@"second" initialOptions:secondChildOptions]; + + 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]; + + OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController); + [self.mainWindow setRootViewController:tabBarController]; + [secondChild viewWillAppear:YES]; + + [self.uut mergeOptions:secondChild.layoutInfo.componentId options:mergeOptions completion:^{ + + }]; + + XCTAssertTrue([secondChild.tabBarItem.badgeValue isEqualToString:@"Badge"]); + XCTAssertNil(firstChild.tabBarItem.badgeValue); + XCTAssertTrue([firstChild.tabBarItem.title isEqualToString:@"First"]); + XCTAssertTrue([secondChild.tabBarItem.title isEqualToString:@"Second"]); +} + - (void)testShowModal_shouldShowAnimated { [self.uut setReadyToReceiveCommands:true]; self.vc1.options = [[RNNNavigationOptions alloc] initEmptyOptions]; diff --git a/playground/ios/NavigationTests/RNNLayoutManagerTest.m b/playground/ios/NavigationTests/RNNLayoutManagerTest.m index dc44e4741a5..8b02f943368 100644 --- a/playground/ios/NavigationTests/RNNLayoutManagerTest.m +++ b/playground/ios/NavigationTests/RNNLayoutManagerTest.m @@ -26,7 +26,7 @@ - (void)setUp { _secondWindow = [[UIWindow alloc] init]; NSArray* windows = @[_firstWindow, _secondWindow]; - UIApplication* sharedApplication = [OCMockObject mockForClass:[UIApplication class]]; + UIApplication* sharedApplication = [OCMockObject niceMockForClass:[UIApplication class]]; id mockedApplicationClass = OCMClassMock([UIApplication class]); OCMStub(ClassMethod([mockedApplicationClass sharedApplication])).andReturn(sharedApplication); OCMStub(sharedApplication.keyWindow).andReturn(_firstWindow); diff --git a/playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.h b/playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.h index 7ad33d21c26..b397dadbf65 100644 --- a/playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.h +++ b/playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.h @@ -5,4 +5,6 @@ + (RNNComponentViewController *)createWithComponentId:(NSString *)componentId; ++ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId initialOptions:(RNNNavigationOptions *)initialOptions; + @end diff --git a/playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.m b/playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.m index fbed8f14f5e..f8a8a7a8606 100644 --- a/playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.m +++ b/playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.m @@ -1,11 +1,16 @@ #import "RNNComponentViewController+Utils.h" +#import "RNNTestRootViewCreator.h" @implementation RNNComponentViewController (Utils) -+ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId { ++ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId initialOptions:(RNNNavigationOptions *)initialOptions { RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init]; layoutInfo.componentId = componentId; - return [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:nil eventEmitter:nil presenter:nil options:nil defaultOptions:nil]; + return [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:[[RNNTestRootViewCreator alloc] init] eventEmitter:nil presenter:[[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil] options:initialOptions defaultOptions:nil]; +} + ++ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId { + return [self createWithComponentId:componentId initialOptions:nil]; } @end diff --git a/playground/ios/playground.xcodeproj/project.pbxproj b/playground/ios/playground.xcodeproj/project.pbxproj index 543c8818610..6a48daf10af 100644 --- a/playground/ios/playground.xcodeproj/project.pbxproj +++ b/playground/ios/playground.xcodeproj/project.pbxproj @@ -21,8 +21,8 @@ 50996C6923AA487800008F89 /* RNNTestRootViewCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D263D2385888C003F36BA /* RNNTestRootViewCreator.m */; }; 50BCB27623F1A2B100D6C8E5 /* TopBarAppearancePresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */; }; 50C9A8D1240EB95F00BD699F /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; }; - 50CF233D240695B10098042D /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; }; 50C9A8D4240FB9D000BD699F /* RNNComponentViewController+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 50C9A8D3240FB9D000BD699F /* RNNComponentViewController+Utils.m */; }; + 50CF233D240695B10098042D /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; }; 67C681D42B662A53F29C19DA /* Pods_NavigationIOS12Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEE0B5D45FD34FBABC6586CF /* Pods_NavigationIOS12Tests.framework */; }; 9D204F3DC4FBCD81583BF99F /* Pods_playground.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A3340545EAAF11C1F146864 /* Pods_playground.framework */; }; E5046080227748EA00212BD8 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E504607F227748EA00212BD8 /* JavaScriptCore.framework */; }; @@ -97,10 +97,10 @@ 50996C6123AA46DD00008F89 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50996C6723AA477400008F89 /* RNNRootViewControllerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNRootViewControllerTest.m; sourceTree = ""; }; 50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TopBarAppearancePresenterTest.m; sourceTree = ""; }; - 50CF233B240695B10098042D /* RNNBottomTabsController+Helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNBottomTabsController+Helpers.h"; sourceTree = ""; }; - 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNBottomTabsController+Helpers.m"; sourceTree = ""; }; 50C9A8D2240FB9D000BD699F /* RNNComponentViewController+Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNComponentViewController+Utils.h"; sourceTree = ""; }; 50C9A8D3240FB9D000BD699F /* RNNComponentViewController+Utils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNComponentViewController+Utils.m"; sourceTree = ""; }; + 50CF233B240695B10098042D /* RNNBottomTabsController+Helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNBottomTabsController+Helpers.h"; sourceTree = ""; }; + 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNBottomTabsController+Helpers.m"; sourceTree = ""; }; 7F8E255E2E08F6ECE7DF6FE3 /* Pods-playground.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-playground.release.xcconfig"; path = "Target Support Files/Pods-playground/Pods-playground.release.xcconfig"; sourceTree = ""; }; 84E32151E3A71C2B7328BCB4 /* Pods_NavigationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NavigationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B484A10A046B0046B98A76B5 /* Pods-playground.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-playground.debug.xcconfig"; path = "Target Support Files/Pods-playground/Pods-playground.debug.xcconfig"; sourceTree = ""; }; @@ -399,11 +399,13 @@ 50996C5C23AA46DD00008F89 = { CreatedOnToolsVersion = 11.2.1; ProvisioningStyle = Automatic; + TestTargetID = 13B07F861A680F5B00A75B9A; }; E58D261A238587F4003F36BA = { CreatedOnToolsVersion = 11.2.1; DevelopmentTeam = S3GLW74Y8N; ProvisioningStyle = Automatic; + TestTargetID = 13B07F861A680F5B00A75B9A; }; }; }; @@ -892,6 +894,7 @@ PRODUCT_BUNDLE_IDENTIFIER = rn.NavigationIOS12Tests; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground"; }; name = Debug; }; @@ -916,6 +919,7 @@ PRODUCT_BUNDLE_IDENTIFIER = rn.NavigationIOS12Tests; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground"; }; name = Release; }; @@ -1026,6 +1030,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 4259AF43A23D928FE78B4A3A /* Pods-NavigationTests.debug.xcconfig */; buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; @@ -1044,6 +1049,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.wix.NavigationTests; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground"; }; name = Debug; }; @@ -1051,6 +1057,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = D95A99C17C65D674BA9DF26B /* Pods-NavigationTests.release.xcconfig */; buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; @@ -1069,6 +1076,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.wix.NavigationTests; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground"; }; name = Release; };