react-native-navigation的迁移库

RNNViewControllerPresenterTest.m 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "RNNViewControllerPresenter.h"
  4. #import "UIViewController+RNNOptions.h"
  5. #import "RNNReactView.h"
  6. #import "RNNRootViewController.h"
  7. @interface RNNViewControllerPresenterTest : XCTestCase
  8. @property (nonatomic, strong) RNNViewControllerPresenter *uut;
  9. @property (nonatomic, strong) RNNNavigationOptions *options;
  10. @property (nonatomic, strong) UIViewController *bindedViewController;
  11. @end
  12. @implementation RNNViewControllerPresenterTest
  13. - (void)setUp {
  14. [super setUp];
  15. self.uut = [[RNNViewControllerPresenter alloc] init];
  16. self.bindedViewController = [OCMockObject partialMockForObject:[RNNRootViewController new]];
  17. [self.uut bindViewController:self.bindedViewController];
  18. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  19. }
  20. - (void)testApplyOptions_backgroundImageDefaultNilShouldNotAddSubview {
  21. [self.uut applyOptions:self.options];
  22. XCTAssertTrue((self.bindedViewController.view.subviews.count) == 0);
  23. }
  24. - (void)testApplyOptions_topBarPrefersLargeTitleDefaultFalse {
  25. [self.uut applyOptions:self.options];
  26. XCTAssertTrue(self.bindedViewController.navigationItem.largeTitleDisplayMode == UINavigationItemLargeTitleDisplayModeNever);
  27. }
  28. - (void)testApplyOptions_layoutBackgroundColorDefaultWhiteColor {
  29. [self.uut applyOptions:self.options];
  30. XCTAssertNil(self.bindedViewController.view.backgroundColor);
  31. }
  32. - (void)testApplyOptions_statusBarBlurDefaultFalse {
  33. [self.uut applyOptions:self.options];
  34. XCTAssertNil([self.bindedViewController.view viewWithTag:BLUR_STATUS_TAG]);
  35. }
  36. - (void)testApplyOptions_statusBarStyleDefaultStyle {
  37. [self.uut applyOptions:self.options];
  38. XCTAssertTrue([self.bindedViewController preferredStatusBarStyle] == UIStatusBarStyleDefault);
  39. }
  40. - (void)testApplyOptions_backButtonVisibleDefaultTrue {
  41. [self.uut applyOptions:self.options];
  42. XCTAssertFalse(self.bindedViewController.navigationItem.hidesBackButton);
  43. }
  44. - (void)testApplyOptions_drawBehindTabBarTrueWhenVisibleFalse {
  45. self.options.bottomTabs.visible = [[Bool alloc] initWithValue:@(0)];
  46. [[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:YES];
  47. [self.uut applyOptionsOnInit:self.options];
  48. [(id)self.bindedViewController verify];
  49. }
  50. - (void)testApplyOptions_setOverlayTouchOutsideIfHasValue {
  51. self.options.overlay.interceptTouchOutside = [[Bool alloc] initWithBOOL:YES];
  52. [[(id)self.bindedViewController expect] rnn_setInterceptTouchOutside:YES];
  53. [self.uut applyOptions:self.options];
  54. [(id)self.bindedViewController verify];
  55. }
  56. - (void)testBindViewControllerShouldCreateNavigationButtonsCreator {
  57. RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
  58. [presenter bindViewController:self.bindedViewController viewCreator:nil];
  59. XCTAssertNotNil(presenter.navigationButtons);
  60. }
  61. - (void)testApplyOptionsOnInit_shouldSetModalPresentetionStyleWithDefault {
  62. [[(id)self.bindedViewController expect] rnn_setModalPresentationStyle:UIModalPresentationFullScreen];
  63. [self.uut applyOptionsOnInit:self.options];
  64. [(id)self.bindedViewController verify];
  65. }
  66. - (void)testApplyOptionsOnInit_shouldSetModalTransitionStyleWithDefault {
  67. [[(id)self.bindedViewController expect] rnn_setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
  68. [self.uut applyOptionsOnInit:self.options];
  69. [(id)self.bindedViewController verify];
  70. }
  71. - (void)testApplyOptionsOnInit_shouldSetModalPresentetionStyleWithValue {
  72. self.options.modalPresentationStyle = [[Text alloc] initWithValue:@"overCurrentContext"];
  73. [[(id)self.bindedViewController expect] rnn_setModalPresentationStyle:UIModalPresentationOverCurrentContext];
  74. [self.uut applyOptionsOnInit:self.options];
  75. [(id)self.bindedViewController verify];
  76. }
  77. - (void)testApplyOptionsOnInit_shouldSetModalTransitionStyleWithValue {
  78. self.options.modalTransitionStyle = [[Text alloc] initWithValue:@"crossDissolve"];
  79. [[(id)self.bindedViewController expect] rnn_setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
  80. [self.uut applyOptionsOnInit:self.options];
  81. [(id)self.bindedViewController verify];
  82. }
  83. -(void)testApplyOptionsOnInit_TopBarDrawUnder_true {
  84. self.options.topBar.drawBehind = [[Bool alloc] initWithValue:@(1)];
  85. [[(id)self.bindedViewController expect] rnn_setDrawBehindTopBar:YES];
  86. [self.uut applyOptionsOnInit:self.options];
  87. [(id)self.bindedViewController verify];
  88. }
  89. -(void)testApplyOptionsOnInit_TopBarDrawUnder_false {
  90. self.options.topBar.drawBehind = [[Bool alloc] initWithValue:@(0)];
  91. [[(id)self.bindedViewController expect] rnn_setDrawBehindTopBar:NO];
  92. [self.uut applyOptionsOnInit:self.options];
  93. [(id)self.bindedViewController verify];
  94. }
  95. -(void)testApplyOptionsOnInit_BottomTabsDrawUnder_true {
  96. self.options.bottomTabs.drawBehind = [[Bool alloc] initWithValue:@(1)];
  97. [[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:YES];
  98. [self.uut applyOptionsOnInit:self.options];
  99. [(id)self.bindedViewController verify];
  100. }
  101. -(void)testApplyOptionsOnInit_BottomTabsDrawUnder_false {
  102. self.options.bottomTabs.drawBehind = [[Bool alloc] initWithValue:@(0)];
  103. [[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:NO];
  104. [self.uut applyOptionsOnInit:self.options];
  105. [(id)self.bindedViewController verify];
  106. }
  107. @end