react-native-navigation的迁移库

RNNRootViewControllerTest.m 31KB

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