react-native-navigation的迁移库

RNNBottomTabsAppearancePresenterTest.m 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "BottomTabsAppearancePresenter.h"
  4. #import "UITabBarController+RNNOptions.h"
  5. #import "RNNBottomTabsController.h"
  6. #import "RNNComponentViewController.h"
  7. @interface RNNBottomTabsAppearancePresenterTest : XCTestCase
  8. @property(nonatomic, strong) BottomTabsAppearancePresenter *uut;
  9. @property(nonatomic, strong) RNNNavigationOptions *options;
  10. @property(nonatomic, strong) id boundViewController;
  11. @end
  12. @implementation RNNBottomTabsAppearancePresenterTest
  13. - (void)setUp {
  14. [super setUp];
  15. self.uut = [OCMockObject partialMockForObject:[BottomTabsAppearancePresenter new]];
  16. self.boundViewController = [OCMockObject partialMockForObject:[RNNBottomTabsController new]];
  17. [self.uut bindViewController:self.boundViewController];
  18. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  19. }
  20. - (void)testApplyOptions_shouldSetDefaultEmptyOptions {
  21. RNNNavigationOptions *emptyOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  22. [[self.boundViewController expect] setTabBarTestID:nil];
  23. [self.uut setTabBarBackgroundColor:nil];
  24. [[self.boundViewController expect] setTabBarTranslucent:NO];
  25. [[self.boundViewController expect] setTabBarHideShadow:NO];
  26. [[self.boundViewController expect] setTabBarStyle:UIBarStyleDefault];
  27. [[self.boundViewController expect] setTabBarVisible:YES animated:NO];
  28. [self.uut applyOptions:emptyOptions];
  29. [self.boundViewController verify];
  30. }
  31. - (void)testApplyOptions_shouldApplyOptions {
  32. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  33. initialOptions.bottomTabs.testID = [[Text alloc] initWithValue:@"testID"];
  34. initialOptions.bottomTabs.backgroundColor = [[Color alloc] initWithValue:[UIColor redColor]];
  35. initialOptions.bottomTabs.translucent = [[Bool alloc] initWithValue:@(0)];
  36. initialOptions.bottomTabs.hideShadow = [[Bool alloc] initWithValue:@(1)];
  37. initialOptions.bottomTabs.visible = [[Bool alloc] initWithValue:@(0)];
  38. initialOptions.bottomTabs.barStyle = [[Text alloc] initWithValue:@"black"];
  39. [[self.boundViewController expect] setTabBarTestID:@"testID"];
  40. [self.uut setTabBarBackgroundColor:[UIColor redColor]];
  41. [[self.boundViewController expect] setTabBarTranslucent:NO];
  42. [[self.boundViewController expect] setTabBarHideShadow:YES];
  43. [[self.boundViewController expect] setTabBarStyle:UIBarStyleBlack];
  44. [[self.boundViewController expect] setTabBarVisible:NO animated:NO];
  45. [self.uut applyOptions:initialOptions];
  46. [self.boundViewController verify];
  47. }
  48. - (void)testApplyOptionsOnInit_alwaysShow_shouldNotCenterTabImages {
  49. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  50. initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysShow"];
  51. [[self.boundViewController reject] centerTabItems];
  52. [self.uut applyOptionsOnInit:initialOptions];
  53. [self.boundViewController verify];
  54. }
  55. - (void)testApplyOptions_shouldApplyOptionsOnInit_alwaysHide_shouldCenterTabImages {
  56. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  57. initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysHide"];
  58. [[self.boundViewController expect] centerTabItems];
  59. [self.uut applyOptionsOnInit:initialOptions];
  60. [self.boundViewController verify];
  61. }
  62. - (void)testViewDidLayoutSubviews_appliesBadgeOnNextRunLoop {
  63. id uut = [self uut];
  64. [[uut expect] applyDotIndicator];
  65. [uut viewDidLayoutSubviews];
  66. [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
  67. [uut verify];
  68. }
  69. - (void)testApplyDotIndicator_callsAppliesBadgeWithEachChild {
  70. id uut = [self uut];
  71. id child1 = [UIViewController new];
  72. id child2 = [UIViewController new];
  73. [[uut expect] applyDotIndicator:child1];
  74. [[uut expect] applyDotIndicator:child2];
  75. [[self boundViewController] addChildViewController:child1];
  76. [[self boundViewController] addChildViewController:child2];
  77. [uut applyDotIndicator];
  78. [uut verify];
  79. }
  80. - (void)testBackgroundColor_validColor {
  81. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  82. self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
  83. [self.uut applyOptions:self.options];
  84. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  85. XCTAssertTrue([((UIViewController *)self.boundViewController).view.backgroundColor isEqual:expectedColor]);
  86. }
  87. - (void)testTabBarBackgroundColor {
  88. UIColor* tabBarBackgroundColor = [UIColor redColor];
  89. RNNComponentPresenter* vcPresenter = [[RNNComponentPresenter alloc] initWithDefaultOptions:nil];
  90. UIViewController* vc = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:vcPresenter options:nil defaultOptions:nil];
  91. [((UITabBarController *)self.boundViewController) setViewControllers:@[vc]];
  92. [self.uut setTabBarBackgroundColor:tabBarBackgroundColor];
  93. XCTAssertTrue([vc.tabBarItem.standardAppearance.backgroundColor isEqual:tabBarBackgroundColor]);
  94. }
  95. @end