react-native-navigation的迁移库

RNNRootViewControllerTest.m 31KB

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