react-native-navigation的迁移库

RNNRootViewControllerTest.m 26KB

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