react-native-navigation的迁移库

RNNSideMenuControllerTest.m 4.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #import <XCTest/XCTest.h>
  2. #import "RNNSideMenuController.h"
  3. #import "RNNComponentViewController.h"
  4. #import "RNNTestRootViewCreator.h"
  5. @interface RNNSideMenuControllerTest : XCTestCase
  6. @property (nonatomic, strong) RNNSideMenuController *uut;
  7. @property (nonatomic, strong) RNNTestRootViewCreator *creator;
  8. @property (nonatomic, strong) RNNSideMenuChildVC *centerVC;
  9. @property (nonatomic, strong) RNNSideMenuChildVC *leftVC;
  10. @property (nonatomic, strong) RNNSideMenuChildVC *rightVC;
  11. @end
  12. @implementation RNNSideMenuControllerTest
  13. - (void)setUp {
  14. [super setUp];
  15. _creator = [[RNNTestRootViewCreator alloc] init];
  16. _leftVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:[RNNBasePresenter new] eventEmitter:nil childViewController:self.generateComponent type:RNNSideMenuChildTypeLeft];
  17. [_leftVC.presenter bindViewController:_leftVC];
  18. _rightVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:[RNNBasePresenter new] eventEmitter:nil childViewController:self.generateComponent type:RNNSideMenuChildTypeRight];
  19. [_rightVC.presenter bindViewController:_rightVC];
  20. _centerVC =[[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:[RNNBasePresenter new] eventEmitter:nil childViewController:self.generateComponent type:RNNSideMenuChildTypeCenter];
  21. [_centerVC.presenter bindViewController:_centerVC];
  22. self.uut = [[RNNSideMenuController alloc] initWithLayoutInfo:nil creator:nil childViewControllers:@[_leftVC, _centerVC, _rightVC] options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:[[RNNSideMenuPresenter alloc] initWithDefaultOptions:nil] eventEmitter:nil];
  23. }
  24. - (RNNComponentViewController *)generateComponent {
  25. return [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:_creator eventEmitter:nil presenter:[RNNComponentPresenter new] options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil];
  26. }
  27. - (void)testSetSideMenuWidthShouldUpdateLeftReactViewFrameWidth {
  28. [self.uut side:MMDrawerSideLeft width:100];
  29. XCTAssertEqual(self.uut.left.child.view.frame.size.width, 100.f);
  30. }
  31. - (void)testSetSideMenuWidthShouldUpdateRightReactViewFrameWidth {
  32. [self.uut side:MMDrawerSideRight width:150];
  33. XCTAssertEqual(self.uut.right.child.view.frame.size.width, 150.f);
  34. }
  35. - (void)testGetCurrentChild {
  36. XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"];
  37. XCTAssertEqual(_uut.getCurrentChild, _centerVC);
  38. [_uut openDrawerSide:MMDrawerSideLeft animated:NO completion:(void (^)(BOOL)) ^{
  39. XCTAssertEqual(_uut.getCurrentChild, _leftVC);
  40. }];
  41. [_uut closeDrawerAnimated:NO completion:nil];
  42. [_uut openDrawerSide:MMDrawerSideRight animated:NO completion:(void (^)(BOOL)) ^{
  43. XCTAssertEqual(_uut.getCurrentChild, _rightVC);
  44. [expectation fulfill];
  45. }];
  46. [self waitForExpectationsWithTimeout:1 handler:nil];
  47. }
  48. - (void)testResolveOptions {
  49. XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"];
  50. RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions];
  51. options.sideMenu.left.visible = [[Bool alloc] initWithBOOL:YES];
  52. [_centerVC overrideOptions:options];
  53. XCTAssertTrue(_uut.resolveOptions.sideMenu.left.visible);
  54. [_uut openDrawerSide:MMDrawerSideLeft animated:NO completion:^(BOOL finished) {
  55. XCTAssertTrue(_uut.resolveOptions.sideMenu.left.visible);
  56. [expectation fulfill];
  57. }];
  58. [self waitForExpectationsWithTimeout:1 handler:nil];
  59. }
  60. - (void)testPreferredStatusHidden_shouldResolveChildStatusBarVisibleTrue {
  61. self.uut.getCurrentChild.options.statusBar.visible = [Bool withValue:@(1)];
  62. XCTAssertFalse(self.uut.prefersStatusBarHidden);
  63. }
  64. - (void)testPreferredStatusHidden_shouldResolveChildStatusBarVisibleFalse {
  65. self.uut.getCurrentChild.options.statusBar.visible = [Bool withValue:@(0)];
  66. XCTAssertTrue(self.uut.prefersStatusBarHidden);
  67. }
  68. - (void)testPreferredStatusHidden_shouldHideStatusBar {
  69. self.uut.options.statusBar.visible = [Bool withValue:@(1)];
  70. XCTAssertFalse(self.uut.prefersStatusBarHidden);
  71. }
  72. - (void)testPreferredStatusHidden_shouldShowStatusBar {
  73. self.uut.options.statusBar.visible = [Bool withValue:@(0)];
  74. XCTAssertTrue(self.uut.prefersStatusBarHidden);
  75. }
  76. @end