react-native-navigation的迁移库

RNNStackPresenterTest.m 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "RNNStackPresenter.h"
  4. #import "UINavigationController+RNNOptions.h"
  5. #import "RNNStackController.h"
  6. @interface RNNStackPresenterTest : XCTestCase
  7. @property (nonatomic, strong) RNNStackPresenter *uut;
  8. @property (nonatomic, strong) RNNNavigationOptions *options;
  9. @property (nonatomic, strong) id boundViewController;
  10. @end
  11. @implementation RNNStackPresenterTest
  12. - (void)setUp {
  13. [super setUp];
  14. self.uut = [[RNNStackPresenter alloc] init];
  15. self.boundViewController = [OCMockObject partialMockForObject:[RNNStackController new]];
  16. [self.uut boundViewController:self.boundViewController];
  17. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  18. }
  19. - (void)testApplyOptions_shouldSetBackButtonColor_withDefaultValues {
  20. [[_boundViewController expect] setBackButtonColor:nil];
  21. [self.uut applyOptions:self.options];
  22. [_boundViewController verify];
  23. }
  24. - (void)testApplyOptions_shouldSetBackButtonColor_withColor {
  25. self.options.topBar.backButton.color = [[Color alloc] initWithValue:[UIColor redColor]];
  26. [[_boundViewController expect] setBackButtonColor:[UIColor redColor]];
  27. [self.uut applyOptions:self.options];
  28. [_boundViewController verify];
  29. }
  30. - (void)testApplyOptionsBeforePoppingShouldSetTopBarBackgroundForPoppingViewController {
  31. _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
  32. [[_boundViewController expect] setTopBarBackgroundColor:_options.topBar.background.color.get];
  33. [self.uut applyOptionsBeforePopping:self.options];
  34. [_boundViewController verify];
  35. }
  36. - (void)testApplyOptionsBeforePoppingShouldSetLargeTitleForPoppingViewController {
  37. _options.topBar.largeTitle.visible = [[Bool alloc] initWithBOOL:YES];
  38. [self.uut applyOptionsBeforePopping:self.options];
  39. XCTAssertTrue([[self.uut.boundViewController navigationBar] prefersLargeTitles]);
  40. }
  41. - (void)testApplyOptionsBeforePoppingShouldSetDefaultLargeTitleFalseForPoppingViewController {
  42. _options.topBar.largeTitle.visible = nil;
  43. [self.uut applyOptionsBeforePopping:self.options];
  44. XCTAssertFalse([[self.uut.boundViewController navigationBar] prefersLargeTitles]);
  45. }
  46. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withTitle {
  47. Text* title = [[Text alloc] initWithValue:@"Title"];
  48. self.options.topBar.backButton.title = title;
  49. [[_boundViewController expect] setBackButtonIcon:nil withColor:nil title:title.get showTitle:YES];
  50. [self.uut applyOptions:self.options];
  51. [_boundViewController verify];
  52. }
  53. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withHideTitle {
  54. Text* title = [[Text alloc] initWithValue:@"Title"];
  55. self.options.topBar.backButton.title = title;
  56. self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)];
  57. [[(id) self.boundViewController expect] setBackButtonIcon:nil withColor:nil title:title.get showTitle:self.options.topBar.backButton.showTitle.get];
  58. [self.uut applyOptions:self.options];
  59. [(id)self.boundViewController verify];
  60. }
  61. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withIcon {
  62. Image* image = [[Image alloc] initWithValue:[UIImage new]];
  63. self.options.topBar.backButton.icon = image;
  64. [[(id) self.boundViewController expect] setBackButtonIcon:image.get withColor:nil title:nil showTitle:YES];
  65. [self.uut applyOptions:self.options];
  66. [(id)self.boundViewController verify];
  67. }
  68. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withDefaultValues {
  69. [[(id) self.boundViewController expect] setBackButtonIcon:nil withColor:nil title:nil showTitle:YES];
  70. [self.uut applyOptions:self.options];
  71. [(id)self.boundViewController verify];
  72. }
  73. @end