|
@@ -0,0 +1,103 @@
|
|
1
|
+#import <XCTest/XCTest.h>
|
|
2
|
+//#import <objc/runtime.h>
|
|
3
|
+#import "RNNStore.h"
|
|
4
|
+#import "RNNNavigationStackManager.h"
|
|
5
|
+
|
|
6
|
+@interface MockUINavigationController : UINavigationController
|
|
7
|
+@property (nonatomic, strong) NSArray* willReturnVCs;
|
|
8
|
+@end
|
|
9
|
+
|
|
10
|
+@implementation MockUINavigationController
|
|
11
|
+
|
|
12
|
+-(NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
|
|
13
|
+ return self.willReturnVCs;
|
|
14
|
+}
|
|
15
|
+
|
|
16
|
+@end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+@interface RNNNavigationStackManagerTest : XCTestCase
|
|
20
|
+
|
|
21
|
+@end
|
|
22
|
+
|
|
23
|
+@implementation RNNNavigationStackManagerTest
|
|
24
|
+
|
|
25
|
+- (void)setUp {
|
|
26
|
+ [super setUp];
|
|
27
|
+
|
|
28
|
+}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+- (void)testPop {
|
|
32
|
+ RNNStore *store = [RNNStore new];
|
|
33
|
+ RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
|
|
34
|
+
|
|
35
|
+ UINavigationController *nvc = [[UINavigationController alloc] init];
|
|
36
|
+
|
|
37
|
+ UIViewController *vc1 = [UIViewController new];
|
|
38
|
+ UIViewController *vc2 = [UIViewController new];
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+ NSArray *vcArray = @[vc1, vc2];
|
|
42
|
+ [nvc setViewControllers:vcArray];
|
|
43
|
+ [store setContainer:vc1 containerId:@"vc1"];
|
|
44
|
+ [store setContainer:vc2 containerId:@"vc2"];
|
|
45
|
+ [uut pop:@"vc2"];
|
|
46
|
+
|
|
47
|
+ XCTAssertNil([store findContainerForId:@"vc2"]);
|
|
48
|
+ XCTAssertNotNil([store findContainerForId:@"vc1"]);
|
|
49
|
+
|
|
50
|
+}
|
|
51
|
+
|
|
52
|
+- (void)testPopTo_singleVc {
|
|
53
|
+ RNNStore *store = [RNNStore new];
|
|
54
|
+ RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
|
|
55
|
+
|
|
56
|
+ UIViewController *vc1 = [UIViewController new];
|
|
57
|
+ UIViewController *vc2 = [UIViewController new];
|
|
58
|
+ UIViewController *vc3 = [UIViewController new];
|
|
59
|
+ MockUINavigationController *nvc = [[MockUINavigationController alloc] initWithRootViewController:vc1];
|
|
60
|
+ [nvc pushViewController:vc2 animated:NO];
|
|
61
|
+ [nvc pushViewController:vc3 animated:NO];
|
|
62
|
+ nvc.willReturnVCs = @[vc2, vc3];
|
|
63
|
+
|
|
64
|
+ [store setContainer:vc1 containerId:@"vc1"];
|
|
65
|
+ [store setContainer:vc2 containerId:@"vc2"];
|
|
66
|
+ [store setContainer:vc3 containerId:@"vc3"];
|
|
67
|
+ [uut popTo:@"vc1" fromContainerId:@"vc3"];
|
|
68
|
+
|
|
69
|
+ XCTAssertNil([store findContainerForId:@"vc2"]);
|
|
70
|
+ XCTAssertNotNil([store findContainerForId:@"vc1"]);
|
|
71
|
+
|
|
72
|
+}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+//- (void)testPopTo {
|
|
76
|
+// RNNStore *store = [RNNStore new];
|
|
77
|
+// RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
|
|
78
|
+//
|
|
79
|
+// UINavigationController *nvc = [[UINavigationController alloc] init];
|
|
80
|
+//
|
|
81
|
+// UIViewController *vc1 = [UIViewController new];
|
|
82
|
+// UIViewController *vc2 = [UIViewController new];
|
|
83
|
+// UIViewController *vc3 = [UIViewController new];
|
|
84
|
+// UIViewController *vc4 = [UIViewController new];
|
|
85
|
+//
|
|
86
|
+// NSArray *vcArray = @[vc1, vc2, vc3, vc4];
|
|
87
|
+// [nvc setViewControllers:vcArray];
|
|
88
|
+// [store setContainer:vc1 containerId:@"vc1"];
|
|
89
|
+// [store setContainer:vc2 containerId:@"vc2"];
|
|
90
|
+// [store setContainer:vc3 containerId:@"vc3"];
|
|
91
|
+// [store setContainer:vc4 containerId:@"vc4"];
|
|
92
|
+// [store setContainer:nvc containerId:@"nvc"];
|
|
93
|
+//
|
|
94
|
+// [uut popTo:@"vc1" fromContainerId:@"vc4"];
|
|
95
|
+//
|
|
96
|
+// XCTAssertNil([store findContainerForId:@"vc4"]);
|
|
97
|
+// XCTAssertNil([store findContainerForId:@"vc3"]);
|
|
98
|
+// XCTAssertNil([store findContainerForId:@"vc2"]);
|
|
99
|
+//
|
|
100
|
+//}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+@end
|