react-native-navigation的迁移库

RNNBasePresenterTest.m 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 boundViewController: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 boundViewController: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 boundViewController: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. - (void)testApplyOptionsOnInit_setSwipeToDismiss {
  74. self.options.modal.swipeToDismiss = [[Bool alloc] initWithBOOL:NO];
  75. XCTAssertFalse(_boundViewController.modalInPresentation);
  76. [self.uut applyOptionsOnInit:self.options];
  77. XCTAssertTrue(_boundViewController.modalInPresentation);
  78. }
  79. @end