react-native-navigation的迁移库

RNNRootViewControllerTest.m 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import <ReactNativeNavigation/RNNComponentViewController.h>
  4. #import "RNNReactRootViewCreator.h"
  5. #import "RNNTestRootViewCreator.h"
  6. #import <React/RCTConvert.h>
  7. #import "RNNNavigationOptions.h"
  8. #import "RNNStackController.h"
  9. #import "RNNBottomTabsController.h"
  10. #import "RNNUIBarButtonItem.h"
  11. #import "RNNBottomTabsController+Helpers.h"
  12. @interface RNNComponentViewController (EmbedInTabBar)
  13. - (void)embedInTabBarController;
  14. @end
  15. @implementation RNNComponentViewController (EmbedInTabBar)
  16. - (void)embedInTabBarController {
  17. RNNBottomTabsController* tabVC = [[RNNBottomTabsController alloc] init];
  18. tabVC.viewControllers = @[self];
  19. [self viewWillAppear:false];
  20. }
  21. @end
  22. @interface RNNRootViewControllerTest : XCTestCase
  23. @property (nonatomic, strong) id<RNNComponentViewCreator> creator;
  24. @property (nonatomic, strong) NSString* pageName;
  25. @property (nonatomic, strong) NSString* componentId;
  26. @property (nonatomic, strong) id emitter;
  27. @property (nonatomic, strong) RNNNavigationOptions* options;
  28. @property (nonatomic, strong) RNNLayoutInfo* layoutInfo;
  29. @property (nonatomic, strong) RNNComponentViewController* uut;
  30. @end
  31. @implementation RNNRootViewControllerTest
  32. - (void)setUp {
  33. [super setUp];
  34. self.creator = [[RNNTestRootViewCreator alloc] init];
  35. self.pageName = @"somename";
  36. self.componentId = @"cntId";
  37. self.emitter = nil;
  38. self.options = [[RNNNavigationOptions alloc] initWithDict:@{}];
  39. RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
  40. layoutInfo.componentId = self.componentId;
  41. layoutInfo.name = self.pageName;
  42. id presenter = [OCMockObject partialMockForObject:[[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil]];
  43. self.uut = [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:self.creator eventEmitter:self.emitter presenter:presenter options:self.options defaultOptions:nil];
  44. }
  45. -(void)testTopBarBackgroundColor_validColor{
  46. NSNumber* inputColor = @(0xFFFF0000);
  47. self.options.topBar.background.color = [[Color alloc] initWithValue:[RCTConvert UIColor:inputColor]];
  48. __unused RNNStackController* nav = [self createNavigationController];
  49. [self.uut viewWillAppear:false];
  50. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  51. XCTAssertTrue([self.uut.navigationController.navigationBar.barTintColor isEqual:expectedColor]);
  52. }
  53. -(void)testTopBarBackgroundColorWithoutNavigationController{
  54. NSNumber* inputColor = @(0xFFFF0000);
  55. self.options.topBar.background.color = [[Color alloc] initWithValue:[RCTConvert UIColor:inputColor]];
  56. XCTAssertNoThrow([self.uut viewWillAppear:false]);
  57. }
  58. - (void)testStatusBarHidden_default {
  59. [self.uut viewWillAppear:false];
  60. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  61. }
  62. - (void)testStatusBarVisible_false {
  63. self.options.statusBar.visible = [[Bool alloc] initWithValue:@(0)];
  64. [self.uut viewWillAppear:false];
  65. XCTAssertTrue([self.uut prefersStatusBarHidden]);
  66. }
  67. - (void)testStatusBarVisible_true {
  68. self.options.statusBar.visible = [[Bool alloc] initWithValue:@(1)];
  69. [self.uut viewWillAppear:false];
  70. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  71. }
  72. - (void)testStatusBarHideWithTopBar_false {
  73. self.options.statusBar.hideWithTopBar = [[Bool alloc] initWithValue:@(0)];
  74. self.options.topBar.visible = [[Bool alloc] initWithValue:@(0)];
  75. [self.uut viewWillAppear:false];
  76. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  77. }
  78. - (void)testStatusBarHideWithTopBar_true {
  79. self.options.statusBar.hideWithTopBar = [[Bool alloc] initWithValue:@(1)];
  80. self.options.topBar.visible = [[Bool alloc] initWithValue:@(0)];
  81. __unused RNNStackController* nav = [self createNavigationController];
  82. [self.uut viewWillAppear:false];
  83. XCTAssertTrue([self.uut prefersStatusBarHidden]);
  84. }
  85. -(void)testTitle_string{
  86. NSString* title =@"some title";
  87. self.options.topBar.title.text = [[Text alloc] initWithValue:title];
  88. [self.uut viewWillAppear:false];
  89. XCTAssertTrue([self.uut.navigationItem.title isEqual:title]);
  90. }
  91. -(void)testTitle_default{
  92. [self.uut viewWillAppear:false];
  93. XCTAssertNil(self.uut.navigationItem.title);
  94. }
  95. -(void)testTopBarTextColor_validColor{
  96. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  97. self.options.topBar.title.color = [[Color alloc] initWithValue:inputColor];
  98. __unused RNNStackController* nav = [self createNavigationController];
  99. [self.uut viewWillAppear:false];
  100. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  101. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  102. }
  103. -(void)testbackgroundColor_validColor{
  104. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  105. self.options.layout.componentBackgroundColor = [[Color alloc] initWithValue:inputColor];
  106. [self.uut viewWillAppear:false];
  107. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  108. XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);
  109. }
  110. -(void)testTopBarTextFontFamily_validFont{
  111. NSString* inputFont = @"HelveticaNeue";
  112. __unused RNNStackController* nav = [self createNavigationController];
  113. self.options.topBar.title.fontFamily = [[Text alloc] initWithValue:inputFont];
  114. [self.uut viewWillAppear:false];
  115. UIFont* expectedFont = [UIFont fontWithName:inputFont size:17];
  116. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  117. }
  118. -(void)testTopBarHideOnScroll_true {
  119. NSNumber* hideOnScrollInput = @(1);
  120. __unused RNNStackController* nav = [self createNavigationController];
  121. self.options.topBar.hideOnScroll = [[Bool alloc] initWithValue:hideOnScrollInput];;
  122. [self.uut viewWillAppear:false];
  123. XCTAssertTrue(self.uut.navigationController.hidesBarsOnSwipe);
  124. }
  125. -(void)testTopBarTranslucent {
  126. NSNumber* topBarTranslucentInput = @(0);
  127. self.options.topBar.background.translucent = [[Bool alloc] initWithValue:topBarTranslucentInput];
  128. __unused RNNStackController* nav = [self createNavigationController];
  129. [self.uut viewWillAppear:false];
  130. XCTAssertFalse(self.uut.navigationController.navigationBar.translucent);
  131. }
  132. -(void)testTabBadge {
  133. NSString* tabBadgeInput = @"5";
  134. self.options.bottomTab.badge = [[Text alloc] initWithValue:tabBadgeInput];
  135. NSMutableArray* controllers = [NSMutableArray new];
  136. UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:@"A Tab" image:nil tag:1];
  137. [self.uut setTabBarItem:item];
  138. [controllers addObject:self.uut];
  139. __unused RNNBottomTabsController* vc = [RNNBottomTabsController createWithChildren:controllers];
  140. [self.uut willMoveToParentViewController:vc];
  141. XCTAssertTrue([self.uut.tabBarItem.badgeValue isEqualToString:tabBadgeInput]);
  142. }
  143. -(void)testTopBarTransparent_BOOL_True {
  144. UIColor* transparentColor = [RCTConvert UIColor:@(0x00000000)];
  145. self.options.topBar.background.color = [[Color alloc] initWithValue:transparentColor];
  146. __unused RNNStackController* nav = [self createNavigationController];
  147. [self.uut viewWillAppear:false];
  148. nav.navigationBar.barTintColor = UIColor.clearColor;
  149. XCTAssertTrue([nav.navigationBar.barTintColor isEqual:UIColor.clearColor]);
  150. XCTAssertTrue(nav.navigationBar.isTranslucent);
  151. }
  152. -(void)testTopBarTransparent_BOOL_false {
  153. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  154. __unused RNNStackController* nav = [self createNavigationController];
  155. self.options.topBar.background.color = [[Color alloc] initWithValue:inputColor];
  156. [self.uut viewWillAppear:false];
  157. XCTAssertFalse(nav.navigationBar.isTranslucent);
  158. XCTAssertFalse([nav.navigationBar.barTintColor isEqual:UIColor.clearColor]);
  159. }
  160. -(void)testTopBarLargeTitle_default {
  161. [self.uut viewWillAppear:false];
  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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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 RNNStackController* 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. NSMutableArray* controllers = [[NSMutableArray alloc] initWithArray:@[self.uut]];
  313. __unused RNNBottomTabsController* vc = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[RNNComponentPresenter new] eventEmitter:nil childViewControllers:controllers];
  314. [self.uut viewWillAppear:false];
  315. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
  316. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  317. }
  318. -(void)testOrientationTabsController_portraitAndLandscape {
  319. NSArray* supportedOrientations = @[@"portrait", @"landscape"];
  320. self.options.layout.orientation = supportedOrientations;
  321. NSMutableArray* controllers = [[NSMutableArray alloc] initWithArray:@[self.uut]];
  322. __unused RNNBottomTabsController* vc = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[RNNComponentPresenter new] eventEmitter:nil childViewControllers:controllers];
  323. [self.uut viewWillAppear:false];
  324. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
  325. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  326. }
  327. -(void)testOrientationTabsController_all {
  328. NSArray* supportedOrientations = @[@"all"];
  329. self.options.layout.orientation = supportedOrientations;
  330. NSMutableArray* controllers = [[NSMutableArray alloc] initWithArray:@[self.uut]];
  331. __unused RNNBottomTabsController* vc = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[RNNComponentPresenter new] eventEmitter:nil childViewControllers:controllers];
  332. [self.uut viewWillAppear:false];
  333. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
  334. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  335. }
  336. -(void)testRightButtonsWithTitle_withoutStyle {
  337. self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test"}];
  338. self.uut = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNComponentPresenter new] options:self.options defaultOptions:nil];
  339. RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
  340. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*) nav.topViewController.navigationItem.rightBarButtonItems[0];
  341. NSString* expectedButtonId = @"testId";
  342. NSString* expectedTitle = @"test";
  343. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  344. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  345. XCTAssertTrue(button.enabled);
  346. }
  347. -(void)testRightButtonsWithTitle_withStyle {
  348. NSNumber* inputColor = @(0xFFFF0000);
  349. self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
  350. self.uut = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNComponentPresenter new] options:self.options defaultOptions:nil];
  351. RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
  352. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
  353. NSString* expectedButtonId = @"testId";
  354. NSString* expectedTitle = @"test";
  355. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  356. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  357. XCTAssertFalse(button.enabled);
  358. //TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
  359. }
  360. -(void)testLeftButtonsWithTitle_withoutStyle {
  361. self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test"}];
  362. self.uut = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNComponentPresenter new] options:self.options defaultOptions:nil];
  363. RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
  364. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
  365. NSString* expectedButtonId = @"testId";
  366. NSString* expectedTitle = @"test";
  367. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  368. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  369. XCTAssertTrue(button.enabled);
  370. }
  371. -(void)testLeftButtonsWithTitle_withStyle {
  372. NSNumber* inputColor = @(0xFFFF0000);
  373. self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
  374. self.uut = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNComponentPresenter new] options:self.options defaultOptions:nil];
  375. RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
  376. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
  377. NSString* expectedButtonId = @"testId";
  378. NSString* expectedTitle = @"test";
  379. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  380. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  381. XCTAssertFalse(button.enabled);
  382. //TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
  383. }
  384. -(void)testTopBarNoBorderOn {
  385. NSNumber* topBarNoBorderInput = @(1);
  386. self.options.topBar.noBorder = [[Bool alloc] initWithValue:topBarNoBorderInput];
  387. __unused RNNStackController* nav = [self createNavigationController];
  388. [self.uut viewWillAppear:false];
  389. XCTAssertNotNil(self.uut.navigationController.navigationBar.shadowImage);
  390. }
  391. -(void)testTopBarNoBorderOff {
  392. NSNumber* topBarNoBorderInput = @(0);
  393. self.options.topBar.noBorder = [[Bool alloc] initWithValue:topBarNoBorderInput];
  394. __unused RNNStackController* nav = [self createNavigationController];
  395. [self.uut viewWillAppear:false];
  396. XCTAssertNil(self.uut.navigationController.navigationBar.shadowImage);
  397. }
  398. -(void)testStatusBarBlurOn {
  399. NSNumber* statusBarBlurInput = @(1);
  400. self.options.statusBar.blur = [[Bool alloc] initWithValue:statusBarBlurInput];
  401. [self.uut viewWillAppear:false];
  402. XCTAssertNotNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  403. }
  404. -(void)testStatusBarBlurOff {
  405. NSNumber* statusBarBlurInput = @(0);
  406. self.options.statusBar.blur = [[Bool alloc] initWithValue:statusBarBlurInput];
  407. [self.uut viewWillAppear:false];
  408. XCTAssertNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  409. }
  410. - (void)testTabBarHidden_default {
  411. [self.uut viewWillAppear:false];
  412. XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
  413. }
  414. - (void)testTabBarHidden_false {
  415. self.options.bottomTabs.visible = [[Bool alloc] initWithValue:@(1)];
  416. [self.uut viewWillAppear:false];
  417. XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
  418. }
  419. -(void)testTopBarBlur_default {
  420. __unused RNNStackController* nav = [self createNavigationController];
  421. [self.uut viewWillAppear:false];
  422. XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  423. }
  424. -(void)testTopBarBlur_false {
  425. NSNumber* topBarBlurInput = @(0);
  426. self.options.topBar.background.blur = [[Bool alloc] initWithValue:topBarBlurInput];
  427. __unused RNNStackController* nav = [self createNavigationController];
  428. [self.uut viewWillAppear:false];
  429. XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  430. }
  431. -(void)testTopBarBlur_true {
  432. NSNumber* topBarBlurInput = @(1);
  433. self.options.topBar.background.blur = [[Bool alloc] initWithValue:topBarBlurInput];
  434. __unused RNNStackController* nav = [self createNavigationController];
  435. [self.uut viewWillAppear:false];
  436. XCTAssertNotNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  437. }
  438. -(void)testBackgroundImage {
  439. Image* backgroundImage = [[Image alloc] initWithValue:[[UIImage alloc] init]];
  440. self.options.backgroundImage = backgroundImage;
  441. [self.uut viewWillAppear:false];
  442. XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:backgroundImage.get]);
  443. }
  444. - (void)testMergeOptionsShouldCallPresenterMergeOptions {
  445. RNNNavigationOptions* newOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  446. [[(id) self.uut.presenter expect] mergeOptions:newOptions resolvedOptions:self.uut.options];
  447. [self.uut mergeOptions:newOptions];
  448. [(id)self.uut.presenter verify];
  449. }
  450. - (void)testOverrideOptions {
  451. RNNNavigationOptions* newOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  452. newOptions.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
  453. [self.uut overrideOptions:newOptions];
  454. XCTAssertEqual([UIColor redColor], self.uut.options.topBar.background.color.get);
  455. }
  456. #pragma mark BottomTabs
  457. - (RNNStackController *)createNavigationController {
  458. RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNStackPresenter alloc] init] eventEmitter:nil childViewControllers:@[self.uut]];
  459. return nav;
  460. }
  461. @end