react-native-navigation的迁移库

RNNCommandsHandlerTest.m 2.9KB

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