react-native-navigation的迁移库

RNNBottomTabsPresenterTest.m 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "RNNBottomTabsPresenter.h"
  4. #import "UITabBarController+RNNOptions.h"
  5. #import "RNNBottomTabsController.h"
  6. @interface RNNBottomTabsPresenterTest : XCTestCase
  7. @property(nonatomic, strong) RNNBottomTabsPresenter *uut;
  8. @property(nonatomic, strong) RNNNavigationOptions *options;
  9. @property(nonatomic, strong) id boundViewController;
  10. @end
  11. @implementation RNNBottomTabsPresenterTest
  12. - (void)setUp {
  13. [super setUp];
  14. self.uut = [OCMockObject partialMockForObject:[RNNBottomTabsPresenter new]];
  15. self.boundViewController = [OCMockObject partialMockForObject:[RNNBottomTabsController new]];
  16. [self.uut bindViewController:self.boundViewController];
  17. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  18. }
  19. - (void)testApplyOptions_shouldSetDefaultEmptyOptions {
  20. RNNNavigationOptions *emptyOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  21. [[self.boundViewController expect] setTabBarTestID:nil];
  22. [[(id)self.uut expect] applyBackgroundColor:nil translucent:NO];
  23. [[self.boundViewController expect] setTabBarHideShadow:NO];
  24. [[self.boundViewController expect] setTabBarStyle:UIBarStyleDefault];
  25. [self.uut applyOptions:emptyOptions];
  26. [self.boundViewController verify];
  27. }
  28. - (void)testApplyOptions_shouldApplyOptions {
  29. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  30. initialOptions.bottomTabs.testID = [[Text alloc] initWithValue:@"testID"];
  31. initialOptions.bottomTabs.backgroundColor = [[Color alloc] initWithValue:[UIColor redColor]];
  32. initialOptions.bottomTabs.translucent = [[Bool alloc] initWithValue:@(0)];
  33. initialOptions.bottomTabs.hideShadow = [[Bool alloc] initWithValue:@(1)];
  34. initialOptions.bottomTabs.visible = [[Bool alloc] initWithValue:@(0)];
  35. initialOptions.bottomTabs.barStyle = [[Text alloc] initWithValue:@"black"];
  36. [[self.boundViewController expect] setTabBarTestID:@"testID"];
  37. [[(id)self.uut expect] applyBackgroundColor:nil translucent:[UIColor redColor]];
  38. [[self.boundViewController expect] setTabBarHideShadow:YES];
  39. [[self.boundViewController expect] setTabBarStyle:UIBarStyleBlack];
  40. [self.uut applyOptions:initialOptions];
  41. [self.boundViewController verify];
  42. }
  43. - (void)testApplyOptionsOnInit_alwaysShow_shouldNotCenterTabImages {
  44. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  45. initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysShow"];
  46. [[self.boundViewController reject] centerTabItems];
  47. [self.uut applyOptionsOnInit:initialOptions];
  48. [self.boundViewController verify];
  49. }
  50. - (void)testApplyOptions_shouldApplyOptionsOnInit_alwaysHide_shouldCenterTabImages {
  51. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  52. initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysHide"];
  53. [[self.boundViewController expect] centerTabItems];
  54. [self.uut applyOptionsOnInit:initialOptions];
  55. [self.boundViewController verify];
  56. }
  57. - (void)testBackgroundColor_validColor {
  58. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  59. self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
  60. [self.uut applyOptions:self.options];
  61. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  62. XCTAssertTrue([((UIViewController *)self.boundViewController).view.backgroundColor isEqual:expectedColor]);
  63. }
  64. - (void)testTabBarBackgroundColor {
  65. UIColor* tabBarBackgroundColor = [UIColor redColor];
  66. [self.uut setTabBarBackgroundColor:tabBarBackgroundColor];
  67. XCTAssertTrue([((UIViewController *)self.uut).tabBarController.tabBar.barTintColor isEqual:tabBarBackgroundColor]);
  68. }
  69. @end