123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #import <XCTest/XCTest.h>
- //#import <objc/runtime.h>
- #import "RNNStore.h"
- #import "RNNNavigationStackManager.h"
-
- @interface MockUINavigationController : UINavigationController
- @property (nonatomic, strong) NSArray* willReturnVCs;
- @end
-
- @implementation MockUINavigationController
-
- -(NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
- return self.willReturnVCs;
- }
-
- @end
-
-
- @interface RNNNavigationStackManagerTest : XCTestCase
-
- @end
-
- @implementation RNNNavigationStackManagerTest
-
- - (void)setUp {
- [super setUp];
-
- }
-
-
- - (void)testPop {
- RNNStore *store = [RNNStore new];
- RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
-
- UINavigationController *nvc = [[UINavigationController alloc] init];
-
- UIViewController *vc1 = [UIViewController new];
- UIViewController *vc2 = [UIViewController new];
-
-
- NSArray *vcArray = @[vc1, vc2];
- [nvc setViewControllers:vcArray];
- [store setContainer:vc1 containerId:@"vc1"];
- [store setContainer:vc2 containerId:@"vc2"];
- [uut pop:@"vc2"];
-
- XCTAssertNil([store findContainerForId:@"vc2"]);
- XCTAssertNotNil([store findContainerForId:@"vc1"]);
-
- }
-
- - (void)testPopTo_singleVc {
- RNNStore *store = [RNNStore new];
- RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
-
- UIViewController *vc1 = [UIViewController new];
- UIViewController *vc2 = [UIViewController new];
- UIViewController *vc3 = [UIViewController new];
- MockUINavigationController *nvc = [[MockUINavigationController alloc] initWithRootViewController:vc1];
- [nvc pushViewController:vc2 animated:NO];
- [nvc pushViewController:vc3 animated:NO];
- nvc.willReturnVCs = @[vc2, vc3];
-
- [store setContainer:vc1 containerId:@"vc1"];
- [store setContainer:vc2 containerId:@"vc2"];
- [store setContainer:vc3 containerId:@"vc3"];
- [uut popTo:@"vc1" fromContainerId:@"vc3"];
-
- XCTAssertNil([store findContainerForId:@"vc2"]);
- XCTAssertNotNil([store findContainerForId:@"vc1"]);
-
- }
-
-
- //- (void)testPopTo {
- // RNNStore *store = [RNNStore new];
- // RNNNavigationStackManager *uut = [[RNNNavigationStackManager alloc] initWithStore:store];
- //
- // UINavigationController *nvc = [[UINavigationController alloc] init];
- //
- // UIViewController *vc1 = [UIViewController new];
- // UIViewController *vc2 = [UIViewController new];
- // UIViewController *vc3 = [UIViewController new];
- // UIViewController *vc4 = [UIViewController new];
- //
- // NSArray *vcArray = @[vc1, vc2, vc3, vc4];
- // [nvc setViewControllers:vcArray];
- // [store setContainer:vc1 containerId:@"vc1"];
- // [store setContainer:vc2 containerId:@"vc2"];
- // [store setContainer:vc3 containerId:@"vc3"];
- // [store setContainer:vc4 containerId:@"vc4"];
- // [store setContainer:nvc containerId:@"nvc"];
- //
- // [uut popTo:@"vc1" fromContainerId:@"vc4"];
- //
- // XCTAssertNil([store findContainerForId:@"vc4"]);
- // XCTAssertNil([store findContainerForId:@"vc3"]);
- // XCTAssertNil([store findContainerForId:@"vc2"]);
- //
- //}
-
-
- @end
|