react-native-navigation的迁移库

RNNRootViewControllerTest.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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)testStatusBarHideWithTopBar_false {
  50. self.options.statusBarHideWithTopBar = @(0);
  51. self.options.topBarHidden = @(1);
  52. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  53. [self.uut viewWillAppear:false];
  54. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  55. }
  56. - (void)testStatusBarHideWithTopBar_true {
  57. self.options.statusBarHideWithTopBar = @(1);
  58. self.options.topBarHidden = @(1);
  59. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  60. [self.uut viewWillAppear:false];
  61. XCTAssertTrue([self.uut prefersStatusBarHidden]);
  62. }
  63. - (void)testStatusBarHidden_false {
  64. self.options.statusBarHidden = @(0);
  65. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  66. [self.uut viewWillAppear:false];
  67. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  68. }
  69. -(void)testTitle_string{
  70. NSString* title =@"some title";
  71. self.options.title= title;
  72. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  73. [self.uut viewWillAppear:false];
  74. XCTAssertTrue([self.uut.navigationItem.title isEqual:title]);
  75. }
  76. -(void)testTitle_default{
  77. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  78. [self.uut viewWillAppear:false];
  79. XCTAssertNil(self.uut.navigationItem.title);
  80. }
  81. -(void)testTopBarTextColor_validColor{
  82. NSNumber* inputColor = @(0xFFFF0000);
  83. self.options.topBarTextColor = inputColor;
  84. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  85. [self.uut viewWillAppear:false];
  86. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  87. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  88. }
  89. -(void)testScreenBackgroundColor_validColor{
  90. NSNumber* inputColor = @(0xFFFF0000);
  91. self.options.screenBackgroundColor = inputColor;
  92. [self.uut viewWillAppear:false];
  93. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  94. XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);
  95. }
  96. -(void)testTopBarTextFontFamily_validFont{
  97. NSString* inputFont = @"HelveticaNeue";
  98. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  99. self.options.topBarTextFontFamily = inputFont;
  100. [self.uut viewWillAppear:false];
  101. UIFont* expectedFont = [UIFont fontWithName:inputFont size:20];
  102. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  103. }
  104. -(void)testTopBarHideOnScroll_true {
  105. NSNumber* hideOnScrollInput = @(1);
  106. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  107. self.options.topBarHideOnScroll = hideOnScrollInput;
  108. [self.uut viewWillAppear:false];
  109. XCTAssertTrue(self.uut.navigationController.hidesBarsOnSwipe);
  110. }
  111. -(void)testTopBarButtonColor {
  112. NSNumber* inputColor = @(0xFFFF0000);
  113. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  114. self.options.topBarButtonColor = inputColor;
  115. [self.uut viewWillAppear:false];
  116. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  117. XCTAssertTrue([self.uut.navigationController.navigationBar.tintColor isEqual:expectedColor]);
  118. }
  119. -(void)testTopBarTranslucent {
  120. NSNumber* topBarTranslucentInput = @(0);
  121. self.options.topBarTranslucent = topBarTranslucentInput;
  122. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  123. [self.uut viewWillAppear:false];
  124. XCTAssertFalse(self.uut.navigationController.navigationBar.translucent);
  125. }
  126. -(void)testTabBadge {
  127. NSString* tabBadgeInput = @"5";
  128. self.options.tabBadge = tabBadgeInput;
  129. __unused UITabBarController* vc = [[UITabBarController alloc] init];
  130. NSMutableArray* controllers = [NSMutableArray new];
  131. UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:@"A Tab" image:nil tag:1];
  132. [self.uut setTabBarItem:item];
  133. [controllers addObject:self.uut];
  134. [vc setViewControllers:controllers];
  135. [self.uut viewWillAppear:false];
  136. XCTAssertTrue([self.uut.tabBarItem.badgeValue isEqualToString:tabBadgeInput]);
  137. }
  138. -(void)testTopBarTextFontSize_withoutTextFontFamily_withoutTextColor {
  139. NSNumber* topBarTextFontSizeInput = @(15);
  140. self.options.topBarTextFontSize = topBarTextFontSizeInput;
  141. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  142. [self.uut viewWillAppear:false];
  143. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  144. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  145. }
  146. -(void)testTopBarTextFontSize_withoutTextFontFamily_withTextColor {
  147. NSNumber* topBarTextFontSizeInput = @(15);
  148. NSNumber* inputColor = @(0xFFFF0000);
  149. self.options.topBarTextFontSize = topBarTextFontSizeInput;
  150. self.options.topBarTextColor = inputColor;
  151. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  152. [self.uut viewWillAppear:false];
  153. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  154. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  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_withTextColor {
  159. NSNumber* topBarTextFontSizeInput = @(15);
  160. NSNumber* inputColor = @(0xFFFF0000);
  161. NSString* inputFont = @"HelveticaNeue";
  162. self.options.topBarTextFontSize = topBarTextFontSizeInput;
  163. self.options.topBarTextColor = inputColor;
  164. self.options.topBarTextFontFamily = inputFont;
  165. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  166. [self.uut viewWillAppear:false];
  167. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  168. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  169. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  170. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  171. }
  172. -(void)testTopBarTextFontSize_withTextFontFamily_withoutTextColor {
  173. NSNumber* topBarTextFontSizeInput = @(15);
  174. NSString* inputFont = @"HelveticaNeue";
  175. self.options.topBarTextFontSize = topBarTextFontSizeInput;
  176. self.options.topBarTextFontFamily = inputFont;
  177. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  178. [self.uut viewWillAppear:false];
  179. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  180. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  181. }
  182. // TODO: Currently not passing
  183. -(void)testTopBarTextFontFamily_invalidFont{
  184. NSString* inputFont = @"HelveticaNeueeeee";
  185. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  186. self.options.topBarTextFontFamily = inputFont;
  187. // XCTAssertThrows([self.uut viewWillAppear:false]);
  188. }
  189. -(void)testTopBarNoBorderOn {
  190. NSNumber* topBarNoBorderInput = @(1);
  191. self.options.topBarNoBorder = topBarNoBorderInput;
  192. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  193. [self.uut viewWillAppear:false];
  194. XCTAssertNotNil(self.uut.navigationController.navigationBar.shadowImage);
  195. }
  196. -(void)testTopBarNoBorderOff {
  197. NSNumber* topBarNoBorderInput = @(0);
  198. self.options.topBarNoBorder = topBarNoBorderInput;
  199. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  200. [self.uut viewWillAppear:false];
  201. XCTAssertNil(self.uut.navigationController.navigationBar.shadowImage);
  202. }
  203. -(void)testStatusBarBlurOn {
  204. NSNumber* statusBarBlurInput = @(1);
  205. self.options.statusBarBlur = statusBarBlurInput;
  206. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  207. [self.uut viewWillAppear:false];
  208. XCTAssertNotNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  209. }
  210. -(void)testStatusBarBlurOff {
  211. NSNumber* statusBarBlurInput = @(0);
  212. self.options.statusBarBlur = statusBarBlurInput;
  213. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  214. [self.uut viewWillAppear:false];
  215. XCTAssertNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  216. }
  217. @end