react-native-navigation的迁移库

RNNCommandsHandlerTest.m 2.7KB

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