react-native-navigation的迁移库

RNNRootViewControllerTest.m 26KB

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