react-native-navigation的迁移库

BottomTabPresenterTest.m 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #import <XCTest/XCTest.h>
  2. #import "RNNBasePresenter.h"
  3. #import <OCMock/OCMock.h>
  4. #import "UIViewController+RNNOptions.h"
  5. #import <ReactNativeNavigation/RNNComponentViewController.h>
  6. #import <ReactNativeNavigation/BottomTabAppearancePresenter.h>
  7. #import "RNNBottomTabsController+Helpers.h"
  8. @interface RNNBottomTabPresenterTest : XCTestCase
  9. @property(nonatomic, strong) BottomTabAppearancePresenter *uut;
  10. @property(nonatomic, strong) RNNNavigationOptions *options;
  11. @property(nonatomic, strong) RNNBottomTabsController *boundViewController;
  12. @property(nonatomic, strong) RNNComponentViewController *componentViewController;
  13. @property(nonatomic, strong) id mockBoundViewController;
  14. @end
  15. @implementation RNNBottomTabPresenterTest
  16. - (void)setUp {
  17. [super setUp];
  18. self.uut = [[BottomTabAppearancePresenter alloc] initWithDefaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
  19. self.componentViewController = [RNNComponentViewController new];
  20. self.boundViewController = [RNNBottomTabsController createWithChildren:@[self.componentViewController]];
  21. self.mockBoundViewController = [OCMockObject partialMockForObject:self.boundViewController];
  22. [self.uut bindViewController:self.mockBoundViewController];
  23. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  24. }
  25. - (void)tearDown {
  26. [super tearDown];
  27. [self.mockBoundViewController stopMocking];
  28. self.boundViewController = nil;
  29. }
  30. - (void)testApplyOptions_shouldSetTabBarItemBadgeWithValue {
  31. self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
  32. [self.uut applyOptions:self.options child:self.componentViewController];
  33. XCTAssertEqual(self.componentViewController.tabBarItem.badgeValue, @"badge");
  34. }
  35. - (void)testMergeOptions_shouldSetTabBarItemColorWithDefaultOptions {
  36. RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  37. defaultOptions.bottomTab.selectedIconColor = [Color withColor:UIColor.greenColor];
  38. self.uut.defaultOptions = defaultOptions;
  39. RNNNavigationOptions* mergeOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  40. mergeOptions.bottomTab.text = [[Text alloc] initWithValue:@"title"];
  41. [self.uut mergeOptions:mergeOptions resolvedOptions:self.options child:self.componentViewController];
  42. XCTAssertEqual(self.componentViewController.tabBarItem.title, @"title");
  43. }
  44. - (void)testMergeOptions_shouldCreateNewTabBarItemInstance {
  45. RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  46. defaultOptions.bottomTab.selectedIconColor = [Color withColor:UIColor.greenColor];
  47. self.uut.defaultOptions = defaultOptions;
  48. RNNNavigationOptions* mergeOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  49. mergeOptions.bottomTab.text = [[Text alloc] initWithValue:@"title"];
  50. UITabBarItem* currentTabBarItem = self.componentViewController.tabBarItem;
  51. [self.uut mergeOptions:mergeOptions resolvedOptions:self.options child:self.componentViewController];
  52. UITabBarItem* newTabBarItem = self.componentViewController.tabBarItem;
  53. XCTAssertNotEqual(currentTabBarItem, newTabBarItem);
  54. }
  55. @end