react-native-navigation的迁移库

RNNCommandsHandlerTest.m 2.8KB

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