react-native-navigation的迁移库

RNNRootViewControllerTest.m 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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)testTopBarHideOnScroll_true {
  91. NSNumber* hideOnScrollInput = @(1);
  92. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  93. self.options.topBarHideOnScroll = hideOnScrollInput;
  94. [self.uut viewWillAppear:false];
  95. XCTAssertTrue(self.uut.navigationController.hidesBarsOnSwipe);
  96. }
  97. -(void)testTopBarButtonColor {
  98. NSNumber* inputColor = @(0xFFFF0000);
  99. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  100. self.options.topBarButtonColor = inputColor;
  101. [self.uut viewWillAppear:false];
  102. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  103. XCTAssertTrue([self.uut.navigationController.navigationBar.tintColor isEqual:expectedColor]);
  104. }
  105. -(void)testTopBarTranslucent {
  106. NSNumber* topBarTranslucentInput = @(0);
  107. self.options.topBarTranslucent = topBarTranslucentInput;
  108. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  109. [self.uut viewWillAppear:false];
  110. XCTAssertFalse(self.uut.navigationController.navigationBar.translucent);
  111. }
  112. -(void)testTabBadge {
  113. NSString* tabBadgeInput = @"5";
  114. self.options.tabBadge = tabBadgeInput;
  115. __unused UITabBarController* vc = [[UITabBarController alloc] init];
  116. NSMutableArray* controllers = [NSMutableArray new];
  117. UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:@"A Tab" image:nil tag:1];
  118. [self.uut setTabBarItem:item];
  119. [controllers addObject:self.uut];
  120. [vc setViewControllers:controllers];
  121. [self.uut viewWillAppear:false];
  122. XCTAssertTrue([self.uut.tabBarItem.badgeValue isEqualToString:tabBadgeInput]);
  123. }
  124. -(void)testTopBarTextFontSize_withoutTextFontFamily_withoutTextColor {
  125. NSNumber* topBarTextFontSizeInput = @(15);
  126. self.options.topBarTextFontSize = topBarTextFontSizeInput;
  127. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  128. [self.uut viewWillAppear:false];
  129. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  130. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  131. }
  132. -(void)testTopBarTextFontSize_withoutTextFontFamily_withTextColor {
  133. NSNumber* topBarTextFontSizeInput = @(15);
  134. NSNumber* inputColor = @(0xFFFF0000);
  135. self.options.topBarTextFontSize = topBarTextFontSizeInput;
  136. self.options.topBarTextColor = inputColor;
  137. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  138. [self.uut viewWillAppear:false];
  139. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  140. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  141. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  142. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  143. }
  144. -(void)testTopBarTextFontSize_withTextFontFamily_withTextColor {
  145. NSNumber* topBarTextFontSizeInput = @(15);
  146. NSNumber* inputColor = @(0xFFFF0000);
  147. NSString* inputFont = @"HelveticaNeue";
  148. self.options.topBarTextFontSize = topBarTextFontSizeInput;
  149. self.options.topBarTextColor = inputColor;
  150. self.options.topBarTextFontFamily = inputFont;
  151. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  152. [self.uut viewWillAppear:false];
  153. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  154. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  155. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  156. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  157. }
  158. -(void)testTopBarTextFontSize_withTextFontFamily_withoutTextColor {
  159. NSNumber* topBarTextFontSizeInput = @(15);
  160. NSString* inputFont = @"HelveticaNeue";
  161. self.options.topBarTextFontSize = topBarTextFontSizeInput;
  162. self.options.topBarTextFontFamily = inputFont;
  163. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  164. [self.uut viewWillAppear:false];
  165. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  166. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  167. }
  168. // TODO: Currently not passing
  169. -(void)testTopBarTextFontFamily_invalidFont{
  170. NSString* inputFont = @"HelveticaNeueeeee";
  171. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  172. self.options.topBarTextFontFamily = inputFont;
  173. // XCTAssertThrows([self.uut viewWillAppear:false]);
  174. }
  175. @end