react-native-navigation的迁移库

RNNBottomTabsPresenterTest.m 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.uut applyOptions:initialOptions];
  42. [self.boundViewController verify];
  43. }
  44. - (void)testApplyOptions_shouldRestoreHiddenTabBar {
  45. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  46. initialOptions.bottomTabs.visible = [[Bool alloc] initWithValue:@(1)];
  47. [[self.boundViewController expect] setTabBarVisible:YES animated:NO];
  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([((UIViewController *)self.uut).tabBarController.tabBar.barTintColor isEqual:tabBarBackgroundColor]);
  76. }
  77. @end