react-native-navigation的迁移库

RNNNavigationControllerPresenterTest.m 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "RNNNavigationControllerPresenter.h"
  4. #import "UINavigationController+RNNOptions.h"
  5. #import "RNNNavigationController.h"
  6. @interface RNNNavigationControllerPresenterTest : XCTestCase
  7. @property (nonatomic, strong) RNNNavigationControllerPresenter *uut;
  8. @property (nonatomic, strong) RNNNavigationOptions *options;
  9. @property (nonatomic, strong) id bindedViewController;
  10. @end
  11. @implementation RNNNavigationControllerPresenterTest
  12. - (void)setUp {
  13. [super setUp];
  14. self.uut = [[RNNNavigationControllerPresenter alloc] init];
  15. self.bindedViewController = [OCMockObject partialMockForObject:[RNNNavigationController new]];
  16. [self.uut bindViewController:self.bindedViewController];
  17. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  18. }
  19. - (void)testApplyOptions_shouldSetBackButtonColor_withDefaultValues {
  20. [[_bindedViewController expect] rnn_setBackButtonColor:nil];
  21. [self.uut applyOptions:self.options];
  22. [_bindedViewController verify];
  23. }
  24. - (void)testApplyOptions_shouldSetBackButtonColor_withColor {
  25. self.options.topBar.backButton.color = [[Color alloc] initWithValue:[UIColor redColor]];
  26. [[_bindedViewController expect] rnn_setBackButtonColor:[UIColor redColor]];
  27. [self.uut applyOptions:self.options];
  28. [_bindedViewController verify];
  29. }
  30. - (void)testApplyOptions_shouldSetBackButtonOnBindedViewController_withTitle {
  31. Text* title = [[Text alloc] initWithValue:@"Title"];
  32. self.options.topBar.backButton.title = title;
  33. [[_bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:title.get];
  34. [self.uut applyOptions:self.options];
  35. [_bindedViewController verify];
  36. }
  37. - (void)testApplyOptions_shouldSetBackButtonOnBindedViewController_withHideTitle {
  38. Text* title = [[Text alloc] initWithValue:@"Title"];
  39. self.options.topBar.backButton.title = title;
  40. self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)];
  41. [[_bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:@""];
  42. [self.uut applyOptions:self.options];
  43. [_bindedViewController verify];
  44. }
  45. - (void)testApplyOptions_shouldSetBackButtonOnBindedViewController_withIcon {
  46. Image* image = [[Image alloc] initWithValue:[UIImage new]];
  47. self.options.topBar.backButton.icon = image;
  48. [[_bindedViewController expect] rnn_setBackButtonIcon:image.get withColor:nil title:nil];
  49. [self.uut applyOptions:self.options];
  50. [_bindedViewController verify];
  51. }
  52. - (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withTitle {
  53. Text* title = [[Text alloc] initWithValue:@"Title"];
  54. self.options.topBar.backButton.title = title;
  55. [[_bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:title.get];
  56. [self.uut applyOptionsOnWillMoveToParentViewController:self.options];
  57. [_bindedViewController verify];
  58. }
  59. - (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withHideTitle {
  60. Text* title = [[Text alloc] initWithValue:@"Title"];
  61. self.options.topBar.backButton.title = title;
  62. self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)];
  63. [[_bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:@""];
  64. [self.uut applyOptionsOnWillMoveToParentViewController:self.options];
  65. [_bindedViewController verify];
  66. }
  67. - (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withIcon {
  68. Image* image = [[Image alloc] initWithValue:[UIImage new]];
  69. self.options.topBar.backButton.icon = image;
  70. [[_bindedViewController expect] rnn_setBackButtonIcon:image.get withColor:nil title:nil];
  71. [self.uut applyOptionsOnWillMoveToParentViewController:self.options];
  72. [_bindedViewController verify];
  73. }
  74. - (void)testApplyOptionsOnWillMoveToParent_shouldSetBackButtonOnBindedViewController_withDefaultValues {
  75. [[_bindedViewController expect] rnn_setBackButtonIcon:nil withColor:nil title:nil];
  76. [self.uut applyOptionsOnWillMoveToParentViewController:self.options];
  77. [_bindedViewController verify];
  78. }
  79. - (void)testApplyOptionsBefoePoppingShouldSetTopBarBackgroundForPoppingViewController {
  80. _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
  81. [[_bindedViewController expect] setTopBarBackgroundColor:_options.topBar.background.color.get];
  82. [self.uut applyOptionsBeforePopping:self.options];
  83. [_bindedViewController verify];
  84. }
  85. @end