react-native-navigation的迁移库

RNNRootViewControllerTest.m 27KB

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