react-native-navigation的迁移库

RNNBottomTabsAppearancePresenterTest.m 4.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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] 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. [[(id)self.uut expect] applyBackgroundColor:nil translucent:NO];
  31. [[self.boundViewController expect] setTabBarHideShadow:NO];
  32. [[self.boundViewController expect] setTabBarStyle:UIBarStyleDefault];
  33. [[self.boundViewController expect] setTabBarVisible:YES animated:NO];
  34. [self.uut applyOptions:emptyOptions];
  35. [self.boundViewController verify];
  36. }
  37. - (void)testApplyOptions_shouldApplyOptions {
  38. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  39. initialOptions.bottomTabs.testID = [[Text alloc] initWithValue:@"testID"];
  40. initialOptions.bottomTabs.backgroundColor = [[Color alloc] initWithValue:[UIColor redColor]];
  41. initialOptions.bottomTabs.translucent = [[Bool alloc] initWithValue:@(0)];
  42. initialOptions.bottomTabs.hideShadow = [[Bool alloc] initWithValue:@(1)];
  43. initialOptions.bottomTabs.visible = [[Bool alloc] initWithValue:@(0)];
  44. initialOptions.bottomTabs.barStyle = [[Text alloc] initWithValue:@"black"];
  45. [[self.boundViewController expect] setTabBarTestID:@"testID"];
  46. [[(id)self.uut expect] applyBackgroundColor:nil translucent:[UIColor redColor]];
  47. [[self.boundViewController expect] setTabBarHideShadow:YES];
  48. [[self.boundViewController expect] setTabBarStyle:UIBarStyleBlack];
  49. [[self.boundViewController expect] setTabBarVisible:NO animated:NO];
  50. [self.uut applyOptions:initialOptions];
  51. [self.boundViewController verify];
  52. }
  53. - (void)testApplyOptionsOnInit_alwaysShow_shouldNotCenterTabImages {
  54. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  55. initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysShow"];
  56. [[self.boundViewController reject] centerTabItems];
  57. [self.uut applyOptionsOnInit:initialOptions];
  58. [self.boundViewController verify];
  59. }
  60. - (void)testApplyOptions_shouldApplyOptionsOnInit_alwaysHide_shouldCenterTabImages {
  61. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  62. initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysHide"];
  63. [[self.boundViewController expect] centerTabItems];
  64. [self.uut applyOptionsOnInit:initialOptions];
  65. [self.boundViewController verify];
  66. }
  67. - (void)testBackgroundColor_validColor {
  68. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  69. self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
  70. [self.uut applyOptions:self.options];
  71. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  72. XCTAssertTrue([((UIViewController *)self.boundViewController).view.backgroundColor isEqual:expectedColor]);
  73. }
  74. - (void)testTabBarBackgroundColor {
  75. UIColor* tabBarBackgroundColor = [UIColor redColor];
  76. [self.uut setTabBarBackgroundColor:tabBarBackgroundColor];
  77. XCTAssertTrue([self.children.lastObject.tabBarItem.standardAppearance.backgroundColor isEqual:tabBarBackgroundColor]);
  78. }
  79. @end