react-native-navigation的迁移库

RNNCommandsHandlerTest.m 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. __strong id uut = self.uut;
  22. SEL s = NSSelectorFromString(methodName);
  23. IMP imp = [uut methodForSelector:s];
  24. void (*func)(id, SEL) = (void *)imp;
  25. XCTAssertThrowsSpecificNamed(func(uut,s), 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 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 = @{@"topBarBackgroundColor" :@(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