react-native-navigation的迁移库

RNNBasePresenterTest.m 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 RNNBasePresenterTest : 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 RNNBasePresenterTest
  13. - (void)setUp {
  14. [super setUp];
  15. self.uut = [[RNNBasePresenter alloc] initWithDefaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
  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_setTabBarItemBadgeShouldNotCalledOnUITabBarController {
  32. [self.uut bindViewController:self.mockBoundViewController];
  33. self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
  34. [[self.mockBoundViewController reject] setTabBarItemBadge:[[RNNBottomTabOptions alloc] initWithDict:@{@"badge": @"badge"}]];
  35. [self.uut applyOptions:self.options];
  36. [self.mockBoundViewController verify];
  37. }
  38. - (void)testApplyOptions_setTabBarItemBadgeShouldWhenNoValue {
  39. [self.uut bindViewController:self.mockBoundViewController];
  40. self.options.bottomTab.badge = nil;
  41. [[self.mockBoundViewController reject] setTabBarItemBadge:[OCMArg any]];
  42. [self.uut applyOptions:self.options];
  43. [self.mockBoundViewController verify];
  44. }
  45. - (void)testGetPreferredStatusBarStyle_returnLightIfLight {
  46. RNNNavigationOptions * lightOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  47. lightOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
  48. XCTAssertEqual([_uut getStatusBarStyle:lightOptions], UIStatusBarStyleLightContent);
  49. }
  50. - (void)testGetPreferredStatusBarStyle_returnDark {
  51. RNNNavigationOptions * darkOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  52. darkOptions.statusBar.style = [[Text alloc] initWithValue:@"dark"];
  53. XCTAssertEqual([_uut getStatusBarStyle:darkOptions], UIStatusBarStyleDarkContent);
  54. }
  55. - (void)testGetPreferredStatusBarStyle_returnDefaultIfNil {
  56. RNNNavigationOptions * options = [[RNNNavigationOptions alloc] initEmptyOptions];
  57. XCTAssertEqual([_uut getStatusBarStyle:options], UIStatusBarStyleDefault);
  58. }
  59. - (void)testGetPreferredStatusBarStyle_considersDefaultOptions {
  60. RNNNavigationOptions * options = [[RNNNavigationOptions alloc] initEmptyOptions];
  61. RNNNavigationOptions * lightOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  62. lightOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
  63. [_uut setDefaultOptions:lightOptions];
  64. XCTAssertEqual([_uut getStatusBarStyle:options], UIStatusBarStyleLightContent);
  65. }
  66. - (void)testApplyOptionsOnInit_setSwipeToDismiss {
  67. self.options.modal.swipeToDismiss = [[Bool alloc] initWithBOOL:NO];
  68. XCTAssertFalse(_boundViewController.modalInPresentation);
  69. [self.uut applyOptionsOnInit:self.options];
  70. XCTAssertTrue(_boundViewController.modalInPresentation);
  71. }
  72. @end