react-native-navigation的迁移库

RNNBasePresenterTest.m 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #import <XCTest/XCTest.h>
  2. #import "RNNBasePresenter.h"
  3. #import <OCMock/OCMock.h>
  4. #import "UIViewController+RNNOptions.h"
  5. #import "RNNComponentViewController+Utils.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 createWithComponentId:@"componentId" initialOptions:[RNNNavigationOptions emptyOptions]];
  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. self.boundViewController.options.statusBar.style = [[Text alloc] initWithValue:@"light"];
  47. XCTAssertEqual([_uut getStatusBarStyle], UIStatusBarStyleLightContent);
  48. }
  49. - (void)testGetPreferredStatusBarStyle_returnDark {
  50. self.boundViewController.options.statusBar.style = [[Text alloc] initWithValue:@"dark"];
  51. XCTAssertEqual([_uut getStatusBarStyle], UIStatusBarStyleDarkContent);
  52. }
  53. - (void)testGetPreferredStatusBarStyle_returnDefaultIfNil {
  54. self.boundViewController.options.statusBar.style = nil;
  55. XCTAssertEqual([_uut getStatusBarStyle], UIStatusBarStyleDefault);
  56. }
  57. - (void)testGetPreferredStatusBarStyle_considersDefaultOptions {
  58. RNNNavigationOptions * lightOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  59. lightOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
  60. [_uut setDefaultOptions:lightOptions];
  61. XCTAssertEqual([_uut getStatusBarStyle], UIStatusBarStyleLightContent);
  62. }
  63. - (void)testApplyOptionsOnInit_setSwipeToDismiss {
  64. self.options.modal.swipeToDismiss = [[Bool alloc] initWithBOOL:NO];
  65. XCTAssertFalse(_boundViewController.modalInPresentation);
  66. [self.uut applyOptionsOnInit:self.options];
  67. XCTAssertTrue(_boundViewController.modalInPresentation);
  68. }
  69. @end