react-native-navigation的迁移库

RNNTabBarPresenterTest.m 4.0KB

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 RNNTabBarPresenterTest : XCTestCase
  7. @property(nonatomic, strong) RNNBottomTabsPresenter *uut;
  8. @property(nonatomic, strong) RNNNavigationOptions *options;
  9. @property(nonatomic, strong) id boundViewController;
  10. @end
  11. @implementation RNNTabBarPresenterTest
  12. - (void)setUp {
  13. [super setUp];
  14. self.uut = [OCMockObject partialMockForObject:[RNNBottomTabsPresenter new]];
  15. self.boundViewController = [OCMockObject partialMockForObject:[RNNBottomTabsController new]];
  16. [self.uut boundViewController: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. [[self.boundViewController expect] setTabBarBackgroundColor:nil];
  23. [[self.boundViewController expect] setTabBarTranslucent:NO];
  24. [[self.boundViewController expect] setTabBarHideShadow:NO];
  25. [[self.boundViewController expect] setTabBarStyle:UIBarStyleDefault];
  26. [[self.boundViewController expect] setTabBarVisible:YES animated:NO];
  27. [self.uut applyOptions:emptyOptions];
  28. [self.boundViewController verify];
  29. }
  30. - (void)testApplyOptions_shouldApplyOptions {
  31. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  32. initialOptions.bottomTabs.testID = [[Text alloc] initWithValue:@"testID"];
  33. initialOptions.bottomTabs.backgroundColor = [[Color alloc] initWithValue:[UIColor redColor]];
  34. initialOptions.bottomTabs.translucent = [[Bool alloc] initWithValue:@(0)];
  35. initialOptions.bottomTabs.hideShadow = [[Bool alloc] initWithValue:@(1)];
  36. initialOptions.bottomTabs.visible = [[Bool alloc] initWithValue:@(0)];
  37. initialOptions.bottomTabs.barStyle = [[Text alloc] initWithValue:@"black"];
  38. [[self.boundViewController expect] setTabBarTestID:@"testID"];
  39. [[self.boundViewController expect] setTabBarBackgroundColor:[UIColor redColor]];
  40. [[self.boundViewController expect] setTabBarTranslucent:NO];
  41. [[self.boundViewController expect] setTabBarHideShadow:YES];
  42. [[self.boundViewController expect] setTabBarStyle:UIBarStyleBlack];
  43. [[self.boundViewController expect] setTabBarVisible:NO animated:NO];
  44. [self.uut applyOptions:initialOptions];
  45. [self.boundViewController verify];
  46. }
  47. - (void)testApplyOptionsOnInit_alwaysShow_shouldNotCenterTabImages {
  48. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  49. initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysShow"];
  50. [[self.boundViewController reject] centerTabItems];
  51. [self.uut applyOptionsOnInit:initialOptions];
  52. [self.boundViewController verify];
  53. }
  54. - (void)testApplyOptions_shouldApplyOptionsOnInit_alwaysHide_shouldCenterTabImages {
  55. RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  56. initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysHide"];
  57. [[self.boundViewController expect] centerTabItems];
  58. [self.uut applyOptionsOnInit:initialOptions];
  59. [self.boundViewController verify];
  60. }
  61. - (void)testViewDidLayoutSubviews_appliesBadgeOnNextRunLoop {
  62. id uut = [self uut];
  63. [[uut expect] applyDotIndicator];
  64. [uut viewDidLayoutSubviews];
  65. [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
  66. [uut verify];
  67. }
  68. - (void)testApplyDotIndicator_callsAppliesBadgeWithEachChild {
  69. id uut = [self uut];
  70. id child1 = [UIViewController new];
  71. id child2 = [UIViewController new];
  72. [[uut expect] applyDotIndicator:child1];
  73. [[uut expect] applyDotIndicator:child2];
  74. [[self boundViewController] addChildViewController:child1];
  75. [[self boundViewController] addChildViewController:child2];
  76. [uut applyDotIndicator];
  77. [uut verify];
  78. }
  79. @end