Skip to content

Commit

Permalink
Added unit test coverage for RNNNavigationController
Browse files Browse the repository at this point in the history
  • Loading branch information
yogevbd committed Sep 16, 2018
1 parent 69c3e0d commit 40a590b
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/ios/RNNNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ - (UIViewController *)childViewControllerForStatusBarStyle {

- (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers {
[super setViewControllers:viewControllers];
for (UIViewController<RNNRootViewProtocol>* viewController in viewControllers) {
if (viewController.layoutInfo.options) {
[viewController.layoutInfo.options mergeOptions:self.layoutInfo.options overrideOptions:NO];
}
}
for (UIViewController<RNNRootViewProtocol>* viewController in viewControllers) {
if ([viewController respondsToSelector:@selector(layoutInfo)]) {
[viewController.layoutInfo.options mergeOptions:self.layoutInfo.options overrideOptions:NO];
}
}
}

- (void)pushViewController:(UIViewController<RNNRootViewProtocol> *)viewController animated:(BOOL)animated {
[super pushViewController:viewController animated:animated];
if (viewController.layoutInfo.options) {
if ([viewController respondsToSelector:@selector(layoutInfo)]) {
[viewController.layoutInfo.options mergeOptions:self.layoutInfo.options overrideOptions:NO];
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@implementation RNNOptions

-(instancetype) initWithDict:(NSDictionary *)dict {
- (instancetype)initWithDict:(NSDictionary *)dict {
self = [super init];
[self initializeOptionsPropertiesWithDict:dict];

Expand Down
4 changes: 4 additions & 0 deletions lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
50570B272061473D006A1B5C /* RNNTitleOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50570B252061473D006A1B5C /* RNNTitleOptions.m */; };
50570BEA2063E09B006A1B5C /* RNNTitleViewHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 50570BE82063E09B006A1B5C /* RNNTitleViewHelper.h */; };
50570BEB2063E09B006A1B5C /* RNNTitleViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 50570BE92063E09B006A1B5C /* RNNTitleViewHelper.m */; };
505EDD32214E4BE80071C7DE /* RNNNavigationControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 505EDD31214E4BE80071C7DE /* RNNNavigationControllerTest.m */; };
5064495D20DC62B90026709C /* RNNSideMenuSideOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 5064495B20DC62B90026709C /* RNNSideMenuSideOptions.h */; };
5064495E20DC62B90026709C /* RNNSideMenuSideOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5064495C20DC62B90026709C /* RNNSideMenuSideOptions.m */; };
50644A2020E11A720026709C /* Constants.h in Headers */ = {isa = PBXBuildFile; fileRef = 50644A1E20E11A720026709C /* Constants.h */; };
Expand Down Expand Up @@ -329,6 +330,7 @@
50570B252061473D006A1B5C /* RNNTitleOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTitleOptions.m; sourceTree = "<group>"; };
50570BE82063E09B006A1B5C /* RNNTitleViewHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNTitleViewHelper.h; sourceTree = "<group>"; };
50570BE92063E09B006A1B5C /* RNNTitleViewHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTitleViewHelper.m; sourceTree = "<group>"; };
505EDD31214E4BE80071C7DE /* RNNNavigationControllerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNNavigationControllerTest.m; sourceTree = "<group>"; };
5064495B20DC62B90026709C /* RNNSideMenuSideOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSideMenuSideOptions.h; sourceTree = "<group>"; };
5064495C20DC62B90026709C /* RNNSideMenuSideOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSideMenuSideOptions.m; sourceTree = "<group>"; };
50644A1E20E11A720026709C /* Constants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -712,6 +714,7 @@
7B49FEC91E95098500DEB3EA /* RNNCommandsHandlerTest.m */,
7B49FECA1E95098500DEB3EA /* RNNNavigationStackManagerTest.m */,
504753772109C13C00FFFBE6 /* RNNOverlayManagerTest.m */,
505EDD31214E4BE80071C7DE /* RNNNavigationControllerTest.m */,
7B49FEBF1E95090800DEB3EA /* Info.plist */,
E83BAD671F2734B500A9F3DD /* RNNNavigationOptionsTest.m */,
E83BAD781F27416B00A9F3DD /* RNNRootViewControllerTest.m */,
Expand Down Expand Up @@ -1026,6 +1029,7 @@
504753782109C13C00FFFBE6 /* RNNOverlayManagerTest.m in Sources */,
7B49FECE1E95098500DEB3EA /* RNNCommandsHandlerTest.m in Sources */,
E83BAD681F2734B500A9F3DD /* RNNNavigationOptionsTest.m in Sources */,
505EDD32214E4BE80071C7DE /* RNNNavigationControllerTest.m in Sources */,
7B49FECF1E95098500DEB3EA /* RNNNavigationStackManagerTest.m in Sources */,
7B49FECB1E95098500DEB3EA /* RNNControllerFactoryTest.m in Sources */,
7B49FECD1E95098500DEB3EA /* RNNModalManagerTest.m in Sources */,
Expand Down
68 changes: 68 additions & 0 deletions lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#import <XCTest/XCTest.h>
#import "RNNNavigationController.h"

@interface RNNNavigationControllerTest : XCTestCase

@property (nonatomic, strong) RNNNavigationController *uut;

@end

@implementation RNNNavigationControllerTest {
RNNRootViewController* _vc1;
RNNRootViewController* _vc2;
UIViewController* _vc3;
}

- (void)setUp {
[super setUp];

self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:[self createLayoutInfo]];
_vc1 = [[RNNRootViewController alloc] init];
_vc1.layoutInfo = [self createLayoutInfo];
_vc2 = [[RNNRootViewController alloc] init];
_vc2.layoutInfo = [self createLayoutInfo];
_vc3 = [UIViewController new];
}

- (void)testSetViewControllers_shouldPropogateOptionsToViewController {
self.uut.layoutInfo.options.topBar.visible = @(1);
[self.uut setViewControllers:@[_vc1]];
XCTAssertTrue(_vc1.layoutInfo.options.topBar.visible.boolValue == self.uut.layoutInfo.options.topBar.visible.boolValue);
}

- (void)testSetViewControllers_externalViewControllerShouldNotCrash {
NSArray* viewControllers = @[_vc1, _vc3];
XCTAssertNoThrow([self.uut setViewControllers:viewControllers]);
}

- (void)testPushViewController_shouldPropogateOptionsToViewController {
self.uut.layoutInfo.options.topBar.visible = @(1);
[self.uut pushViewController:_vc2 animated:NO];
XCTAssertTrue(_vc2.layoutInfo.options.topBar.visible.boolValue == self.uut.layoutInfo.options.topBar.visible.boolValue);
}

- (void)testPushViewController_externalViewControllerShouldNotCrash {
XCTAssertNoThrow([self.uut pushViewController:_vc3 animated:NO]);
}

- (void)testChildViewControllerForStatusBarStyle_shouldReturnTopViewController {
XCTAssertTrue(self.uut.childViewControllerForStatusBarStyle == self.uut.topViewController);
}

- (void)testGetLeafViewController_shouldReturnTopViewController {
XCTAssertTrue(self.uut.getLeafViewController == self.uut.topViewController);
}

- (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle {
[self.uut setViewControllers:@[_vc1]];
self.uut.getLeafViewController.layoutInfo.options.statusBar.style = @"dark";
XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getLeafViewController.preferredStatusBarStyle);
}

- (RNNLayoutInfo *)createLayoutInfo {
RNNLayoutInfo *layoutInfo = [RNNLayoutInfo new];
layoutInfo.options = [[RNNNavigationOptions alloc] initWithDict:@{}];
return layoutInfo;
}

@end

0 comments on commit 40a590b

Please sign in to comment.