react-native-navigation的迁移库

RNNBottomTabsAppearancePresenterTest.m 4.6KB

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