react-native-navigation的迁移库

RNNNavigationControllerPresenterTest.m 3.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. @end