Sfoglia il codice sorgente

unit tests for setStackRoot

yogevbd 7 anni fa
parent
commit
6b4da44fff

+ 5
- 0
lib/ios/RNNNavigationStackManager.m Vedi File

106
 -(void)setRoot:(UIViewController<RNNRootViewProtocol> *)newRoot fromComponent:(NSString *)componentId completion:(RNNTransitionCompletionBlock)completion {
106
 -(void)setRoot:(UIViewController<RNNRootViewProtocol> *)newRoot fromComponent:(NSString *)componentId completion:(RNNTransitionCompletionBlock)completion {
107
 	UIViewController* vc = [_store findComponentForId:componentId];
107
 	UIViewController* vc = [_store findComponentForId:componentId];
108
 	UINavigationController* nvc = [vc navigationController];
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
 	[CATransaction begin];
114
 	[CATransaction begin];
110
 	[CATransaction setCompletionBlock:^{
115
 	[CATransaction setCompletionBlock:^{
111
 		if (completion) {
116
 		if (completion) {

+ 14
- 1
lib/ios/ReactNativeNavigationTests/RNNNavigationStackManagerTest.m Vedi File

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
 @end
98
 @end