瀏覽代碼

unit tests for setStackRoot

yogevbd 6 年之前
父節點
當前提交
6b4da44fff

+ 5
- 0
lib/ios/RNNNavigationStackManager.m 查看文件

@@ -106,6 +106,11 @@ dispatch_queue_t RCTGetUIManagerQueue(void);
106 106
 -(void)setRoot:(UIViewController<RNNRootViewProtocol> *)newRoot fromComponent:(NSString *)componentId completion:(RNNTransitionCompletionBlock)completion {
107 107
 	UIViewController* vc = [_store findComponentForId:componentId];
108 108
 	UINavigationController* nvc = [vc navigationController];
109
+	
110
+	if (!nvc) {
111
+		@throw [NSException exceptionWithName:@"StackNotFound" reason:@"Missing stack, setRoot should contain stack layout" userInfo:nil];
112
+	}
113
+	
109 114
 	[CATransaction begin];
110 115
 	[CATransaction setCompletionBlock:^{
111 116
 		if (completion) {

+ 14
- 1
lib/ios/ReactNativeNavigationTests/RNNNavigationStackManagerTest.m 查看文件

@@ -79,7 +79,20 @@
79 79
 
80 80
 }
81 81
 
82
+- (void)testStackRoot_navigationControllerNilShouldThrow {
83
+	[self.nvc setViewControllers:@[self.vc1]];
84
+	self.nvc.willReturnVCs = @[self.vc1];
85
+	
86
+	XCTAssertThrowsSpecificNamed([self.uut setRoot:self.vc2 fromComponent:nil completion:nil], NSException, @"StackNotFound");
87
+}
82 88
 
83
-
89
+- (void)testStackRoot_shouldUpdateNavigationControllerChildrenViewControllers {
90
+	self.nvc.willReturnVCs = @[self.vc1, self.vc2, self.vc3];
91
+	
92
+	[self.uut setRoot:self.vc2 fromComponent:@"vc1" completion:nil];
93
+	
94
+	XCTAssertEqual(self.nvc.viewControllers.lastObject, self.vc2);
95
+	XCTAssertEqual(self.nvc.viewControllers.count, 1);
96
+}
84 97
 
85 98
 @end