react-native-navigation的迁移库

RNNStackPresenterTest.m 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import <ReactNativeNavigation/RNNStackPresenter.h>
  4. #import "UINavigationController+RNNOptions.h"
  5. #import "RNNStackController.h"
  6. #import "UIImage+Utils.h"
  7. #import "RNNComponentViewController+Utils.h"
  8. @interface RNNStackPresenterTest : XCTestCase
  9. @property (nonatomic, strong) RNNStackPresenter *uut;
  10. @property (nonatomic, strong) RNNNavigationOptions *options;
  11. @property (nonatomic, strong) RNNStackController* boundViewController;
  12. @end
  13. @implementation RNNStackPresenterTest
  14. - (void)setUp {
  15. [super setUp];
  16. self.uut = [[RNNStackPresenter alloc] init];
  17. RNNStackController* stackController = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:self.uut eventEmitter:nil childViewControllers:@[[RNNComponentViewController createWithComponentId:@"component1"], [RNNComponentViewController createWithComponentId:@"component2"]]];
  18. self.boundViewController = [OCMockObject partialMockForObject:stackController];
  19. [self.uut bindViewController:self.boundViewController];
  20. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  21. }
  22. - (void)testApplyOptions_shouldSetBackButtonColor_withDefaultValues {
  23. [[(id)_boundViewController expect] setBackButtonColor:nil];
  24. [self.uut applyOptions:self.options];
  25. [(id)_boundViewController verify];
  26. }
  27. - (void)testApplyOptions_shouldSetBackButtonColor_withColor {
  28. self.options.topBar.backButton.color = [[Color alloc] initWithValue:[UIColor redColor]];
  29. [[(id)_boundViewController expect] setBackButtonColor:[UIColor redColor]];
  30. [self.uut applyOptions:self.options];
  31. [(id)_boundViewController verify];
  32. }
  33. - (void)testApplyOptionsBeforePoppingShouldSetTopBarBackgroundForPoppingViewController {
  34. _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
  35. [self.uut applyOptionsBeforePopping:self.options];
  36. XCTAssertTrue([_boundViewController.childViewControllers.lastObject.navigationItem.standardAppearance.backgroundColor isEqual:[UIColor redColor]]);
  37. }
  38. - (void)testApplyOptionsShouldSetLargeTitleVisible {
  39. _options.topBar.largeTitle.visible = [[Bool alloc] initWithBOOL:YES];
  40. [self.uut applyOptions:self.options];
  41. XCTAssertTrue([[_boundViewController navigationBar] prefersLargeTitles]);
  42. }
  43. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withTitle {
  44. Text* title = [[Text alloc] initWithValue:@"Title"];
  45. self.options.topBar.backButton.title = title;
  46. [self.uut applyOptions:self.options];
  47. XCTAssertTrue([self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title isEqual:@"Title"]);
  48. }
  49. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withHideTitle {
  50. Text* title = [[Text alloc] initWithValue:@"Title"];
  51. self.options.topBar.backButton.title = title;
  52. self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)];
  53. [self.uut applyOptions:self.options];
  54. NSLog(@"%@", self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title);
  55. XCTAssertTrue([self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title isEqualToString:@""]);
  56. }
  57. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withDefaultValues {
  58. [self.uut applyOptions:self.options];
  59. XCTAssertTrue(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title == nil);
  60. }
  61. - (void)testSetBackButtonIcon_withColor_shouldSetColor {
  62. Color* color = [[Color alloc] initWithValue:UIColor.redColor];
  63. self.options.topBar.backButton.color = color;
  64. [self.uut applyOptions:self.options];
  65. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
  66. }
  67. - (void)testSetBackButtonIcon_withColor_shouldSetTitle {
  68. Color* color = [[Color alloc] initWithValue:UIColor.redColor];
  69. Text* title = [[Text alloc] initWithValue:@"Title"];
  70. self.options.topBar.backButton.color = color;
  71. self.options.topBar.backButton.title = title;
  72. [self.uut applyOptions:self.options];
  73. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
  74. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title, @"Title");
  75. }
  76. - (void)testSetBackButtonIcon_withColor_shouldSetIcon {
  77. Color* color = [[Color alloc] initWithValue:UIColor.redColor];
  78. UIImage *image = [UIImage emptyImage];
  79. Image* icon = [[Image alloc] initWithValue:image];
  80. self.options.topBar.backButton.color = color;
  81. self.options.topBar.backButton.icon = icon;
  82. [self.uut applyOptions:self.options];
  83. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
  84. XCTAssertTrue([self.boundViewController.viewControllers.lastObject.navigationItem.standardAppearance.backIndicatorImage isEqual:image]);
  85. }
  86. - (void)testBackgroundColor_validColor {
  87. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  88. self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
  89. [self.uut applyOptions:self.options];
  90. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  91. XCTAssertTrue([self.boundViewController.view.backgroundColor isEqual:expectedColor]);
  92. }
  93. @end