react-native-navigation的迁移库

RNNBottomTabPresenterTest.m 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #import <XCTest/XCTest.h>
  2. #import "RNNBottomTabPresenter.h"
  3. #import <OCMock/OCMock.h>
  4. #import "UIViewController+RNNOptions.h"
  5. @interface RNNBottomTabPresenterTest : XCTestCase
  6. @property (nonatomic, strong) RNNBottomTabPresenter *uut;
  7. @property (nonatomic, strong) RNNNavigationOptions *options;
  8. @property (nonatomic, strong) id bindedViewController;
  9. @end
  10. @implementation RNNBottomTabPresenterTest
  11. - (void)setUp {
  12. [super setUp];
  13. self.uut = [[RNNBottomTabPresenter alloc] init];
  14. self.bindedViewController = [OCMockObject partialMockForObject:[UIViewController new]];
  15. [self.uut bindViewController:self.bindedViewController];
  16. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  17. }
  18. - (void)testApplyOptions_shouldSetTabBarItemBadgeWithDefaultWhenParentIsUITabBarController {
  19. UITabBarController* tabBarController = [[UITabBarController alloc] init];
  20. [tabBarController setViewControllers:@[self.bindedViewController]];
  21. [[self.bindedViewController expect] rnn_setTabBarItemBadge:nil];
  22. [self.uut applyOptions:self.options];
  23. [self.bindedViewController verify];
  24. }
  25. - (void)testApplyOptions_shouldSetTabBarItemBadgeOnlyWhenParentIsUITabBarController {
  26. [[self.bindedViewController reject] rnn_setTabBarItemBadge:[OCMArg any]];
  27. [self.uut applyOptions:self.options];
  28. [self.bindedViewController verify];
  29. }
  30. - (void)testApplyOptions_shouldSetTabBarItemBadgeWithValue {
  31. UITabBarController* tabBarController = [[UITabBarController alloc] init];
  32. [tabBarController setViewControllers:@[self.bindedViewController]];
  33. self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
  34. [[self.bindedViewController expect] rnn_setTabBarItemBadge:@"badge"];
  35. [self.uut applyOptions:self.options];
  36. [self.bindedViewController verify];
  37. }
  38. - (void)testApplyOptions_setTabBarItemBadgeShouldNotCalledOnUITabBarController {
  39. self.bindedViewController = [OCMockObject partialMockForObject:[UITabBarController new]];
  40. [self.uut bindViewController:self.bindedViewController];
  41. self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
  42. [[self.bindedViewController reject] rnn_setTabBarItemBadge:@"badge"];
  43. [self.uut applyOptions:self.options];
  44. [self.bindedViewController verify];
  45. }
  46. //- (void)test_tabBarTextFontFamily_validFont {
  47. // UIViewController* viewController = [UIViewController new];
  48. //
  49. // NSString* inputFont = @"HelveticaNeue";
  50. // UIFont* expectedFont = [UIFont fontWithName:inputFont size:10];
  51. //
  52. // self.uut.fontFamily = inputFont;
  53. // self.uut.text = @"Tab 1";
  54. //
  55. // [self.uut rnn_set];
  56. //
  57. // NSDictionary* attributes = [viewController.tabBarItem titleTextAttributesForState:UIControlStateNormal];
  58. // XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  59. //}
  60. //- (void)test_tabBarTextFontSize_withoutTextFontFamily_withoutTextColor {
  61. // UIViewController* viewController = [UIViewController new];
  62. //
  63. // UIFont* expectedFont = [UIFont systemFontOfSize:15];
  64. //
  65. // self.uut.fontSize = @(15);
  66. // self.uut.text = @"Tab 1";
  67. //
  68. // [self.uut applyOn:viewController];
  69. //
  70. // NSDictionary* attributes = [viewController.tabBarItem titleTextAttributesForState:UIControlStateNormal];
  71. // XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  72. //}
  73. //
  74. //- (void)test_tabBarTextFontSize_withoutTextFontFamily {
  75. // UIViewController* viewController = [UIViewController new];
  76. //
  77. // UIFont* expectedFont = [UIFont systemFontOfSize:15];
  78. //
  79. // self.uut.fontSize = @(15);
  80. // self.uut.text = @"Tab 1";
  81. //
  82. // [self.uut applyOn:viewController];
  83. //
  84. // NSDictionary* attributes = [viewController.tabBarItem titleTextAttributesForState:UIControlStateNormal];
  85. // XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  86. //}
  87. //
  88. //- (void)test_tabBarTextFontSize_withTextFontFamily_withTextColor {
  89. // UIViewController* viewController = [UIViewController new];
  90. //
  91. // NSString* inputFont = @"HelveticaNeue";
  92. // UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
  93. //
  94. // self.uut.fontSize = @(15);
  95. // self.uut.text = @"Tab 1";
  96. // self.uut.fontFamily = inputFont;
  97. // self.uut.textColor = @(4279979127);
  98. // [self.uut applyOn:viewController];
  99. //
  100. // NSDictionary* attributes = [viewController.tabBarItem titleTextAttributesForState:UIControlStateNormal];
  101. // UIColor* color = attributes[NSForegroundColorAttributeName];
  102. // UIColor* expectedColor = [RCTConvert UIColor:@(4279979127)];
  103. //
  104. // XCTAssertTrue([color isEqual:expectedColor]);
  105. // XCTAssertTrue([attributes[@"NSFont"] isEqual:expectedFont]);
  106. //}
  107. @end