react-native-navigation的迁移库

RNNBottomTabsAppearancePresenterTest.m 4.9KB

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