react-native-navigation的迁移库

RNNStackPresenterTest.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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)testApplyOptionsBeforePoppingShouldSetTopBarBackgroundForPoppingViewController {
  23. _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
  24. [self.uut applyOptionsBeforePopping:self.options];
  25. XCTAssertFalse([_boundViewController.childViewControllers.lastObject.navigationItem.standardAppearance.backgroundColor isEqual:[UIColor redColor]]);
  26. }
  27. - (void)testApplyOptionsShouldSetLargeTitleVisible {
  28. _options.topBar.largeTitle.visible = [[Bool alloc] initWithBOOL:YES];
  29. [self.uut applyOptions:self.options];
  30. XCTAssertTrue([[_boundViewController navigationBar] prefersLargeTitles]);
  31. }
  32. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withTitle {
  33. Text* title = [[Text alloc] initWithValue:@"Title"];
  34. self.options.topBar.backButton.title = title;
  35. [self.uut applyOptions:self.options];
  36. XCTAssertTrue([self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title isEqual:@"Title"]);
  37. }
  38. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withHideTitle {
  39. Text* title = [[Text alloc] initWithValue:@"Title"];
  40. self.options.topBar.backButton.title = title;
  41. self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)];
  42. [self.uut applyOptions:self.options];
  43. NSLog(@"%@", self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title);
  44. XCTAssertTrue([self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title isEqualToString:@""]);
  45. }
  46. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withDefaultValues {
  47. [self.uut applyOptions:self.options];
  48. XCTAssertTrue(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title == nil);
  49. }
  50. - (void)testSetBackButtonIcon_withColor_shouldSetColor {
  51. Color* color = [[Color alloc] initWithValue:UIColor.redColor];
  52. self.options.topBar.backButton.color = color;
  53. [self.uut applyOptions:self.options];
  54. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
  55. }
  56. - (void)testSetBackButtonIcon_withColor_shouldSetTitle {
  57. Color* color = [[Color alloc] initWithValue:UIColor.redColor];
  58. Text* title = [[Text alloc] initWithValue:@"Title"];
  59. self.options.topBar.backButton.color = color;
  60. self.options.topBar.backButton.title = title;
  61. [self.uut applyOptions:self.options];
  62. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
  63. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title, @"Title");
  64. }
  65. - (void)testSetBackButtonIcon_withColor_shouldSetIcon {
  66. Color* color = [[Color alloc] initWithValue:UIColor.redColor];
  67. UIImage *image = [UIImage emptyImage];
  68. Image* icon = [[Image alloc] initWithValue:image];
  69. self.options.topBar.backButton.color = color;
  70. self.options.topBar.backButton.icon = icon;
  71. [self.uut applyOptions:self.options];
  72. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
  73. XCTAssertTrue([self.boundViewController.viewControllers.lastObject.navigationItem.standardAppearance.backIndicatorImage isEqual:image]);
  74. }
  75. - (void)testBackgroundColor_validColor {
  76. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  77. self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
  78. [self.uut applyOptions:self.options];
  79. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  80. XCTAssertTrue([self.boundViewController.view.backgroundColor isEqual:expectedColor]);
  81. }
  82. @end