react-native-navigation的迁移库

RNNNavigationControllerTest.m 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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] 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 = rootBackgroundImage;
  56. //
  57. // self.uut = [self createNavigationControllerWithOptions:options];
  58. // [self.uut viewWillAppear:false];
  59. //
  60. // XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:rootBackgroundImage]);
  61. //}
  62. - (void)testTopBarBackgroundClipToBounds_true {
  63. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  64. options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(1)];
  65. self.uut = [self createNavigationControllerWithOptions:options];
  66. [self.uut onChildWillAppear];
  67. XCTAssertTrue(self.uut.navigationBar.clipsToBounds);
  68. }
  69. - (void)testTopBarBackgroundClipToBounds_false {
  70. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  71. options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(0)];
  72. self.uut = [self createNavigationControllerWithOptions:options];
  73. XCTAssertFalse(self.uut.navigationController.navigationBar.clipsToBounds);
  74. }
  75. - (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
  76. return [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1] options:options presenter:[[RNNNavigationControllerPresenter alloc] init]];
  77. }
  78. @end