react-native-navigation的迁移库

RNNBottomTabsPresenterTest.m 3.8KB

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