react-native-navigation的迁移库

RNNRootViewControllerTest.m 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. @interface RNNComponentViewController (EmbedInTabBar)
  12. - (void)embedInTabBarController;
  13. @end
  14. @implementation RNNComponentViewController (EmbedInTabBar)
  15. - (void)embedInTabBarController {
  16. RNNBottomTabsController* tabVC = [[RNNBottomTabsController alloc] init];
  17. tabVC.viewControllers = @[self];
  18. [self viewWillAppear:false];
  19. }
  20. @end
  21. @interface RNNRootViewControllerTest : XCTestCase
  22. @property (nonatomic, strong) id<RNNComponentViewCreator> creator;
  23. @property (nonatomic, strong) NSString* pageName;
  24. @property (nonatomic, strong) NSString* componentId;
  25. @property (nonatomic, strong) id emitter;
  26. @property (nonatomic, strong) RNNNavigationOptions* options;
  27. @property (nonatomic, strong) RNNLayoutInfo* layoutInfo;
  28. @property (nonatomic, strong) RNNComponentViewController* uut;
  29. @end
  30. @implementation RNNRootViewControllerTest
  31. - (void)setUp {
  32. [super setUp];
  33. self.creator = [[RNNTestRootViewCreator alloc] init];
  34. self.pageName = @"somename";
  35. self.componentId = @"cntId";
  36. self.emitter = nil;
  37. self.options = [[RNNNavigationOptions alloc] initWithDict:@{}];
  38. RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
  39. layoutInfo.componentId = self.componentId;
  40. layoutInfo.name = self.pageName;
  41. id presenter = [OCMockObject partialMockForObject:[[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil]];
  42. self.uut = [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:self.creator eventEmitter:self.emitter presenter:presenter options:self.options defaultOptions:nil];
  43. }
  44. - (void)testTopBarBackgroundColor_validColor {
  45. NSNumber* inputColor = @(0xFFFF0000);
  46. self.options.topBar.background.color = [[Color alloc] initWithValue:[RCTConvert UIColor:inputColor]];
  47. __unused RNNStackController* nav = [self createNavigationController];
  48. [self.uut viewWillAppear:false];
  49. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  50. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.backgroundColor isEqual:expectedColor]);
  51. }
  52. - (void)testTopBarBackgroundColorWithoutNavigationController {
  53. NSNumber* inputColor = @(0xFFFF0000);
  54. self.options.topBar.background.color = [[Color alloc] initWithValue:[RCTConvert UIColor:inputColor]];
  55. XCTAssertNoThrow([self.uut viewWillAppear:false]);
  56. }
  57. - (void)testStatusBarHidden_default {
  58. [self.uut viewWillAppear:false];
  59. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  60. }
  61. - (void)testStatusBarVisible_false {
  62. self.options.statusBar.visible = [[Bool alloc] initWithValue:@(0)];
  63. [self.uut viewWillAppear:false];
  64. XCTAssertTrue([self.uut prefersStatusBarHidden]);
  65. }
  66. - (void)testStatusBarVisible_true {
  67. self.options.statusBar.visible = [[Bool alloc] initWithValue:@(1)];
  68. [self.uut viewWillAppear:false];
  69. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  70. }
  71. - (void)testStatusBarHideWithTopBar_false {
  72. self.options.statusBar.hideWithTopBar = [[Bool alloc] initWithValue:@(0)];
  73. self.options.topBar.visible = [[Bool alloc] initWithValue:@(0)];
  74. [self.uut viewWillAppear:false];
  75. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  76. }
  77. - (void)testStatusBarHideWithTopBar_true {
  78. self.options.statusBar.hideWithTopBar = [[Bool alloc] initWithValue:@(1)];
  79. self.options.topBar.visible = [[Bool alloc] initWithValue:@(0)];
  80. __unused RNNStackController* nav = [self createNavigationController];
  81. [self.uut viewWillAppear:false];
  82. XCTAssertTrue([self.uut prefersStatusBarHidden]);
  83. }
  84. - (void)testTitle_string {
  85. NSString* title =@"some title";
  86. self.options.topBar.title.text = [[Text alloc] initWithValue:title];
  87. [self.uut viewWillAppear:false];
  88. XCTAssertTrue([self.uut.navigationItem.title isEqual:title]);
  89. }
  90. - (void)testTitle_default{
  91. [self.uut viewWillAppear:false];
  92. XCTAssertNil(self.uut.navigationItem.title);
  93. }
  94. - (void)testTopBarTextColor_validColor{
  95. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  96. self.options.topBar.title.color = [[Color alloc] initWithValue:inputColor];
  97. __unused RNNStackController* nav = [self createNavigationController];
  98. [self.uut viewWillAppear:false];
  99. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  100. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  101. }
  102. - (void)testbackgroundColor_validColor{
  103. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  104. self.options.layout.backgroundColor = [[Color alloc] initWithValue: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)testTopBarTextFontFamily_validFont{
  110. NSString* inputFont = @"HelveticaNeue";
  111. __unused RNNStackController* nav = [self createNavigationController];
  112. self.options.topBar.title.fontFamily = [[Text alloc] initWithValue:inputFont];
  113. [self.uut viewWillAppear:false];
  114. UIFont* expectedFont = [UIFont fontWithName:inputFont size:17];
  115. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  116. }
  117. - (void)testTopBarHideOnScroll_true {
  118. NSNumber* hideOnScrollInput = @(1);
  119. __unused RNNStackController* nav = [self createNavigationController];
  120. self.options.topBar.hideOnScroll = [[Bool alloc] initWithValue:hideOnScrollInput];;
  121. [self.uut viewWillAppear:false];
  122. XCTAssertTrue(self.uut.navigationController.hidesBarsOnSwipe);
  123. }
  124. - (void)testTopBarTranslucent {
  125. NSNumber* topBarTranslucentInput = @(0);
  126. self.options.topBar.background.translucent = [[Bool alloc] initWithValue:topBarTranslucentInput];
  127. __unused RNNStackController* nav = [self createNavigationController];
  128. [self.uut viewWillAppear:false];
  129. XCTAssertTrue(CGColorEqualToColor(self.uut.navigationController.navigationBar.standardAppearance.shadowColor.CGColor, [UINavigationBarAppearance new].shadowColor.CGColor));
  130. XCTAssertTrue(CGColorEqualToColor(self.uut.navigationController.navigationBar.standardAppearance.backgroundColor.CGColor, UIColor.systemBackgroundColor.CGColor));
  131. }
  132. - (void)testTopBarTransparent {
  133. self.options.topBar.background.color = [[Color alloc] initWithValue:UIColor.clearColor];
  134. __unused RNNStackController* nav = [self createNavigationController];
  135. [self.uut viewWillAppear:false];
  136. XCTAssertNil(self.uut.navigationController.navigationBar.standardAppearance.backgroundColor);
  137. }
  138. - (void)testTabBadge {
  139. NSString* tabBadgeInput = @"5";
  140. self.options.bottomTab.badge = [[Text alloc] initWithValue:tabBadgeInput];
  141. __unused RNNBottomTabsController* vc = [[RNNBottomTabsController alloc] init];
  142. NSMutableArray* controllers = [NSMutableArray new];
  143. UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:@"A Tab" image:nil tag:1];
  144. [self.uut setTabBarItem:item];
  145. [controllers addObject:self.uut];
  146. [vc setViewControllers:controllers];
  147. [self.uut viewWillAppear:false];
  148. XCTAssertTrue([self.uut.tabBarItem.badgeValue isEqualToString:tabBadgeInput]);
  149. }
  150. - (void)testTopBarLargeTitle_default {
  151. [self.uut viewWillAppear:false];
  152. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeNever);
  153. }
  154. - (void)testTopBarLargeTitle_true {
  155. self.options.topBar.largeTitle.visible = [[Bool alloc] initWithValue:@(1)];
  156. [self.uut viewWillAppear:false];
  157. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeAlways);
  158. }
  159. - (void)testTopBarLargeTitle_false {
  160. self.options.topBar.largeTitle.visible = [[Bool alloc] initWithValue:@(0)];
  161. [self.uut viewWillAppear:false];
  162. XCTAssertEqual(self.uut.navigationItem.largeTitleDisplayMode, UINavigationItemLargeTitleDisplayModeNever);
  163. }
  164. - (void)testTopBarLargeTitleFontSize_withoutTextFontFamily_withoutTextColor {
  165. NSNumber* topBarTextFontSizeInput = @(15);
  166. self.options.topBar.largeTitle.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  167. __unused RNNStackController* nav = [self createNavigationController];
  168. UIFont* initialFont = self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"];
  169. [self.uut viewWillAppear:false];
  170. UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
  171. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  172. }
  173. - (void)testTopBarLargeTitleFontSize_withoutTextFontFamily_withTextColor {
  174. NSNumber* topBarTextFontSizeInput = @(15);
  175. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  176. self.options.topBar.largeTitle.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  177. self.options.topBar.largeTitle.color = [[Color alloc] initWithValue:inputColor];
  178. __unused RNNStackController* nav = [self createNavigationController];
  179. UIFont* initialFont = self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"];
  180. [self.uut viewWillAppear:false];
  181. UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
  182. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  183. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  184. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  185. }
  186. - (void)testTopBarLargeTitleFontSize_withTextFontFamily_withTextColor {
  187. NSNumber* topBarTextFontSizeInput = @(15);
  188. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  189. NSString* inputFont = @"HelveticaNeue";
  190. self.options.topBar.largeTitle.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  191. self.options.topBar.largeTitle.color = [[Color alloc] initWithValue:inputColor];
  192. self.options.topBar.largeTitle.fontFamily = [[Text alloc] initWithValue:inputFont];
  193. __unused RNNStackController* nav = [self createNavigationController];
  194. [self.uut viewWillAppear:false];
  195. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  196. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  197. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  198. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  199. }
  200. - (void)testTopBarLargeTitleFontSize_withTextFontFamily_withoutTextColor {
  201. NSNumber* topBarTextFontSizeInput = @(15);
  202. NSString* inputFont = @"HelveticaNeue";
  203. self.options.topBar.largeTitle.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  204. self.options.topBar.largeTitle.fontFamily = [[Text alloc] initWithValue:inputFont];
  205. __unused RNNStackController* nav = [self createNavigationController];
  206. [self.uut viewWillAppear:false];
  207. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  208. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  209. }
  210. - (void)testTopBarTextFontSize_withoutTextFontFamily_withoutTextColor {
  211. NSNumber* topBarTextFontSizeInput = @(15);
  212. self.options.topBar.title.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  213. __unused RNNStackController* nav = [self createNavigationController];
  214. UIFont* initialFont = self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"];
  215. [self.uut viewWillAppear:false];
  216. UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
  217. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  218. }
  219. - (void)testTopBarTextFontSize_withoutTextFontFamily_withTextColor {
  220. NSNumber* topBarTextFontSizeInput = @(15);
  221. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  222. self.options.topBar.title.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  223. self.options.topBar.title.color = [[Color alloc] initWithValue:inputColor];
  224. __unused RNNStackController* nav = [self createNavigationController];
  225. UIFont* initialFont = self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"];
  226. [self.uut viewWillAppear:false];
  227. UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
  228. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  229. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  230. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  231. }
  232. - (void)testTopBarTextFontSize_withTextFontFamily_withTextColor {
  233. NSNumber* topBarTextFontSizeInput = @(15);
  234. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  235. NSString* inputFont = @"HelveticaNeue";
  236. self.options.topBar.title.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  237. self.options.topBar.title.color = [[Color alloc] initWithValue:inputColor];
  238. self.options.topBar.title.fontFamily = [[Text alloc] initWithValue:inputFont];
  239. __unused RNNStackController* nav = [self createNavigationController];
  240. [self.uut viewWillAppear:false];
  241. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  242. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  243. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  244. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  245. }
  246. - (void)testTopBarTextFontSize_withTextFontFamily_withoutTextColor {
  247. NSNumber* topBarTextFontSizeInput = @(15);
  248. NSString* inputFont = @"HelveticaNeue";
  249. self.options.topBar.title.fontSize = [[Number alloc] initWithValue:topBarTextFontSizeInput];
  250. self.options.topBar.title.fontFamily = [[Text alloc] initWithValue:inputFont];
  251. __unused RNNStackController* nav = [self createNavigationController];
  252. [self.uut viewWillAppear:false];
  253. UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  254. XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
  255. }
  256. // TODO: Currently not passing
  257. - (void)testTopBarTextFontFamily_invalidFont{
  258. NSString* inputFont = @"HelveticaNeueeeee";
  259. __unused RNNStackController* nav = [self createNavigationController];
  260. self.options.topBar.title.fontFamily = [[Text alloc] initWithValue:inputFont];
  261. // XCTAssertThrows([self.uut viewWillAppear:false]);
  262. }
  263. - (void)testOrientation_portrait {
  264. NSArray* supportedOrientations = @[@"portrait"];
  265. self.options.layout.orientation = supportedOrientations;
  266. __unused RNNStackController* nav = [self createNavigationController];
  267. [self.uut viewWillAppear:false];
  268. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
  269. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  270. }
  271. - (void)testOrientation_portraitString {
  272. NSString* supportedOrientation = @"portrait";
  273. self.options.layout.orientation = supportedOrientation;
  274. __unused RNNStackController* nav = [self createNavigationController];
  275. [self.uut viewWillAppear:false];
  276. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait);
  277. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  278. }
  279. - (void)testOrientation_portraitAndLandscape {
  280. NSArray* supportedOrientations = @[@"portrait", @"landscape"];
  281. self.options.layout.orientation = supportedOrientations;
  282. __unused RNNStackController* nav = [self createNavigationController];
  283. [self.uut viewWillAppear:false];
  284. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
  285. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  286. }
  287. - (void)testOrientation_all {
  288. NSArray* supportedOrientations = @[@"all"];
  289. self.options.layout.orientation = supportedOrientations;
  290. __unused RNNStackController* nav = [self createNavigationController];
  291. [self.uut viewWillAppear:false];
  292. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
  293. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  294. }
  295. - (void)testOrientation_default {
  296. NSString* supportedOrientations = @"default";
  297. self.options.layout.orientation = supportedOrientations;
  298. __unused RNNStackController* nav = [self createNavigationController];
  299. [self.uut viewWillAppear:false];
  300. UIInterfaceOrientationMask expectedOrientation = [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
  301. XCTAssertTrue(self.uut.navigationController.supportedInterfaceOrientations == expectedOrientation);
  302. }
  303. - (void)testOrientationTabsController_portrait {
  304. NSArray* supportedOrientations = @[@"portrait"];
  305. self.options.layout.orientation = supportedOrientations;
  306. NSMutableArray* controllers = [[NSMutableArray alloc] initWithArray:@[self.uut]];
  307. __unused RNNBottomTabsController* vc = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[RNNComponentPresenter new] eventEmitter:nil childViewControllers:controllers];
  308. [self.uut viewWillAppear:false];
  309. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
  310. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  311. }
  312. - (void)testOrientationTabsController_portraitAndLandscape {
  313. NSArray* supportedOrientations = @[@"portrait", @"landscape"];
  314. self.options.layout.orientation = supportedOrientations;
  315. NSMutableArray* controllers = [[NSMutableArray alloc] initWithArray:@[self.uut]];
  316. __unused RNNBottomTabsController* vc = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[RNNComponentPresenter new] eventEmitter:nil childViewControllers:controllers];
  317. [self.uut viewWillAppear:false];
  318. UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
  319. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  320. }
  321. - (void)testOrientationTabsController_all {
  322. NSArray* supportedOrientations = @[@"all"];
  323. self.options.layout.orientation = supportedOrientations;
  324. NSMutableArray* controllers = [[NSMutableArray alloc] initWithArray:@[self.uut]];
  325. __unused RNNBottomTabsController* vc = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[RNNComponentPresenter new] eventEmitter:nil childViewControllers:controllers];
  326. [self.uut viewWillAppear:false];
  327. UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
  328. XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
  329. }
  330. - (void)testRightButtonsWithTitle_withoutStyle {
  331. self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test"}];
  332. self.uut = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNComponentPresenter new] options:self.options defaultOptions:nil];
  333. RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
  334. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*) nav.topViewController.navigationItem.rightBarButtonItems[0];
  335. NSString* expectedButtonId = @"testId";
  336. NSString* expectedTitle = @"test";
  337. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  338. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  339. XCTAssertTrue(button.enabled);
  340. }
  341. - (void)testRightButtonsWithTitle_withStyle {
  342. NSNumber* inputColor = @(0xFFFF0000);
  343. self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
  344. self.uut = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNComponentPresenter new] options:self.options defaultOptions:nil];
  345. RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
  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. XCTAssertFalse(button.enabled);
  352. //TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
  353. }
  354. - (void)testLeftButtonsWithTitle_withoutStyle {
  355. self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test"}];
  356. self.uut = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNComponentPresenter new] options:self.options defaultOptions:nil];
  357. RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
  358. RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
  359. NSString* expectedButtonId = @"testId";
  360. NSString* expectedTitle = @"test";
  361. XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
  362. XCTAssertTrue([button.title isEqualToString:expectedTitle]);
  363. XCTAssertTrue(button.enabled);
  364. }
  365. - (void)testLeftButtonsWithTitle_withStyle {
  366. NSNumber* inputColor = @(0xFFFF0000);
  367. self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
  368. self.uut = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNComponentPresenter new] options:self.options defaultOptions:nil];
  369. RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
  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. XCTAssertFalse(button.enabled);
  376. //TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
  377. }
  378. - (void)testTopBarNoBorderOn {
  379. NSNumber* topBarNoBorderInput = @(1);
  380. self.options.topBar.noBorder = [[Bool alloc] initWithValue:topBarNoBorderInput];
  381. __unused RNNStackController* nav = [self createNavigationController];
  382. [self.uut viewWillAppear:false];
  383. XCTAssertNil(self.uut.navigationController.navigationBar.standardAppearance.shadowColor);
  384. }
  385. - (void)testTopBarNoBorderOff {
  386. NSNumber* topBarNoBorderInput = @(0);
  387. self.options.topBar.noBorder = [[Bool alloc] initWithValue:topBarNoBorderInput];
  388. __unused RNNStackController* nav = [self createNavigationController];
  389. [self.uut viewWillAppear:false];
  390. XCTAssertTrue(CGColorEqualToColor(self.uut.navigationController.navigationBar.standardAppearance.shadowColor.CGColor, [UINavigationBarAppearance new].shadowColor.CGColor));
  391. }
  392. - (void)testStatusBarBlurOn {
  393. NSNumber* statusBarBlurInput = @(1);
  394. self.options.statusBar.blur = [[Bool alloc] initWithValue:statusBarBlurInput];
  395. [self.uut viewWillAppear:false];
  396. XCTAssertNotNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  397. }
  398. - (void)testStatusBarBlurOff {
  399. NSNumber* statusBarBlurInput = @(0);
  400. self.options.statusBar.blur = [[Bool alloc] initWithValue:statusBarBlurInput];
  401. [self.uut viewWillAppear:false];
  402. XCTAssertNil([self.uut.view viewWithTag:BLUR_STATUS_TAG]);
  403. }
  404. - (void)testTabBarHidden_default {
  405. [self.uut viewWillAppear:false];
  406. XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
  407. }
  408. - (void)testTabBarHidden_false {
  409. self.options.bottomTabs.visible = [[Bool alloc] initWithValue:@(1)];
  410. [self.uut viewWillAppear:false];
  411. XCTAssertFalse([self.uut hidesBottomBarWhenPushed]);
  412. }
  413. - (void)testTopBarBlur_default {
  414. __unused RNNStackController* nav = [self createNavigationController];
  415. [self.uut viewWillAppear:false];
  416. XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  417. }
  418. - (void)testTopBarBlur_false {
  419. NSNumber* topBarBlurInput = @(0);
  420. self.options.topBar.background.blur = [[Bool alloc] initWithValue:topBarBlurInput];
  421. __unused RNNStackController* nav = [self createNavigationController];
  422. [self.uut viewWillAppear:false];
  423. XCTAssertNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  424. }
  425. - (void)testTopBarBlur_true {
  426. NSNumber* topBarBlurInput = @(1);
  427. self.options.topBar.background.blur = [[Bool alloc] initWithValue:topBarBlurInput];
  428. __unused RNNStackController* nav = [self createNavigationController];
  429. [self.uut viewWillAppear:false];
  430. XCTAssertNotNil([self.uut.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]);
  431. }
  432. - (void)testBackgroundImage {
  433. Image* backgroundImage = [[Image alloc] initWithValue:[[UIImage alloc] init]];
  434. self.options.backgroundImage = backgroundImage;
  435. [self.uut viewWillAppear:false];
  436. XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:backgroundImage.get]);
  437. }
  438. - (void)testMergeOptionsShouldCallPresenterMergeOptions {
  439. RNNNavigationOptions* newOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  440. [[(id) self.uut.presenter expect] mergeOptions:newOptions resolvedOptions:self.uut.options];
  441. [self.uut mergeOptions:newOptions];
  442. [(id)self.uut.presenter verify];
  443. }
  444. - (void)testOverrideOptions {
  445. RNNNavigationOptions* newOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  446. newOptions.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
  447. [self.uut overrideOptions:newOptions];
  448. XCTAssertEqual([UIColor redColor], self.uut.options.topBar.background.color.get);
  449. }
  450. #pragma mark BottomTabs
  451. - (RNNStackController *)createNavigationController {
  452. RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNStackPresenter alloc] init] eventEmitter:nil childViewControllers:@[self.uut]];
  453. return nav;
  454. }
  455. @end