react-native-navigation的迁移库

RNNRootViewControllerTest.m 30KB

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