react-native-navigation的迁移库

RNNRootViewControllerTest.m 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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 new];
  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.backgroundColor = 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.backgroundColor = 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.statusBarHidden = @(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.statusBarHideWithTopBar = @(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.statusBarHideWithTopBar = @(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.statusBarHidden = @(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)testScreenBackgroundColor_validColor{
  103. NSNumber* inputColor = @(0xFFFF0000);
  104. self.options.screenBackgroundColor = 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)testTopBarTextFontSize_withoutTextFontFamily_withoutTextColor {
  185. NSNumber* topBarTextFontSizeInput = @(15);
  186. self.options.topBar.title.fontSize = topBarTextFontSizeInput;
  187. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  188. [self.uut viewWillAppear:false];
  189. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  190. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  191. }
  192. -(void)testTopBarTextFontSize_withoutTextFontFamily_withTextColor {
  193. NSNumber* topBarTextFontSizeInput = @(15);
  194. NSNumber* inputColor = @(0xFFFF0000);
  195. self.options.topBar.title.fontSize = topBarTextFontSizeInput;
  196. self.options.topBar.title.color = inputColor;
  197. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  198. [self.uut viewWillAppear:false];
  199. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  200. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  201. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  202. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  203. }
  204. -(void)testTopBarTextFontSize_withTextFontFamily_withTextColor {
  205. NSNumber* topBarTextFontSizeInput = @(15);
  206. NSNumber* inputColor = @(0xFFFF0000);
  207. NSString* inputFont = @"HelveticaNeue";
  208. self.options.topBar.title.fontSize = topBarTextFontSizeInput;
  209. self.options.topBar.title.color = inputColor;
  210. self.options.topBar.title.fontFamily = inputFont;
  211. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  212. [self.uut viewWillAppear:false];
  213. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  214. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  215. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  216. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  217. }
  218. -(void)testTopBarTextFontSize_withTextFontFamily_withoutTextColor {
  219. NSNumber* topBarTextFontSizeInput = @(15);
  220. NSString* inputFont = @"HelveticaNeue";
  221. self.options.topBar.title.fontSize = topBarTextFontSizeInput;
  222. self.options.topBar.title.fontFamily = inputFont;
  223. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  224. [self.uut viewWillAppear:false];
  225. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  226. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  227. }
  228. // TODO: Currently not passing
  229. -(void)testTopBarTextFontFamily_invalidFont{
  230. NSString* inputFont = @"HelveticaNeueeeee";
  231. __unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  232. self.options.topBar.title.fontFamily = inputFont;
  233. // XCTAssertThrows([self.uut viewWillAppear:false]);
  234. }
  235. -(void)testOrientation_portrait {
  236. NSArray* supportedOrientations = @[@"portrait"];
  237. self.options.orientation = supportedOrientations;
  238. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  239. [self.uut viewWillAppear:false];
  240. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
  241. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  242. }
  243. -(void)testOrientation_portraitString {
  244. NSString* supportedOrientation = @"portrait";
  245. self.options.orientation = supportedOrientation;
  246. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  247. [self.uut viewWillAppear:false];
  248. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait);
  249. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  250. }
  251. -(void)testOrientation_portraitAndLandscape {
  252. NSArray* supportedOrientations = @[@"portrait", @"landscape"];
  253. self.options.orientation = supportedOrientations;
  254. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  255. [self.uut viewWillAppear:false];
  256. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
  257. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  258. }
  259. -(void)testOrientation_all {
  260. NSArray* supportedOrientations = @[@"all"];
  261. self.options.orientation = supportedOrientations;
  262. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  263. [self.uut viewWillAppear:false];
  264. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
  265. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  266. }
  267. -(void)testOrientation_default {
  268. NSString* supportedOrientations = @"default";
  269. self.options.orientation = supportedOrientations;
  270. __unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
  271. [self.uut viewWillAppear:false];
  272. UIInterfaceOrientationMask expectedOrientation = [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
  273. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  274. }
  275. -(void)testOrientationTabsController_portrait {
  276. NSArray* supportedOrientations = @[@"portrait"];
  277. self.options.orientation = supportedOrientations;
  278. __unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
  279. NSMutableArray* controllers = [NSMutableArray new];
  280. [controllers addObject:self.uut];
  281. [vc setViewControllers:controllers];
  282. [self.uut viewWillAppear:false];
  283. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
  284. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  285. }
  286. -(void)testOrientationTabsController_portraitAndLandscape {
  287. NSArray* supportedOrientations = @[@"portrait", @"landscape"];
  288. self.options.orientation = supportedOrientations;
  289. __unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
  290. NSMutableArray* controllers = [NSMutableArray new];
  291. [controllers addObject:self.uut];
  292. [vc setViewControllers:controllers];
  293. [self.uut viewWillAppear:false];
  294. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
  295. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  296. }
  297. -(void)testOrientationTabsController_all {
  298. NSArray* supportedOrientations = @[@"all"];
  299. self.options.orientation = supportedOrientations;
  300. __unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
  301. NSMutableArray* controllers = [NSMutableArray new];
  302. [controllers addObject:self.uut];
  303. [vc setViewControllers:controllers];
  304. [self.uut viewWillAppear:false];
  305. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
  306. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  307. }
  308. -(void)testRightButtonsWithTitle_withoutStyle {
  309. self.options.topBar.rightButtons = @[@{@"id": @"testId", @"title": @"test"}];
  310. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  311. [self.uut viewWillAppear:false];
  312. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
  313. NSString* expectedButtonId = @"testId";
  314. NSString* expectedTitle = @"test";
  315. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  316. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  317. XCTAssertTrue(button.enabled);
  318. }
  319. -(void)testRightButtonsWithTitle_withStyle {
  320. NSNumber* inputColor = @(0xFFFF0000);
  321. self.options.topBar.rightButtons = @[@{@"id": @"testId", @"title": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
  322. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  323. [self.uut viewWillAppear:false];
  324. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
  325. NSString* expectedButtonId = @"testId";
  326. NSString* expectedTitle = @"test";
  327. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  328. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  329. XCTAssertFalse(button.enabled);
  330. //TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
  331. }
  332. -(void)testLeftButtonsWithTitle_withoutStyle {
  333. self.options.topBar.leftButtons = @[@{@"id": @"testId", @"title": @"test"}];
  334. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  335. [self.uut viewWillAppear:false];
  336. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
  337. NSString* expectedButtonId = @"testId";
  338. NSString* expectedTitle = @"test";
  339. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  340. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  341. XCTAssertTrue(button.enabled);
  342. }
  343. -(void)testLeftButtonsWithTitle_withStyle {
  344. NSNumber* inputColor = @(0xFFFF0000);
  345. self.options.topBar.leftButtons = @[@{@"id": @"testId", @"title": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
  346. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  347. [self.uut viewWillAppear:false];
  348. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
  349. NSString* expectedButtonId = @"testId";
  350. NSString* expectedTitle = @"test";
  351. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  352. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  353. XCTAssertFalse(button.enabled);
  354. //TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
  355. }
  356. -(void)testTopBarNoBorderOn {
  357. NSNumber* topBarNoBorderInput = @(1);
  358. self.options.topBar.noBorder = topBarNoBorderInput;
  359. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  360. [self.uut viewWillAppear:false];
  361. XCTAssertNotNil(self.uut.navigationController.navigationBar.shadowImage);
  362. }
  363. -(void)testTopBarNoBorderOff {
  364. NSNumber* topBarNoBorderInput = @(0);
  365. self.options.topBar.noBorder = topBarNoBorderInput;
  366. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  367. [self.uut viewWillAppear:false];
  368. XCTAssertNil(self.uut.navigationController.navigationBar.shadowImage);
  369. }
  370. -(void)testStatusBarBlurOn {
  371. NSNumber* statusBarBlurInput = @(1);
  372. self.options.statusBarBlur = statusBarBlurInput;
  373. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  374. [self.uut viewWillAppear:false];
  375. XCTAssertNotNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  376. }
  377. -(void)testStatusBarBlurOff {
  378. NSNumber* statusBarBlurInput = @(0);
  379. self.options.statusBarBlur = statusBarBlurInput;
  380. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  381. [self.uut viewWillAppear:false];
  382. XCTAssertNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  383. }
  384. - (void)testTabBarHidden_default {
  385. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  386. [self.uut viewWillAppear:false];
  387. XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
  388. }
  389. - (void)testTabBarHidden_true {
  390. self.options.bottomTabs.visible = @(0);
  391. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  392. [self.uut viewWillAppear:false];
  393. XCTAssertTrue([self.uut hidesBottomBarWhenPushed]);
  394. }
  395. - (void)testTabBarHidden_false {
  396. self.options.bottomTabs.visible = @(1);
  397. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  398. [self.uut viewWillAppear:false];
  399. XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
  400. }
  401. -(void)testTopBarBlur_default {
  402. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  403. [self.uut viewWillAppear:false];
  404. XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  405. }
  406. -(void)testTopBarLargeTitle_default {
  407. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  408. [self.uut viewWillAppear:false];
  409. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeNever);
  410. }
  411. -(void)testTopBarLargeTitle_true {
  412. self.options.topBar.largeTitle = @(1);
  413. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  414. [self.uut viewWillAppear:false];
  415. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeAlways);
  416. }
  417. -(void)testTopBarLargeTitle_false {
  418. self.options.topBar.largeTitle = @(0);
  419. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  420. [self.uut viewWillAppear:false];
  421. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeNever);
  422. }
  423. -(void)testTopBarBlur_false {
  424. NSNumber* topBarBlurInput = @(0);
  425. self.options.topBar.blur = topBarBlurInput;
  426. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  427. [self.uut viewWillAppear:false];
  428. XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  429. }
  430. -(void)testTopBarBlur_true {
  431. NSNumber* topBarBlurInput = @(1);
  432. self.options.topBar.blur = topBarBlurInput;
  433. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  434. [self.uut viewWillAppear:false];
  435. XCTAssertNotNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  436. }
  437. -(void)testBackgroundImage {
  438. UIImage* backgroundImage = [[UIImage alloc] init];
  439. self.options.backgroundImage = backgroundImage;
  440. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  441. [self.uut viewWillAppear:false];
  442. XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:backgroundImage]);
  443. }
  444. -(void)testRootBackgroundImage {
  445. UIImage* rootBackgroundImage = [[UIImage alloc] init];
  446. self.options.rootBackgroundImage = rootBackgroundImage;
  447. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  448. [self.uut viewWillAppear:false];
  449. XCTAssertTrue([[(UIImageView*)self.uut.navigationController.view.subviews[0] image] isEqual:rootBackgroundImage]);
  450. }
  451. -(void)testTopBarDrawUnder_true {
  452. self.options.topBar.drawBehind = @(1);
  453. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  454. [self.uut viewWillAppear:false];
  455. XCTAssertTrue(self.uut.edgesForExtendedLayout & UIRectEdgeTop);
  456. }
  457. -(void)testTopBarDrawUnder_false {
  458. self.options.topBar.drawBehind = @(0);
  459. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  460. [self.uut viewWillAppear:false];
  461. XCTAssertFalse(self.uut.edgesForExtendedLayout & UIRectEdgeTop);
  462. }
  463. -(void)testBottomTabsDrawUnder_true {
  464. self.options.bottomTabs.drawBehind = @(1);
  465. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  466. [self.uut viewWillAppear:false];
  467. XCTAssertTrue(self.uut.edgesForExtendedLayout & UIRectEdgeBottom);
  468. }
  469. -(void)testBottomTabsDrawUnder_false {
  470. self.options.bottomTabs.drawBehind = @(0);
  471. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  472. [self.uut viewWillAppear:false];
  473. XCTAssertFalse(self.uut.edgesForExtendedLayout & UIRectEdgeBottom);
  474. }
  475. #pragma mark BottomTabs
  476. - (void)testTabBarTranslucent_default {
  477. [self.uut embedInTabBarController];
  478. XCTAssertFalse(self.uut.tabBarController.tabBar.translucent);
  479. }
  480. - (void)testTabBarTranslucent_true {
  481. self.options.bottomTabs.translucent = @(1);
  482. [self.uut embedInTabBarController];
  483. XCTAssertTrue(self.uut.tabBarController.tabBar.translucent);
  484. }
  485. - (void)testTabBarTranslucent_false {
  486. self.options.bottomTabs.translucent = @(0);
  487. [self.uut embedInTabBarController];
  488. XCTAssertFalse(self.uut.tabBarController.tabBar.translucent);
  489. }
  490. - (void)testTabBarHideShadow_default {
  491. [self.uut embedInTabBarController];
  492. XCTAssertFalse(self.uut.tabBarController.tabBar.clipsToBounds);
  493. }
  494. - (void)testTabBarHideShadow_true {
  495. self.options.bottomTabs.hideShadow = @(1);
  496. [self.uut embedInTabBarController];
  497. XCTAssertTrue(self.uut.tabBarController.tabBar.clipsToBounds);
  498. }
  499. - (void)testTabBarHideShadow_false {
  500. self.options.bottomTabs.hideShadow = @(0);
  501. [self.uut embedInTabBarController];
  502. XCTAssertFalse(self.uut.tabBarController.tabBar.clipsToBounds);
  503. }
  504. - (void)testTabBarBackgroundColor {
  505. self.options.bottomTabs.backgroundColor = @(0xFFFF0000);
  506. [self.uut embedInTabBarController];
  507. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  508. XCTAssertTrue([self.uut.tabBarController.tabBar.barTintColor isEqual:expectedColor]);
  509. }
  510. -(void)testTabBarSelectedColor_validColor{
  511. NSNumber* inputColor = @(0xFFFF0000);
  512. self.options.bottomTabs.tabColor = inputColor;
  513. [self.uut embedInTabBarController];
  514. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  515. XCTAssertTrue([self.uut.tabBarController.tabBar.unselectedItemTintColor isEqual:expectedColor]);
  516. }
  517. -(void)testTabBarUnselectedColor_validColor{
  518. NSNumber* inputColor = @(0xFFFF0000);
  519. self.options.bottomTabs.selectedTabColor = inputColor;
  520. [self.uut embedInTabBarController];
  521. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  522. XCTAssertTrue([self.uut.tabBarController.tabBar.tintColor isEqual:expectedColor]);
  523. }
  524. -(void)testTabBarTextFontFamily_validFont{
  525. NSString* inputFont = @"HelveticaNeue";
  526. self.options.bottomTabs.fontFamily = inputFont;
  527. [self.uut embedInTabBarController];
  528. UIFont* expectedFont = [UIFont fontWithName:inputFont size:10];
  529. NSDictionary* attributes = [self.uut.tabBarController.tabBar.items.firstObject titleTextAttributesForState:UIControlStateNormal];
  530. XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  531. }
  532. -(void)testTabBarTextFontSize_withoutTextFontFamily_withoutTextColor {
  533. self.options.bottomTabs.fontSize = @(15);
  534. [self.uut embedInTabBarController];
  535. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  536. NSDictionary* attributes = [self.uut.tabBarController.tabBar.items.firstObject titleTextAttributesForState:UIControlStateNormal];
  537. XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  538. }
  539. -(void)testTabBarTextFontSize_withoutTextFontFamily {
  540. self.options.bottomTabs.fontSize = @(15);
  541. [self.uut embedInTabBarController];
  542. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  543. NSDictionary* attributes = [self.uut.tabBarController.tabBar.items.firstObject titleTextAttributesForState:UIControlStateNormal];
  544. XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  545. }
  546. -(void)testTabBarTextFontSize_withTextFontFamily_withTextColor {
  547. NSString* inputFont = @"HelveticaNeue";
  548. self.options.bottomTabs.fontSize = @(15);
  549. self.options.bottomTabs.fontFamily = inputFont;
  550. [self.uut embedInTabBarController];
  551. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  552. NSDictionary* attributes = [self.uut.tabBarController.tabBar.items.firstObject titleTextAttributesForState:UIControlStateNormal];
  553. XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  554. }
  555. -(void)testTabBarTextFontSize_withTextFontFamily_withoutTextColor {
  556. NSString* inputFont = @"HelveticaNeue";
  557. self.options.bottomTabs.fontSize = @(15);
  558. self.options.bottomTabs.fontFamily = inputFont;
  559. [self.uut embedInTabBarController];
  560. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  561. NSDictionary* attributes = [self.uut.tabBarController.tabBar.items.firstObject titleTextAttributesForState:UIControlStateNormal];
  562. XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  563. }
  564. @end