react-native-navigation的迁移库

RNNNavigationControllerTest.m 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #import <XCTest/XCTest.h>
  2. #import "RNNNavigationController.h"
  3. #import "RNNRootViewController.h"
  4. @interface RNNNavigationControllerTest : XCTestCase
  5. @property (nonatomic, strong) RNNNavigationController *uut;
  6. @end
  7. @implementation RNNNavigationControllerTest {
  8. RNNRootViewController* _vc1;
  9. RNNRootViewController* _vc2;
  10. UIViewController* _vc3;
  11. }
  12. - (void)setUp {
  13. [super setUp];
  14. _vc1 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions]];
  15. _vc2 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:nil];
  16. _vc3 = [UIViewController new];
  17. self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1, _vc2] options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
  18. }
  19. - (void)testInitWithLayoutInfo_shouldBindPresenter {
  20. XCTAssertNotNil(self.uut.presenter);
  21. }
  22. - (void)testInitWithLayoutInfo_shouldSetMultipleViewControllers {
  23. self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1, _vc2] options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
  24. XCTAssertTrue(self.uut.viewControllers.count == 2);
  25. }
  26. - (void)testChildViewControllerForStatusBarStyle_shouldReturnTopViewController {
  27. XCTAssertTrue(self.uut.childViewControllerForStatusBarStyle == self.uut.topViewController);
  28. }
  29. - (void)testGetLeafViewController_shouldReturnTopViewController {
  30. XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
  31. }
  32. - (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle {
  33. self.uut.getCurrentChild.options.statusBar.style = [[Text alloc] initWithValue:@"light"];
  34. XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getCurrentChild.preferredStatusBarStyle);
  35. }
  36. - (void)testPopGestureEnabled_false {
  37. NSNumber* popGestureEnabled = @(0);
  38. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  39. options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled];
  40. self.uut = [self createNavigationControllerWithOptions:options];
  41. [self.uut viewWillAppear:false];
  42. XCTAssertFalse(self.uut.interactivePopGestureRecognizer.enabled);
  43. }
  44. - (void)testPopGestureEnabled_true {
  45. NSNumber* popGestureEnabled = @(1);
  46. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  47. options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled];
  48. self.uut = [self createNavigationControllerWithOptions:options];
  49. [self.uut onChildWillAppear];
  50. XCTAssertTrue(self.uut.interactivePopGestureRecognizer.enabled);
  51. }
  52. - (void)testRootBackgroundImage {
  53. UIImage* rootBackgroundImage = [[UIImage alloc] init];
  54. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  55. options.rootBackgroundImage = [[Image alloc] initWithValue:rootBackgroundImage];
  56. self.uut = [self createNavigationControllerWithOptions:options];
  57. [self.uut onChildWillAppear];
  58. XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:rootBackgroundImage]);
  59. }
  60. - (void)testTopBarBackgroundClipToBounds_true {
  61. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  62. options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(1)];
  63. self.uut = [self createNavigationControllerWithOptions:options];
  64. [self.uut onChildWillAppear];
  65. XCTAssertTrue(self.uut.navigationBar.clipsToBounds);
  66. }
  67. - (void)testTopBarBackgroundClipToBounds_false {
  68. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  69. options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(0)];
  70. self.uut = [self createNavigationControllerWithOptions:options];
  71. XCTAssertFalse(self.uut.navigationController.navigationBar.clipsToBounds);
  72. }
  73. - (void)testTabBarItemShouldReturnFirstChildTabBarItem {
  74. XCTAssertEqual(self.uut.tabBarItem, self.uut.childViewControllers.firstObject.tabBarItem);
  75. }
  76. - (void)testSupportedOrientationsShouldReturnCurrentChildSupportedOrientations {
  77. XCTAssertEqual(self.uut.supportedInterfaceOrientations, self.uut.getCurrentChild.supportedInterfaceOrientations);
  78. }
  79. - (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
  80. return [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1] options:options presenter:[[RNNNavigationControllerPresenter alloc] init]];
  81. }
  82. @end