ソースを参照

unit tests for setStackRoot

yogevbd 6 年 前
コミット
6b4da44fff
共有2 個のファイルを変更した19 個の追加1 個の削除を含む
  1. 5
    0
      lib/ios/RNNNavigationStackManager.m
  2. 14
    1
      lib/ios/ReactNativeNavigationTests/RNNNavigationStackManagerTest.m

+ 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