react-native-navigation的迁移库

RNNRootViewControllerTest.m 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. #import "RNNNavigationController.h"
  8. #import "RNNTabBarController.h"
  9. #import "RNNUIBarButtonItem.h"
  10. @interface RNNRootViewController (EmbedInTabBar)
  11. - (void)embedInTabBarController;
  12. @end
  13. @implementation RNNRootViewController (EmbedInTabBar)
  14. - (void)embedInTabBarController {
  15. RNNTabBarController* tabVC = [[RNNTabBarController alloc] init];
  16. tabVC.viewControllers = @[self];
  17. [self viewWillAppear:false];
  18. }
  19. @end
  20. @interface RNNRootViewControllerTest : XCTestCase
  21. @property (nonatomic, strong) id<RNNRootViewCreator> creator;
  22. @property (nonatomic, strong) NSString* pageName;
  23. @property (nonatomic, strong) NSString* componentId;
  24. @property (nonatomic, strong) id emitter;
  25. @property (nonatomic, strong) RNNNavigationOptions* options;
  26. @property (nonatomic, strong) RNNLayoutInfo* layoutInfo;
  27. @property (nonatomic, strong) RNNRootViewController* uut;
  28. @end
  29. @implementation RNNRootViewControllerTest
  30. - (void)setUp {
  31. [super setUp];
  32. self.creator = [[RNNTestRootViewCreator alloc] init];
  33. self.pageName = @"somename";
  34. self.componentId = @"cntId";
  35. self.emitter = nil;
  36. self.options = [[RNNNavigationOptions alloc] initWithDict:@{}];
  37. RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
  38. layoutInfo.componentId = self.componentId;
  39. layoutInfo.name = self.pageName;
  40. layoutInfo.options = self.options;
  41. self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:self.creator eventEmitter:self.emitter isExternalComponent:NO];
  42. }
  43. -(void)testTopBarBackgroundColor_validColor{
  44. NSNumber* inputColor = @(0xFFFF0000);
  45. self.options.topBar.background.color = inputColor;
  46. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  47. [self.uut viewWillAppear:false];
  48. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  49. XCTAssertTrue([self.uut.navigationController.navigationBar.barTintColor isEqual:expectedColor]);
  50. }
  51. -(void)testTopBarBackgroundColorWithoutNavigationController{
  52. NSNumber* inputColor = @(0xFFFF0000);
  53. self.options.topBar.background.color = inputColor;
  54. XCTAssertNoThrow([self.uut viewWillAppear:false]);
  55. }
  56. - (void)testStatusBarHidden_default {
  57. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  58. [self.uut viewWillAppear:false];
  59. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  60. }
  61. - (void)testStatusBarVisible_false {
  62. self.options.statusBar.visible = @(0);
  63. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  64. [self.uut viewWillAppear:false];
  65. XCTAssertTrue([self.uut prefersStatusBarHidden]);
  66. }
  67. - (void)testStatusBarVisible_true {
  68. self.options.statusBar.visible = @(1);
  69. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  70. [self.uut viewWillAppear:false];
  71. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  72. }
  73. - (void)testStatusBarHideWithTopBar_false {
  74. self.options.statusBar.hideWithTopBar = @(0);
  75. self.options.topBar.visible = @(0);
  76. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  77. [self.uut viewWillAppear:false];
  78. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  79. }
  80. - (void)testStatusBarHideWithTopBar_true {
  81. self.options.statusBar.hideWithTopBar = @(1);
  82. self.options.topBar.visible = @(0);
  83. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  84. [self.uut viewWillAppear:false];
  85. XCTAssertTrue([self.uut prefersStatusBarHidden]);
  86. }
  87. -(void)testTitle_string{
  88. NSString* title =@"some title";
  89. self.options.topBar.title.text = title;
  90. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  91. [self.uut viewWillAppear:false];
  92. XCTAssertTrue([self.uut.navigationItem.title isEqual:title]);
  93. }
  94. -(void)testTitle_default{
  95. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  96. [self.uut viewWillAppear:false];
  97. XCTAssertNil(self.uut.navigationItem.title);
  98. }
  99. -(void)testTopBarTextColor_validColor{
  100. NSNumber* inputColor = @(0xFFFF0000);
  101. self.options.topBar.title.color = inputColor;
  102. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  103. [self.uut viewWillAppear:false];
  104. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  105. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  106. }
  107. -(void)testbackgroundColor_validColor{
  108. NSNumber* inputColor = @(0xFFFF0000);
  109. self.options.layout.backgroundColor = inputColor;
  110. [self.uut viewWillAppear:false];
  111. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  112. XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);
  113. }
  114. -(void)testPopGestureEnabled_true{
  115. NSNumber* popGestureEnabled = @(1);
  116. self.options.popGesture = popGestureEnabled;
  117. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  118. [self.uut viewWillAppear:false];
  119. XCTAssertTrue(self.uut.navigationController.interactivePopGestureRecognizer.enabled);
  120. }
  121. -(void)testPopGestureEnabled_false{
  122. NSNumber* popGestureEnabled = @(0);
  123. self.options.popGesture = popGestureEnabled;
  124. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  125. [self.uut viewWillAppear:false];
  126. XCTAssertFalse(self.uut.navigationController.interactivePopGestureRecognizer.enabled);
  127. }
  128. -(void)testTopBarTextFontFamily_validFont{
  129. NSString* inputFont = @"HelveticaNeue";
  130. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  131. self.options.topBar.title.fontFamily = inputFont;
  132. [self.uut viewWillAppear:false];
  133. UIFont* expectedFont = [UIFont fontWithName:inputFont size:17];
  134. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  135. }
  136. -(void)testTopBarHideOnScroll_true {
  137. NSNumber* hideOnScrollInput = @(1);
  138. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  139. self.options.topBar.hideOnScroll = hideOnScrollInput;
  140. [self.uut viewWillAppear:false];
  141. XCTAssertTrue(self.uut.navigationController.hidesBarsOnSwipe);
  142. }
  143. -(void)testTopBarTranslucent {
  144. NSNumber* topBarTranslucentInput = @(0);
  145. self.options.topBar.translucent = topBarTranslucentInput;
  146. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  147. [self.uut viewWillAppear:false];
  148. XCTAssertFalse(self.uut.navigationController.navigationBar.translucent);
  149. }
  150. -(void)testTabBadge {
  151. NSString* tabBadgeInput = @"5";
  152. self.options.bottomTab.badge = tabBadgeInput;
  153. __unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
  154. NSMutableArray* controllers = [NSMutableArray new];
  155. UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:@"A Tab" image:nil tag:1];
  156. [self.uut setTabBarItem:item];
  157. [controllers addObject:self.uut];
  158. [vc setViewControllers:controllers];
  159. [self.uut viewWillAppear:false];
  160. XCTAssertTrue([self.uut.tabBarItem.badgeValue isEqualToString:tabBadgeInput]);
  161. }
  162. -(void)testTopBarTransparent_BOOL_True {
  163. NSNumber* topBarTransparentInput = @(1);
  164. self.options.topBar.transparent = topBarTransparentInput;
  165. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  166. [self.uut viewWillAppear:false];
  167. UIView* transparentView = [self.uut.navigationController.navigationBar viewWithTag:TOP_BAR_TRANSPARENT_TAG];
  168. XCTAssertTrue(transparentView);
  169. XCTAssertTrue([NSStringFromCGRect(transparentView.frame) isEqual: NSStringFromCGRect(CGRectZero)]);
  170. }
  171. -(void)testTopBarTransparent_BOOL_false {
  172. NSNumber* topBarTransparentInput = @(0);
  173. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  174. self.options.topBar.transparent = topBarTransparentInput;
  175. [self.uut viewWillAppear:false];
  176. UIView* transparentView = [self.uut.navigationController.navigationBar viewWithTag:TOP_BAR_TRANSPARENT_TAG];
  177. XCTAssertFalse(transparentView);
  178. }
  179. -(void)testStoreOriginalTopBarImages {
  180. }
  181. -(void)testTopBarLargeTitle_default {
  182. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  183. [self.uut viewWillAppear:false];
  184. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeNever);
  185. }
  186. -(void)testTopBarLargeTitle_true {
  187. self.options.topBar.largeTitle.visible = @(1);
  188. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  189. [self.uut viewWillAppear:false];
  190. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeAlways);
  191. }
  192. -(void)testTopBarLargeTitle_false {
  193. self.options.topBar.largeTitle.visible = @(0);
  194. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  195. [self.uut viewWillAppear:false];
  196. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeNever);
  197. }
  198. -(void)testTopBarLargeTitleFontSize_withoutTextFontFamily_withoutTextColor {
  199. NSNumber* topBarTextFontSizeInput = @(15);
  200. self.options.topBar.largeTitle.fontSize = topBarTextFontSizeInput;
  201. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  202. [self.uut viewWillAppear:false];
  203. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  204. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  205. }
  206. -(void)testTopBarLargeTitleFontSize_withoutTextFontFamily_withTextColor {
  207. NSNumber* topBarTextFontSizeInput = @(15);
  208. NSNumber* inputColor = @(0xFFFF0000);
  209. self.options.topBar.largeTitle.fontSize = topBarTextFontSizeInput;
  210. self.options.topBar.largeTitle.color = inputColor;
  211. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  212. [self.uut viewWillAppear:false];
  213. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  214. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  215. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  216. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  217. }
  218. -(void)testTopBarLargeTitleFontSize_withTextFontFamily_withTextColor {
  219. NSNumber* topBarTextFontSizeInput = @(15);
  220. NSNumber* inputColor = @(0xFFFF0000);
  221. NSString* inputFont = @"HelveticaNeue";
  222. self.options.topBar.largeTitle.fontSize = topBarTextFontSizeInput;
  223. self.options.topBar.largeTitle.color = inputColor;
  224. self.options.topBar.largeTitle.fontFamily = inputFont;
  225. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  226. [self.uut viewWillAppear:false];
  227. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  228. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  229. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  230. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  231. }
  232. -(void)testTopBarLargeTitleFontSize_withTextFontFamily_withoutTextColor {
  233. NSNumber* topBarTextFontSizeInput = @(15);
  234. NSString* inputFont = @"HelveticaNeue";
  235. self.options.topBar.largeTitle.fontSize = topBarTextFontSizeInput;
  236. self.options.topBar.largeTitle.fontFamily = inputFont;
  237. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  238. [self.uut viewWillAppear:false];
  239. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  240. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  241. }
  242. -(void)testTopBarTextFontSize_withoutTextFontFamily_withoutTextColor {
  243. NSNumber* topBarTextFontSizeInput = @(15);
  244. self.options.topBar.title.fontSize = topBarTextFontSizeInput;
  245. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  246. [self.uut viewWillAppear:false];
  247. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  248. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  249. }
  250. -(void)testTopBarTextFontSize_withoutTextFontFamily_withTextColor {
  251. NSNumber* topBarTextFontSizeInput = @(15);
  252. NSNumber* inputColor = @(0xFFFF0000);
  253. self.options.topBar.title.fontSize = topBarTextFontSizeInput;
  254. self.options.topBar.title.color = inputColor;
  255. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  256. [self.uut viewWillAppear:false];
  257. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  258. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  259. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  260. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  261. }
  262. -(void)testTopBarTextFontSize_withTextFontFamily_withTextColor {
  263. NSNumber* topBarTextFontSizeInput = @(15);
  264. NSNumber* inputColor = @(0xFFFF0000);
  265. NSString* inputFont = @"HelveticaNeue";
  266. self.options.topBar.title.fontSize = topBarTextFontSizeInput;
  267. self.options.topBar.title.color = inputColor;
  268. self.options.topBar.title.fontFamily = inputFont;
  269. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  270. [self.uut viewWillAppear:false];
  271. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  272. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  273. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  274. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  275. }
  276. -(void)testTopBarTextFontSize_withTextFontFamily_withoutTextColor {
  277. NSNumber* topBarTextFontSizeInput = @(15);
  278. NSString* inputFont = @"HelveticaNeue";
  279. self.options.topBar.title.fontSize = topBarTextFontSizeInput;
  280. self.options.topBar.title.fontFamily = inputFont;
  281. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  282. [self.uut viewWillAppear:false];
  283. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  284. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  285. }
  286. // TODO: Currently not passing
  287. -(void)testTopBarTextFontFamily_invalidFont{
  288. NSString* inputFont = @"HelveticaNeueeeee";
  289. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  290. self.options.topBar.title.fontFamily = inputFont;
  291. // XCTAssertThrows([self.uut viewWillAppear:false]);
  292. }
  293. -(void)testOrientation_portrait {
  294. NSArray* supportedOrientations = @[@"portrait"];
  295. self.options.layout.orientation = supportedOrientations;
  296. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  297. [self.uut viewWillAppear:false];
  298. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
  299. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  300. }
  301. -(void)testOrientation_portraitString {
  302. NSString* supportedOrientation = @"portrait";
  303. self.options.layout.orientation = supportedOrientation;
  304. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  305. [self.uut viewWillAppear:false];
  306. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait);
  307. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  308. }
  309. -(void)testOrientation_portraitAndLandscape {
  310. NSArray* supportedOrientations = @[@"portrait", @"landscape"];
  311. self.options.layout.orientation = supportedOrientations;
  312. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  313. [self.uut viewWillAppear:false];
  314. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
  315. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  316. }
  317. -(void)testOrientation_all {
  318. NSArray* supportedOrientations = @[@"all"];
  319. self.options.layout.orientation = supportedOrientations;
  320. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  321. [self.uut viewWillAppear:false];
  322. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
  323. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  324. }
  325. -(void)testOrientation_default {
  326. NSString* supportedOrientations = @"default";
  327. self.options.layout.orientation = supportedOrientations;
  328. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  329. [self.uut viewWillAppear:false];
  330. UIInterfaceOrientationMask expectedOrientation = [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
  331. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  332. }
  333. -(void)testOrientationTabsController_portrait {
  334. NSArray* supportedOrientations = @[@"portrait"];
  335. self.options.layout.orientation = supportedOrientations;
  336. __unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
  337. NSMutableArray* controllers = [NSMutableArray new];
  338. [controllers addObject:self.uut];
  339. [vc setViewControllers:controllers];
  340. [self.uut viewWillAppear:false];
  341. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
  342. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  343. }
  344. -(void)testOrientationTabsController_portraitAndLandscape {
  345. NSArray* supportedOrientations = @[@"portrait", @"landscape"];
  346. self.options.layout.orientation = supportedOrientations;
  347. __unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
  348. NSMutableArray* controllers = [NSMutableArray new];
  349. [controllers addObject:self.uut];
  350. [vc setViewControllers:controllers];
  351. [self.uut viewWillAppear:false];
  352. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
  353. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  354. }
  355. -(void)testOrientationTabsController_all {
  356. NSArray* supportedOrientations = @[@"all"];
  357. self.options.layout.orientation = supportedOrientations;
  358. __unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
  359. NSMutableArray* controllers = [NSMutableArray new];
  360. [controllers addObject:self.uut];
  361. [vc setViewControllers:controllers];
  362. [self.uut viewWillAppear:false];
  363. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
  364. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  365. }
  366. -(void)testRightButtonsWithTitle_withoutStyle {
  367. self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test"}];
  368. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  369. [self.uut viewWillAppear:false];
  370. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
  371. NSString* expectedButtonId = @"testId";
  372. NSString* expectedTitle = @"test";
  373. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  374. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  375. XCTAssertTrue(button.enabled);
  376. }
  377. -(void)testRightButtonsWithTitle_withStyle {
  378. NSNumber* inputColor = @(0xFFFF0000);
  379. self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
  380. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  381. [self.uut viewWillAppear:false];
  382. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
  383. NSString* expectedButtonId = @"testId";
  384. NSString* expectedTitle = @"test";
  385. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  386. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  387. XCTAssertFalse(button.enabled);
  388. //TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
  389. }
  390. -(void)testLeftButtonsWithTitle_withoutStyle {
  391. self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test"}];
  392. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  393. [self.uut viewWillAppear:false];
  394. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
  395. NSString* expectedButtonId = @"testId";
  396. NSString* expectedTitle = @"test";
  397. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  398. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  399. XCTAssertTrue(button.enabled);
  400. }
  401. -(void)testLeftButtonsWithTitle_withStyle {
  402. NSNumber* inputColor = @(0xFFFF0000);
  403. self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
  404. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  405. [self.uut viewWillAppear:false];
  406. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
  407. NSString* expectedButtonId = @"testId";
  408. NSString* expectedTitle = @"test";
  409. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  410. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  411. XCTAssertFalse(button.enabled);
  412. //TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
  413. }
  414. -(void)testTopBarNoBorderOn {
  415. NSNumber* topBarNoBorderInput = @(1);
  416. self.options.topBar.noBorder = topBarNoBorderInput;
  417. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  418. [self.uut viewWillAppear:false];
  419. XCTAssertNotNil(self.uut.navigationController.navigationBar.shadowImage);
  420. }
  421. -(void)testTopBarNoBorderOff {
  422. NSNumber* topBarNoBorderInput = @(0);
  423. self.options.topBar.noBorder = topBarNoBorderInput;
  424. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  425. [self.uut viewWillAppear:false];
  426. XCTAssertNil(self.uut.navigationController.navigationBar.shadowImage);
  427. }
  428. -(void)testStatusBarBlurOn {
  429. NSNumber* statusBarBlurInput = @(1);
  430. self.options.statusBar.blur = statusBarBlurInput;
  431. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  432. [self.uut viewWillAppear:false];
  433. XCTAssertNotNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  434. }
  435. -(void)testStatusBarBlurOff {
  436. NSNumber* statusBarBlurInput = @(0);
  437. self.options.statusBar.blur = statusBarBlurInput;
  438. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  439. [self.uut viewWillAppear:false];
  440. XCTAssertNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  441. }
  442. - (void)testTabBarHidden_default {
  443. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  444. [self.uut viewWillAppear:false];
  445. XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
  446. }
  447. - (void)testTabBarHidden_true {
  448. self.options.bottomTabs.visible = @(0);
  449. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  450. [self.uut viewWillAppear:false];
  451. XCTAssertTrue([self.uut hidesBottomBarWhenPushed]);
  452. }
  453. - (void)testTabBarHidden_false {
  454. self.options.bottomTabs.visible = @(1);
  455. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  456. [self.uut viewWillAppear:false];
  457. XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
  458. }
  459. -(void)testTopBarBlur_default {
  460. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  461. [self.uut viewWillAppear:false];
  462. XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  463. }
  464. -(void)testTopBarBlur_false {
  465. NSNumber* topBarBlurInput = @(0);
  466. self.options.topBar.blur = topBarBlurInput;
  467. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  468. [self.uut viewWillAppear:false];
  469. XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  470. }
  471. -(void)testTopBarBlur_true {
  472. NSNumber* topBarBlurInput = @(1);
  473. self.options.topBar.blur = topBarBlurInput;
  474. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  475. [self.uut viewWillAppear:false];
  476. XCTAssertNotNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  477. }
  478. -(void)testBackgroundImage {
  479. UIImage* backgroundImage = [[UIImage alloc] init];
  480. self.options.backgroundImage = backgroundImage;
  481. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  482. [self.uut viewWillAppear:false];
  483. XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:backgroundImage]);
  484. }
  485. -(void)testRootBackgroundImage {
  486. UIImage* rootBackgroundImage = [[UIImage alloc] init];
  487. self.options.rootBackgroundImage = rootBackgroundImage;
  488. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  489. [self.uut viewWillAppear:false];
  490. XCTAssertTrue([[(UIImageView*)self.uut.navigationController.view.subviews[0] image] isEqual:rootBackgroundImage]);
  491. }
  492. -(void)testTopBarDrawUnder_true {
  493. self.options.topBar.drawBehind = @(1);
  494. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  495. [self.uut viewWillAppear:false];
  496. XCTAssertTrue(self.uut.edgesForExtendedLayout & UIRectEdgeTop);
  497. }
  498. -(void)testTopBarDrawUnder_false {
  499. self.options.topBar.drawBehind = @(0);
  500. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  501. [self.uut viewWillAppear:false];
  502. XCTAssertFalse(self.uut.edgesForExtendedLayout & UIRectEdgeTop);
  503. }
  504. -(void)testBottomTabsDrawUnder_true {
  505. self.options.bottomTabs.drawBehind = @(1);
  506. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  507. [self.uut viewWillAppear:false];
  508. XCTAssertTrue(self.uut.edgesForExtendedLayout & UIRectEdgeBottom);
  509. }
  510. -(void)testBottomTabsDrawUnder_false {
  511. self.options.bottomTabs.drawBehind = @(0);
  512. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  513. [self.uut viewWillAppear:false];
  514. XCTAssertFalse(self.uut.edgesForExtendedLayout & UIRectEdgeBottom);
  515. }
  516. #pragma mark BottomTabs
  517. - (void)testTabBarTranslucent_default {
  518. [self.uut embedInTabBarController];
  519. XCTAssertFalse(self.uut.tabBarController.tabBar.translucent);
  520. }
  521. - (void)testTabBarTranslucent_true {
  522. self.options.bottomTabs.translucent = @(1);
  523. [self.uut embedInTabBarController];
  524. XCTAssertTrue(self.uut.tabBarController.tabBar.translucent);
  525. }
  526. - (void)testTabBarTranslucent_false {
  527. self.options.bottomTabs.translucent = @(0);
  528. [self.uut embedInTabBarController];
  529. XCTAssertFalse(self.uut.tabBarController.tabBar.translucent);
  530. }
  531. - (void)testTabBarHideShadow_default {
  532. [self.uut embedInTabBarController];
  533. XCTAssertFalse(self.uut.tabBarController.tabBar.clipsToBounds);
  534. }
  535. - (void)testTabBarHideShadow_true {
  536. self.options.bottomTabs.hideShadow = @(1);
  537. [self.uut embedInTabBarController];
  538. XCTAssertTrue(self.uut.tabBarController.tabBar.clipsToBounds);
  539. }
  540. - (void)testTabBarHideShadow_false {
  541. self.options.bottomTabs.hideShadow = @(0);
  542. [self.uut embedInTabBarController];
  543. XCTAssertFalse(self.uut.tabBarController.tabBar.clipsToBounds);
  544. }
  545. - (void)testTabBarBackgroundColor {
  546. self.options.bottomTabs.backgroundColor = @(0xFFFF0000);
  547. [self.uut embedInTabBarController];
  548. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  549. XCTAssertTrue([self.uut.tabBarController.tabBar.barTintColor isEqual:expectedColor]);
  550. }
  551. -(void)testTabBarTextFontFamily_validFont{
  552. NSString* inputFont = @"HelveticaNeue";
  553. self.options.bottomTab.fontFamily = inputFont;
  554. self.options.bottomTab.text = @"Tab 1";
  555. [self.uut embedInTabBarController];
  556. UIFont* expectedFont = [UIFont fontWithName:inputFont size:10];
  557. NSDictionary* attributes = [self.uut.tabBarController.tabBar.items.firstObject titleTextAttributesForState:UIControlStateNormal];
  558. XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  559. }
  560. -(void)testTabBarTextFontSize_withoutTextFontFamily_withoutTextColor {
  561. self.options.bottomTab.fontSize = @(15);
  562. self.options.bottomTab.text = @"Tab 1";
  563. [self.uut embedInTabBarController];
  564. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  565. NSDictionary* attributes = [self.uut.tabBarController.tabBar.items.firstObject titleTextAttributesForState:UIControlStateNormal];
  566. XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  567. }
  568. -(void)testTabBarTextFontSize_withoutTextFontFamily {
  569. self.options.bottomTab.fontSize = @(15);
  570. self.options.bottomTab.text = @"Tab 1";
  571. [self.uut embedInTabBarController];
  572. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  573. NSDictionary* attributes = [self.uut.tabBarController.tabBar.items.firstObject titleTextAttributesForState:UIControlStateNormal];
  574. XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  575. }
  576. -(void)testTabBarTextFontSize_withTextFontFamily_withTextColor {
  577. NSString* inputFont = @"HelveticaNeue";
  578. self.options.bottomTab.text = @"Tab 1";
  579. self.options.bottomTab.fontSize = @(15);
  580. self.options.bottomTab.fontFamily = inputFont;
  581. [self.uut embedInTabBarController];
  582. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  583. NSDictionary* attributes = [self.uut.tabBarController.tabBar.items.firstObject titleTextAttributesForState:UIControlStateNormal];
  584. XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  585. }
  586. -(void)testTabBarTextFontSize_withTextFontFamily_withoutTextColor {
  587. NSString* inputFont = @"HelveticaNeue";
  588. self.options.bottomTab.text = @"Tab 1";
  589. self.options.bottomTab.fontSize = @(15);
  590. self.options.bottomTab.fontFamily = inputFont;
  591. [self.uut embedInTabBarController];
  592. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  593. NSDictionary* attributes = [self.uut.tabBarController.tabBar.items.firstObject titleTextAttributesForState:UIControlStateNormal];
  594. XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  595. }
  596. - (void)testTopBarBackgroundClipToBounds_true {
  597. self.options.topBar.background.clipToBounds = @(1);
  598. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  599. [self.uut viewWillAppear:false];
  600. XCTAssertTrue(self.uut.navigationController.navigationBar.clipsToBounds);
  601. }
  602. - (void)testTopBarBackgroundClipToBounds_false {
  603. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  604. [self.uut viewWillAppear:false];
  605. XCTAssertFalse(self.uut.navigationController.navigationBar.clipsToBounds);
  606. }
  607. @end