react-native-navigation的迁移库

RNNViewControllerPresenterTest.m 4.9KB

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