react-native-navigation的迁移库

RNNCommandsHandlerTest.m 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #import <XCTest/XCTest.h>
  2. #import <objc/runtime.h>
  3. #import "RNNCommandsHandler.h"
  4. #import "RNNNavigationOptions.h"
  5. #import "RNNTestRootViewCreator.h"
  6. #import "RNNRootViewController.h"
  7. #import "RNNNavigationController.h"
  8. @interface RNNCommandsHandlerTest : XCTestCase
  9. @property (nonatomic, strong) RNNStore* store;
  10. @property (nonatomic, strong) RNNCommandsHandler* uut;
  11. @property (nonatomic, strong) RCTBridge* bridge;
  12. @end
  13. @implementation RNNCommandsHandlerTest
  14. - (void)setUp {
  15. [super setUp];
  16. // [self.store setReadyToReceiveCommands:true];
  17. self.store = [[RNNStore alloc] init];
  18. self.bridge = nil;
  19. self.uut = [[RNNCommandsHandler alloc] initWithStore:self.store controllerFactory:nil andBridge:self.bridge];
  20. }
  21. - (void)testAssertReadyForEachMethodThrowsExceptoins {
  22. NSArray* methods = [self getPublicMethodNamesForObject:self.uut];
  23. [self.store setReadyToReceiveCommands:false];
  24. for (NSString* methodName in methods) {
  25. SEL s = NSSelectorFromString(methodName);
  26. IMP imp = [self.uut methodForSelector:s];
  27. void (*func)(id, SEL, id, id, id) = (void *)imp;
  28. XCTAssertThrowsSpecificNamed(func(self.uut,s, nil, nil, nil), NSException, @"BridgeNotLoadedError");
  29. }
  30. }
  31. -(NSArray*) getPublicMethodNamesForObject:(NSObject*)obj{
  32. NSMutableArray* skipMethods = [NSMutableArray new];
  33. [skipMethods addObject:@"initWithStore:controllerFactory:andBridge:"];
  34. [skipMethods addObject:@"assertReady"];
  35. [skipMethods addObject:@".cxx_destruct"];
  36. NSMutableArray* result = [NSMutableArray new];
  37. // count and names:
  38. int i=0;
  39. unsigned int mc = 0;
  40. Method * mlist = class_copyMethodList(object_getClass(obj), &mc);
  41. for(i=0; i<mc; i++) {
  42. NSString *methodName = [NSString stringWithUTF8String:sel_getName(method_getName(mlist[i]))];
  43. // filter skippedMethods
  44. if (methodName && ![skipMethods containsObject:methodName]) {
  45. [result addObject:methodName];
  46. }
  47. }
  48. return result;
  49. }
  50. -(void)testDynamicStylesMergeWithStaticStyles {
  51. RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] init];
  52. [initialOptions.topBar setTitle:@"the title"];
  53. RNNRootViewController* vc = [[RNNRootViewController alloc] initWithName:@"name"
  54. withOptions:initialOptions
  55. withContainerId:@"containerId"
  56. rootViewCreator:[[RNNTestRootViewCreator alloc] init]
  57. eventEmitter:nil
  58. animator:nil];
  59. RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:vc];
  60. [vc viewWillAppear:false];
  61. XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
  62. [self.store setReadyToReceiveCommands:true];
  63. [self.store setContainer:vc containerId:@"containerId"];
  64. NSDictionary* dictFromJs = @{@"topBar": @{@"backgroundColor" :@(0xFFFF0000)}};
  65. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  66. [self.uut setOptions:@"containerId" options:dictFromJs completion:^{
  67. XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
  68. XCTAssertTrue([nav.navigationBar.barTintColor isEqual:expectedColor]);
  69. }];
  70. }
  71. @end