react-native-navigation的迁移库

RNNStackPresenterTest.m 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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)testApplyOptionsBeforePoppingShouldSetLargeTitleForPoppingViewController {
  38. _options.topBar.largeTitle.visible = [[Bool alloc] initWithBOOL:YES];
  39. [self.uut applyOptionsBeforePopping:self.options];
  40. XCTAssertTrue([[_boundViewController navigationBar] prefersLargeTitles]);
  41. }
  42. - (void)testApplyOptionsBeforePoppingShouldSetDefaultLargeTitleFalseForPoppingViewController {
  43. _options.topBar.largeTitle.visible = nil;
  44. [self.uut applyOptionsBeforePopping:self.options];
  45. XCTAssertFalse([[_boundViewController navigationBar] prefersLargeTitles]);
  46. }
  47. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withTitle {
  48. Text* title = [[Text alloc] initWithValue:@"Title"];
  49. self.options.topBar.backButton.title = title;
  50. [self.uut applyOptions:self.options];
  51. XCTAssertTrue([self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title isEqual:@"Title"]);
  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. [self.uut applyOptions:self.options];
  58. XCTAssertNil(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title);
  59. }
  60. - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withDefaultValues {
  61. [self.uut applyOptions:self.options];
  62. XCTAssertTrue(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title == nil);
  63. }
  64. - (void)testSetBackButtonIcon_withColor_shouldSetColor {
  65. Color* color = [[Color alloc] initWithValue:UIColor.redColor];
  66. self.options.topBar.backButton.color = color;
  67. [self.uut applyOptions:self.options];
  68. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
  69. }
  70. - (void)testSetBackButtonIcon_withColor_shouldSetTitle {
  71. Color* color = [[Color alloc] initWithValue:UIColor.redColor];
  72. Text* title = [[Text alloc] initWithValue:@"Title"];
  73. self.options.topBar.backButton.color = color;
  74. self.options.topBar.backButton.title = title;
  75. [self.uut applyOptions:self.options];
  76. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
  77. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title, @"Title");
  78. }
  79. - (void)testSetBackButtonIcon_withColor_shouldSetIcon {
  80. Color* color = [[Color alloc] initWithValue:UIColor.redColor];
  81. UIImage *image = [UIImage emptyImage];
  82. Image* icon = [[Image alloc] initWithValue:image];
  83. self.options.topBar.backButton.color = color;
  84. self.options.topBar.backButton.icon = icon;
  85. [self.uut applyOptions:self.options];
  86. XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
  87. XCTAssertTrue([self.boundViewController.navigationBar.standardAppearance.backIndicatorImage isEqual:image]);
  88. }
  89. @end