react-native-navigation的迁移库

RNNBasePresenterTest.m 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #import <XCTest/XCTest.h>
  2. #import "RNNBasePresenter.h"
  3. #import <OCMock/OCMock.h>
  4. #import "UIViewController+RNNOptions.h"
  5. #import "RNNComponentViewController.h"
  6. @interface RNNBottomTabPresenterTest : XCTestCase
  7. @property(nonatomic, strong) RNNBasePresenter *uut;
  8. @property(nonatomic, strong) RNNNavigationOptions *options;
  9. @property(nonatomic, strong) RNNComponentViewController *boundViewController;
  10. @property(nonatomic, strong) id mockBoundViewController;
  11. @end
  12. @implementation RNNBottomTabPresenterTest
  13. - (void)setUp {
  14. [super setUp];
  15. self.uut = [[RNNBasePresenter alloc] init];
  16. self.boundViewController = [RNNComponentViewController new];
  17. self.mockBoundViewController = [OCMockObject partialMockForObject:self.boundViewController];
  18. [self.uut bindViewController:self.mockBoundViewController];
  19. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  20. }
  21. - (void)tearDown {
  22. [super tearDown];
  23. [self.mockBoundViewController stopMocking];
  24. self.boundViewController = nil;
  25. }
  26. - (void)testApplyOptions_shouldSetTabBarItemBadgeOnlyWhenParentIsUITabBarController {
  27. [[self.mockBoundViewController reject] setTabBarItemBadge:[OCMArg any]];
  28. [self.uut applyOptions:self.options];
  29. [self.mockBoundViewController verify];
  30. }
  31. - (void)testApplyOptions_shouldSetTabBarItemBadgeWithValue {
  32. OCMStub([self.mockBoundViewController parentViewController]).andReturn([UITabBarController new]);
  33. self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
  34. [[self.mockBoundViewController expect] setTabBarItemBadge:self.options.bottomTab.badge.get];
  35. [self.uut applyOptions:self.options];
  36. [self.mockBoundViewController verify];
  37. }
  38. - (void)testApplyOptions_setTabBarItemBadgeShouldNotCalledOnUITabBarController {
  39. [self.uut bindViewController:self.mockBoundViewController];
  40. self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
  41. [[self.mockBoundViewController reject] setTabBarItemBadge:[[RNNBottomTabOptions alloc] initWithDict:@{@"badge": @"badge"}]];
  42. [self.uut applyOptions:self.options];
  43. [self.mockBoundViewController verify];
  44. }
  45. - (void)testApplyOptions_setTabBarItemBadgeShouldWhenNoValue {
  46. [self.uut bindViewController:self.mockBoundViewController];
  47. self.options.bottomTab.badge = nil;
  48. [[self.mockBoundViewController reject] setTabBarItemBadge:[OCMArg any]];
  49. [self.uut applyOptions:self.options];
  50. [self.mockBoundViewController verify];
  51. }
  52. - (void)testGetPreferredStatusBarStyle_returnLightIfLight {
  53. RNNNavigationOptions * lightOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  54. lightOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
  55. XCTAssertEqual([_uut getStatusBarStyle:lightOptions], UIStatusBarStyleLightContent);
  56. }
  57. - (void)testGetPreferredStatusBarStyle_returnDefaultIfDark {
  58. RNNNavigationOptions * darkOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  59. darkOptions.statusBar.style = [[Text alloc] initWithValue:@"dark"];
  60. XCTAssertEqual([_uut getStatusBarStyle:darkOptions], UIStatusBarStyleDefault);
  61. }
  62. - (void)testGetPreferredStatusBarStyle_returnDefaultIfNil {
  63. RNNNavigationOptions * options = [[RNNNavigationOptions alloc] initEmptyOptions];
  64. XCTAssertEqual([_uut getStatusBarStyle:options], UIStatusBarStyleDefault);
  65. }
  66. - (void)testGetPreferredStatusBarStyle_considersDefaultOptions {
  67. RNNNavigationOptions * options = [[RNNNavigationOptions alloc] initEmptyOptions];
  68. RNNNavigationOptions * lightOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  69. lightOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
  70. [_uut setDefaultOptions:lightOptions];
  71. XCTAssertEqual([_uut getStatusBarStyle:options], UIStatusBarStyleLightContent);
  72. }
  73. @end