react-native-navigation的迁移库

RNNRootViewControllerTest.m 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. -(void)testScreenBackgroundColor_validColor{
  76. NSNumber* inputColor = @(0xFFFF0000);
  77. self.options.screenBackgroundColor = inputColor;
  78. [self.uut viewWillAppear:false];
  79. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  80. XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);
  81. }
  82. -(void)testTopBarTextFontFamily_validFont{
  83. NSString* inputFont = @"HelveticaNeue";
  84. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  85. self.options.topBarTextFontFamily = inputFont;
  86. [self.uut viewWillAppear:false];
  87. UIFont* expectedFont = [UIFont fontWithName:inputFont size:20];
  88. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  89. }
  90. -(void)testTopBarTextFontFamily_invalidFont{
  91. NSString* inputFont = @"HelveticaNeueeeee";
  92. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  93. self.options.topBarTextFontFamily = inputFont;
  94. XCTAssertThrows([self.uut viewWillAppear:false]);
  95. }
  96. -(void)testTopBarHideOnScroll_true {
  97. NSNumber* hideOnScrollInput = @(1);
  98. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  99. self.options.topBarHideOnScroll = hideOnScrollInput;
  100. [self.uut viewWillAppear:false];
  101. XCTAssertTrue(self.uut.navigationController.hidesBarsOnSwipe);
  102. }
  103. -(void)testTopBarButtonColor {
  104. NSNumber* inputColor = @(0xFFFF0000);
  105. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  106. self.options.topBarButtonColor = inputColor;
  107. [self.uut viewWillAppear:false];
  108. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  109. XCTAssertTrue([self.uut.navigationController.navigationBar.tintColor isEqual:expectedColor]);
  110. }
  111. -(void)testTopBarTranslucent {
  112. NSNumber* topBarTranslucentInput = @(0);
  113. self.options.topBarTranslucent = topBarTranslucentInput;
  114. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  115. [self.uut viewWillAppear:false];
  116. XCTAssertFalse(self.uut.navigationController.navigationBar.translucent);
  117. }
  118. @end