react-native-navigation的迁移库

RNNRootViewControllerTest.m 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #import <XCTest/XCTest.h>
  2. #import "RNNRootViewController.h"
  3. #import "RNNReactRootViewCreator.h"
  4. #import "RNNTestRootViewCreator.h"
  5. #import <React/RCTConvert.h>
  6. #import "RNNNavigationOptions.h"
  7. @interface RNNRootViewControllerTest : XCTestCase
  8. @property (nonatomic, strong) id<RNNRootViewCreator> creator;
  9. @property (nonatomic, strong) NSString* pageName;
  10. @property (nonatomic, strong) NSString* containerId;
  11. @property (nonatomic, strong) id emitter;
  12. @property (nonatomic, strong) RNNNavigationOptions* options;
  13. @property (nonatomic, strong) RNNRootViewController* uut;
  14. @end
  15. @implementation RNNRootViewControllerTest
  16. - (void)setUp {
  17. [super setUp];
  18. self.creator = [[RNNTestRootViewCreator alloc] init];
  19. self.pageName = @"somename";
  20. self.containerId = @"cntId";
  21. self.emitter = nil;
  22. self.options = [RNNNavigationOptions new];
  23. self.uut = [[RNNRootViewController alloc] initWithName:self.pageName withOptions:self.options withContainerId:self.containerId rootViewCreator:self.creator eventEmitter:self.emitter];
  24. }
  25. -(void)testTopBarBackgroundColor_validColor{
  26. NSNumber* inputColor = @(0xFFFF0000);
  27. self.options.topBarBackgroundColor = inputColor;
  28. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  29. [self.uut viewWillAppear:false];
  30. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  31. XCTAssertTrue([self.uut.navigationController.navigationBar.barTintColor isEqual:expectedColor]);
  32. }
  33. -(void)testTopBarBackgroundColorWithoutNavigationController{
  34. NSNumber* inputColor = @(0xFFFF0000);
  35. self.options.topBarBackgroundColor = inputColor;
  36. XCTAssertNoThrow([self.uut viewWillAppear:false]);
  37. }
  38. - (void)testStatusBarHidden_default {
  39. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  40. [self.uut viewWillAppear:false];
  41. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  42. }
  43. - (void)testStatusBarHidden_true {
  44. self.options.statusBarHidden = @(1);
  45. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  46. [self.uut viewWillAppear:false];
  47. XCTAssertTrue([self.uut prefersStatusBarHidden]);
  48. }
  49. - (void)testStatusBarHidden_false {
  50. self.options.statusBarHidden = @(0);
  51. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  52. [self.uut viewWillAppear:false];
  53. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  54. }
  55. -(void)testTitle_string{
  56. NSString* title =@"some title";
  57. self.options.title= title;
  58. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  59. [self.uut viewWillAppear:false];
  60. XCTAssertTrue([self.uut.navigationItem.title isEqual:title]);
  61. }
  62. -(void)testTitle_default{
  63. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  64. [self.uut viewWillAppear:false];
  65. XCTAssertNil(self.uut.navigationItem.title);
  66. }
  67. -(void)testTopBarTextColor_validColor{
  68. NSNumber* inputColor = @(0xFFFF0000);
  69. self.options.topBarTextColor = inputColor;
  70. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  71. [self.uut viewWillAppear:false];
  72. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  73. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  74. }
  75. @end