#import #import #import "RNNCommandsHandler.h" #import "RNNNavigationOptions.h" #import "RNNTestRootViewCreator.h" #import "RNNRootViewController.h" #import "RNNNavigationController.h" #import "RNNErrorHandler.h" #import @interface MockUINavigationController : RNNNavigationController @property (nonatomic, strong) NSArray* willReturnVCs; @end @implementation MockUINavigationController -(NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated { return self.willReturnVCs; } -(NSArray *)popToRootViewControllerAnimated:(BOOL)animated { return self.willReturnVCs; } @end @interface RNNCommandsHandlerTest : XCTestCase @property (nonatomic, strong) RNNStore* store; @property (nonatomic, strong) id overlayStore; @property (nonatomic, strong) RNNCommandsHandler* uut; @property (nonatomic, strong) RNNRootViewController* vc1; @property (nonatomic, strong) RNNRootViewController* vc2; @property (nonatomic, strong) RNNRootViewController* vc3; @property (nonatomic, strong) MockUINavigationController* nvc; @property (nonatomic, strong) id controllerFactory; @property (nonatomic, strong) id overlayManager; @property (nonatomic, strong) id eventEmmiter; @end @implementation RNNCommandsHandlerTest - (void)setUp { [super setUp]; // [self.store setReadyToReceiveCommands:true]; self.store = [[RNNStore alloc] init]; self.overlayStore = [OCMockObject partialMockForObject:[[RNNStore alloc] init]]; self.eventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]]; self.overlayManager = [OCMockObject partialMockForObject:[RNNOverlayManager new]]; self.controllerFactory = [OCMockObject partialMockForObject:[[RNNControllerFactory alloc] initWithRootViewCreator:nil eventEmitter:self.eventEmmiter andBridge:nil]]; self.uut = [[RNNCommandsHandler alloc] initWithStore:self.store overlayStore:self.overlayStore controllerFactory:self.controllerFactory eventEmitter:self.eventEmmiter stackManager:[RNNNavigationStackManager new] modalManager:[RNNModalManager new] overlayManager:self.overlayManager]; self.vc1 = [RNNRootViewController new]; self.vc2 = [RNNRootViewController new]; self.vc3 = [RNNRootViewController new]; _nvc = [[MockUINavigationController alloc] init]; [_nvc setViewControllers:@[self.vc1, self.vc2, self.vc3]]; [self.store setComponent:self.vc1 componentId:@"vc1"]; [self.store setComponent:self.vc2 componentId:@"vc2"]; [self.store setComponent:self.vc3 componentId:@"vc3"]; } - (void)testAssertReadyForEachMethodThrowsExceptoins { NSArray* methods = [self getPublicMethodNamesForObject:self.uut]; [self.store setReadyToReceiveCommands:false]; for (NSString* methodName in methods) { SEL s = NSSelectorFromString(methodName); IMP imp = [self.uut methodForSelector:s]; void (*func)(id, SEL, id, id, id) = (void *)imp; XCTAssertThrowsSpecificNamed(func(self.uut,s, nil, nil, nil), NSException, @"BridgeNotLoadedError"); } } -(NSArray*) getPublicMethodNamesForObject:(NSObject*)obj{ NSMutableArray* skipMethods = [NSMutableArray new]; [skipMethods addObject:@"initWithStore:overlayStore:controllerFactory:eventEmitter:stackManager:modalManager:overlayManager:"]; [skipMethods addObject:@"assertReady"]; [skipMethods addObject:@"removePopedViewControllers:"]; [skipMethods addObject:@".cxx_destruct"]; [skipMethods addObject:@"dismissedModal:"]; [skipMethods addObject:@"dismissedMultipleModals:"]; NSMutableArray* result = [NSMutableArray new]; // count and names: int i=0; unsigned int mc = 0; Method * mlist = class_copyMethodList(object_getClass(obj), &mc); for(i=0; i