react-native-navigation的迁移库

RNNStackPresenterTest.m 5.0KB

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