react-native-navigation的迁移库

RNNRootViewControllerTest.m 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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 = [[Color alloc] initWithValue:[RCTConvert UIColor: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 = [[Color alloc] initWithValue:[RCTConvert UIColor: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 = [[Bool alloc] initWithValue:@(0)];
  62. [self.uut viewWillAppear:false];
  63. XCTAssertTrue([self.uut prefersStatusBarHidden]);
  64. }
  65. - (void)testStatusBarVisible_true {
  66. self.options.statusBar.visible = [[Bool alloc] initWithValue:@(1)];
  67. [self.uut viewWillAppear:false];
  68. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  69. }
  70. - (void)testStatusBarHideWithTopBar_false {
  71. self.options.statusBar.hideWithTopBar = [[Bool alloc] initWithValue:@(0)];
  72. self.options.topBar.visible = [[Bool alloc] initWithValue:@(0)];
  73. [self.uut viewWillAppear:false];
  74. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  75. }
  76. - (void)testStatusBarHideWithTopBar_true {
  77. self.options.statusBar.hideWithTopBar = [[Bool alloc] initWithValue:@(1)];
  78. self.options.topBar.visible = [[Bool alloc] initWithValue:@(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 = [[Text alloc] initWithValue: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. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  95. self.options.topBar.title.color = [[Color alloc] initWithValue: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. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  103. self.options.layout.backgroundColor = [[Color alloc] initWithValue: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 = [[Text alloc] initWithValue: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 = [[Bool alloc] initWithValue: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 = [[Bool alloc] initWithValue: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 = [[Text alloc] initWithValue: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. UIColor* transparentColor = [RCTConvert UIColor:@(0x00000000)];
  144. self.options.topBar.background.color = [[Color alloc] initWithValue: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. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  153. __unused RNNNavigationController* nav = [self createNavigationController];
  154. self.options.topBar.background.color = [[Color alloc] initWithValue: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. //
  162. // XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeNever);
  163. //}
  164. -(void)testTopBarLargeTitle_true {
  165. self.options.topBar.largeTitle.visible = [[Bool alloc] initWithValue:@(1)];
  166. [self.uut viewWillAppear:false];
  167. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeAlways);
  168. }
  169. -(void)testTopBarLargeTitle_false {
  170. self.options.topBar.largeTitle.visible = [[Bool alloc] initWithValue:@(0)];
  171. [self.uut viewWillAppear:false];
  172. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeNever);
  173. }
  174. -(void)testTopBarLargeTitleFontSize_withoutTextFontFamily_withoutTextColor {
  175. NSNumber* topBarTextFontSizeInput = @(15);
  176. self.options.topBar.largeTitle.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  177. __unused RNNNavigationController* nav = [self createNavigationController];
  178. [self.uut viewWillAppear:false];
  179. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  180. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  181. }
  182. -(void)testTopBarLargeTitleFontSize_withoutTextFontFamily_withTextColor {
  183. NSNumber* topBarTextFontSizeInput = @(15);
  184. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  185. self.options.topBar.largeTitle.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  186. self.options.topBar.largeTitle.color = [[Color alloc] initWithValue:inputColor];
  187. __unused RNNNavigationController* nav = [self createNavigationController];
  188. [self.uut viewWillAppear:false];
  189. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  190. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  191. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  192. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  193. }
  194. -(void)testTopBarLargeTitleFontSize_withTextFontFamily_withTextColor {
  195. NSNumber* topBarTextFontSizeInput = @(15);
  196. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  197. NSString* inputFont = @"HelveticaNeue";
  198. self.options.topBar.largeTitle.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  199. self.options.topBar.largeTitle.color = [[Color alloc] initWithValue:inputColor];
  200. self.options.topBar.largeTitle.fontFamily = [[Text alloc] initWithValue:inputFont];
  201. __unused RNNNavigationController* nav = [self createNavigationController];
  202. [self.uut viewWillAppear:false];
  203. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  204. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  205. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  206. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  207. }
  208. -(void)testTopBarLargeTitleFontSize_withTextFontFamily_withoutTextColor {
  209. NSNumber* topBarTextFontSizeInput = @(15);
  210. NSString* inputFont = @"HelveticaNeue";
  211. self.options.topBar.largeTitle.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  212. self.options.topBar.largeTitle.fontFamily = [[Text alloc] initWithValue:inputFont];
  213. __unused RNNNavigationController* nav = [self createNavigationController];
  214. [self.uut viewWillAppear:false];
  215. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  216. XCTAssertTrue([self.uut.navigationController.navigationBar.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  217. }
  218. -(void)testTopBarTextFontSize_withoutTextFontFamily_withoutTextColor {
  219. NSNumber* topBarTextFontSizeInput = @(15);
  220. self.options.topBar.title.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  221. __unused RNNNavigationController* nav = [self createNavigationController];
  222. [self.uut viewWillAppear:false];
  223. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  224. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  225. }
  226. -(void)testTopBarTextFontSize_withoutTextFontFamily_withTextColor {
  227. NSNumber* topBarTextFontSizeInput = @(15);
  228. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  229. self.options.topBar.title.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  230. self.options.topBar.title.color = [[Color alloc] initWithValue:inputColor];
  231. __unused RNNNavigationController* nav = [self createNavigationController];
  232. [self.uut viewWillAppear:false];
  233. UIFont* expectedFont = [UIFont systemFontOfSize:15];
  234. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  235. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  236. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  237. }
  238. -(void)testTopBarTextFontSize_withTextFontFamily_withTextColor {
  239. NSNumber* topBarTextFontSizeInput = @(15);
  240. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  241. NSString* inputFont = @"HelveticaNeue";
  242. self.options.topBar.title.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  243. self.options.topBar.title.color = [[Color alloc] initWithValue:inputColor];
  244. self.options.topBar.title.fontFamily = [[Text alloc] initWithValue:inputFont];
  245. __unused RNNNavigationController* nav = [self createNavigationController];
  246. [self.uut viewWillAppear:false];
  247. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  248. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  249. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  250. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  251. }
  252. -(void)testTopBarTextFontSize_withTextFontFamily_withoutTextColor {
  253. NSNumber* topBarTextFontSizeInput = @(15);
  254. NSString* inputFont = @"HelveticaNeue";
  255. self.options.topBar.title.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  256. self.options.topBar.title.fontFamily = [[Text alloc] initWithValue:inputFont];
  257. __unused RNNNavigationController* nav = [self createNavigationController];
  258. [self.uut viewWillAppear:false];
  259. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  260. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  261. }
  262. // TODO: Currently not passing
  263. -(void)testTopBarTextFontFamily_invalidFont{
  264. NSString* inputFont = @"HelveticaNeueeeee";
  265. __unused RNNNavigationController* nav = [self createNavigationController];
  266. self.options.topBar.title.fontFamily = [[Text alloc] initWithValue:inputFont];
  267. // XCTAssertThrows([self.uut viewWillAppear:false]);
  268. }
  269. -(void)testOrientation_portrait {
  270. NSArray* supportedOrientations = @[@"portrait"];
  271. self.options.layout.orientation = supportedOrientations;
  272. __unused RNNNavigationController* nav = [self createNavigationController];
  273. [self.uut viewWillAppear:false];
  274. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
  275. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  276. }
  277. -(void)testOrientation_portraitString {
  278. NSString* supportedOrientation = @"portrait";
  279. self.options.layout.orientation = supportedOrientation;
  280. __unused RNNNavigationController* nav = [self createNavigationController];
  281. [self.uut viewWillAppear:false];
  282. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait);
  283. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  284. }
  285. -(void)testOrientation_portraitAndLandscape {
  286. NSArray* supportedOrientations = @[@"portrait", @"landscape"];
  287. self.options.layout.orientation = supportedOrientations;
  288. __unused RNNNavigationController* nav = [self createNavigationController];
  289. [self.uut viewWillAppear:false];
  290. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
  291. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  292. }
  293. -(void)testOrientation_all {
  294. NSArray* supportedOrientations = @[@"all"];
  295. self.options.layout.orientation = supportedOrientations;
  296. __unused RNNNavigationController* nav = [self createNavigationController];
  297. [self.uut viewWillAppear:false];
  298. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
  299. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  300. }
  301. -(void)testOrientation_default {
  302. NSString* supportedOrientations = @"default";
  303. self.options.layout.orientation = supportedOrientations;
  304. __unused RNNNavigationController* nav = [self createNavigationController];
  305. [self.uut viewWillAppear:false];
  306. UIInterfaceOrientationMask expectedOrientation = [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
  307. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  308. }
  309. -(void)testOrientationTabsController_portrait {
  310. NSArray* supportedOrientations = @[@"portrait"];
  311. self.options.layout.orientation = supportedOrientations;
  312. __unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
  313. NSMutableArray* controllers = [NSMutableArray new];
  314. [controllers addObject:self.uut];
  315. [vc setViewControllers:controllers];
  316. [self.uut viewWillAppear:false];
  317. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
  318. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  319. }
  320. -(void)testOrientationTabsController_portraitAndLandscape {
  321. NSArray* supportedOrientations = @[@"portrait", @"landscape"];
  322. self.options.layout.orientation = supportedOrientations;
  323. __unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
  324. NSMutableArray* controllers = [NSMutableArray new];
  325. [controllers addObject:self.uut];
  326. [vc setViewControllers:controllers];
  327. [self.uut viewWillAppear:false];
  328. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
  329. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  330. }
  331. -(void)testOrientationTabsController_all {
  332. NSArray* supportedOrientations = @[@"all"];
  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 = UIInterfaceOrientationMaskAll;
  340. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  341. }
  342. -(void)testRightButtonsWithTitle_withoutStyle {
  343. self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test"}];
  344. __unused RNNNavigationController* nav = [self createNavigationController];
  345. [self.uut viewWillAppear:false];
  346. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
  347. NSString* expectedButtonId = @"testId";
  348. NSString* expectedTitle = @"test";
  349. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  350. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  351. XCTAssertTrue(button.enabled);
  352. }
  353. -(void)testRightButtonsWithTitle_withStyle {
  354. NSNumber* inputColor = @(0xFFFF0000);
  355. self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
  356. __unused RNNNavigationController* nav = [self createNavigationController];
  357. [self.uut viewWillAppear:false];
  358. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
  359. NSString* expectedButtonId = @"testId";
  360. NSString* expectedTitle = @"test";
  361. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  362. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  363. XCTAssertFalse(button.enabled);
  364. //TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
  365. }
  366. -(void)testLeftButtonsWithTitle_withoutStyle {
  367. self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test"}];
  368. __unused RNNNavigationController* nav = [self createNavigationController];
  369. [self.uut viewWillAppear:false];
  370. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
  371. NSString* expectedButtonId = @"testId";
  372. NSString* expectedTitle = @"test";
  373. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  374. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  375. XCTAssertTrue(button.enabled);
  376. }
  377. -(void)testLeftButtonsWithTitle_withStyle {
  378. NSNumber* inputColor = @(0xFFFF0000);
  379. self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
  380. __unused RNNNavigationController* nav = [self createNavigationController];
  381. [self.uut viewWillAppear:false];
  382. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
  383. NSString* expectedButtonId = @"testId";
  384. NSString* expectedTitle = @"test";
  385. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  386. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  387. XCTAssertFalse(button.enabled);
  388. //TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
  389. }
  390. -(void)testTopBarNoBorderOn {
  391. NSNumber* topBarNoBorderInput = @(1);
  392. self.options.topBar.noBorder = [[Bool alloc] initWithValue:topBarNoBorderInput];
  393. __unused RNNNavigationController* nav = [self createNavigationController];
  394. [self.uut viewWillAppear:false];
  395. XCTAssertNotNil(self.uut.navigationController.navigationBar.shadowImage);
  396. }
  397. -(void)testTopBarNoBorderOff {
  398. NSNumber* topBarNoBorderInput = @(0);
  399. self.options.topBar.noBorder = [[Bool alloc] initWithValue:topBarNoBorderInput];
  400. __unused RNNNavigationController* nav = [self createNavigationController];
  401. [self.uut viewWillAppear:false];
  402. XCTAssertNil(self.uut.navigationController.navigationBar.shadowImage);
  403. }
  404. -(void)testStatusBarBlurOn {
  405. NSNumber* statusBarBlurInput = @(1);
  406. self.options.statusBar.blur = [[Bool alloc] initWithValue:statusBarBlurInput];
  407. [self.uut viewWillAppear:false];
  408. XCTAssertNotNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  409. }
  410. -(void)testStatusBarBlurOff {
  411. NSNumber* statusBarBlurInput = @(0);
  412. self.options.statusBar.blur = [[Bool alloc] initWithValue:statusBarBlurInput];
  413. [self.uut viewWillAppear:false];
  414. XCTAssertNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  415. }
  416. - (void)testTabBarHidden_default {
  417. [self.uut viewWillAppear:false];
  418. XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
  419. }
  420. - (void)testTabBarHidden_false {
  421. self.options.bottomTabs.visible = [[Bool alloc] initWithValue:@(1)];
  422. [self.uut viewWillAppear:false];
  423. XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
  424. }
  425. -(void)testTopBarBlur_default {
  426. __unused RNNNavigationController* nav = [self createNavigationController];
  427. [self.uut viewWillAppear:false];
  428. XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  429. }
  430. -(void)testTopBarBlur_false {
  431. NSNumber* topBarBlurInput = @(0);
  432. self.options.topBar.background.blur = [[Bool alloc] initWithValue:topBarBlurInput];
  433. __unused RNNNavigationController* nav = [self createNavigationController];
  434. [self.uut viewWillAppear:false];
  435. XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  436. }
  437. -(void)testTopBarBlur_true {
  438. NSNumber* topBarBlurInput = @(1);
  439. self.options.topBar.background.blur = [[Bool alloc] initWithValue:topBarBlurInput];
  440. __unused RNNNavigationController* nav = [self createNavigationController];
  441. [self.uut viewWillAppear:false];
  442. XCTAssertNotNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  443. }
  444. //-(void)testBackgroundImage {
  445. // UIImage* backgroundImage = [[UIImage alloc] init];
  446. // self.options.backgroundImage = backgroundImage;
  447. // [self.uut viewWillAppear:false];
  448. //
  449. // XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:backgroundImage]);
  450. //}
  451. #pragma mark BottomTabs
  452. - (RNNNavigationController *)createNavigationController {
  453. RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[self.uut] options:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:[[RNNNavigationControllerPresenter alloc] init]];
  454. return nav;
  455. }
  456. @end