react-native-navigation的迁移库

RNNBasePresenterTest.m 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. - (void)testHidesBottomBarWhenPushed_showsBar {
  70. _boundViewController.options.bottomTabs.visible = [[Bool alloc] initWithBOOL:NO];
  71. XCTAssertTrue(_boundViewController.hidesBottomBarWhenPushed);
  72. }
  73. - (void)testHidesBottomBarWhenPushed_hidesBar {
  74. _boundViewController.options.bottomTabs.visible = [[Bool alloc] initWithBOOL:YES];
  75. XCTAssertFalse(_boundViewController.hidesBottomBarWhenPushed);
  76. }
  77. - (void)testHidesBottomBarWhenPushed_resolveParentShowsBar {
  78. UINavigationController* nvc = [[UINavigationController alloc] initWithRootViewController:self.boundViewController];
  79. nvc.options = [RNNNavigationOptions emptyOptions];
  80. nvc.options.bottomTabs.visible = [[Bool alloc] initWithBOOL:NO];
  81. XCTAssertTrue(_boundViewController.hidesBottomBarWhenPushed);
  82. }
  83. - (void)testHidesBottomBarWhenPushed_resolveParentHidesBar {
  84. UINavigationController* nvc = [[UINavigationController alloc] initWithRootViewController:self.boundViewController];
  85. nvc.options = [RNNNavigationOptions emptyOptions];
  86. nvc.options.bottomTabs.visible = [[Bool alloc] initWithBOOL:YES];
  87. XCTAssertFalse(_boundViewController.hidesBottomBarWhenPushed);
  88. }
  89. - (void)testHidesBottomBarWhenPushed_resolveChildShowsBarBeforeParent {
  90. UINavigationController* nvc = [[UINavigationController alloc] initWithRootViewController:self.boundViewController];
  91. nvc.options = [RNNNavigationOptions emptyOptions];
  92. nvc.options.bottomTabs.visible = [[Bool alloc] initWithBOOL:NO];
  93. XCTAssertTrue(_boundViewController.hidesBottomBarWhenPushed);
  94. }
  95. - (void)testHidesBottomBarWhenPushed_resolveChildHidesBarBeforeParent {
  96. UINavigationController* nvc = [[UINavigationController alloc] initWithRootViewController:self.boundViewController];
  97. nvc.options = [RNNNavigationOptions emptyOptions];
  98. self.boundViewController.options.bottomTabs.visible = [[Bool alloc] initWithBOOL:NO];
  99. nvc.options.bottomTabs.visible = [[Bool alloc] initWithBOOL:YES];
  100. XCTAssertTrue(_boundViewController.hidesBottomBarWhenPushed);
  101. }
  102. @end