react-native-navigation的迁移库

RNNBottomTabsAppearancePresenterTest.m 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.boundViewController viewWillAppear:YES];
  25. [self.uut bindViewController:self.boundViewController];
  26. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  27. }
  28. - (void)testApplyOptions_shouldSetDefaultEmptyOptions {
  29. RNNNavigationOptions *emptyOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  30. [[self.boundViewController expect] setTabBarTestID:nil];
  31. [[(id)self.uut expect] applyBackgroundColor:nil translucent:NO];
  32. [[self.boundViewController expect] setTabBarHideShadow:NO];
  33. [[self.boundViewController expect] setTabBarVisible:YES animated:NO];
  34. [[self.boundViewController expect] setTabBarStyle:UIBarStyleDefault];
  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. [[(id)self.uut expect] applyBackgroundColor:nil translucent:[UIColor redColor]];
  48. [[self.boundViewController expect] setTabBarHideShadow:YES];
  49. [[self.boundViewController expect] setTabBarStyle:UIBarStyleBlack];
  50. [self.uut applyOptions:initialOptions];
  51. [self.boundViewController verify];
  52. }
  53. - (void)testApplyOptions_shouldRestoreHiddenTabBar {
  54. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  55. initialOptions.bottomTabs.visible = [[Bool alloc] initWithValue:@(1)];
  56. [[self.boundViewController expect] setTabBarVisible:YES animated:NO];
  57. [self.uut applyOptions:initialOptions];
  58. [self.boundViewController verify];
  59. }
  60. - (void)testApplyOptionsOnInit_alwaysShow_shouldNotCenterTabImages {
  61. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  62. initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysShow"];
  63. [[self.boundViewController reject] centerTabItems];
  64. [self.uut applyOptionsOnInit:initialOptions];
  65. [self.boundViewController verify];
  66. }
  67. - (void)testApplyOptions_shouldApplyOptionsOnInit_alwaysHide_shouldCenterTabImages {
  68. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  69. initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysHide"];
  70. [[self.boundViewController expect] centerTabItems];
  71. [self.uut applyOptionsOnInit:initialOptions];
  72. [self.boundViewController verify];
  73. }
  74. - (void)testBackgroundColor_validColor {
  75. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  76. self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
  77. [self.uut applyOptions:self.options];
  78. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  79. XCTAssertTrue([((UIViewController *)self.boundViewController).view.backgroundColor isEqual:expectedColor]);
  80. }
  81. - (void)testTabBarBackgroundColor {
  82. UIColor* tabBarBackgroundColor = [UIColor redColor];
  83. [self.uut setTabBarBackgroundColor:tabBarBackgroundColor];
  84. XCTAssertTrue([self.children.lastObject.tabBarItem.standardAppearance.backgroundColor isEqual:tabBarBackgroundColor]);
  85. }
  86. @end