react-native-navigation的迁移库

RNNRootViewControllerTest.m 27KB

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