react-native-navigation的迁移库

RNNSideMenuPresenterTest.m 4.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "RNNSideMenuPresenter.h"
  4. #import "RNNSideMenuController.h"
  5. @interface RNNSideMenuPresenterTest : XCTestCase
  6. @property (nonatomic, strong) RNNSideMenuPresenter *uut;
  7. @property (nonatomic, strong) RNNNavigationOptions *options;
  8. @property (nonatomic, strong) id boundViewController;
  9. @end
  10. @implementation RNNSideMenuPresenterTest
  11. - (void)setUp {
  12. [super setUp];
  13. self.uut = [[RNNSideMenuPresenter alloc] init];
  14. self.boundViewController = [OCMockObject partialMockForObject:[[RNNSideMenuController alloc] initWithLayoutInfo:nil creator:nil childViewControllers:@[[self createChildVC:RNNSideMenuChildTypeCenter]] options:nil defaultOptions:nil presenter:nil eventEmitter:nil]];
  15. [self.uut bindViewController:self.boundViewController];
  16. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  17. }
  18. - (RNNSideMenuChildVC *)createChildVC:(RNNSideMenuChildType)type {
  19. return [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewController:[UIViewController new] type:type];
  20. }
  21. - (void)testApplyOptionsShouldSetDefaultValues {
  22. [[self.boundViewController expect] side:MMDrawerSideLeft enabled:YES];
  23. [[self.boundViewController expect] side:MMDrawerSideRight enabled:YES];
  24. [[self.boundViewController expect] setShouldStretchLeftDrawer:YES];
  25. [[self.boundViewController expect] setShouldStretchRightDrawer:YES];
  26. [[self.boundViewController expect] setAnimationVelocityLeft:840.0f];
  27. [[self.boundViewController expect] setAnimationVelocityRight:840.0f];
  28. [[self.boundViewController reject] side:MMDrawerSideLeft width:0];
  29. [[self.boundViewController reject] side:MMDrawerSideRight width:0];
  30. [[self.boundViewController expect] setAnimationType:nil];
  31. [self.uut applyOptions:self.options];
  32. [self.boundViewController verify];
  33. }
  34. - (void)testApplyOptionsShouldSetInitialValues {
  35. self.options.sideMenu.left.enabled = [[Bool alloc] initWithBOOL:NO];
  36. self.options.sideMenu.right.enabled = [[Bool alloc] initWithBOOL:NO];
  37. self.options.sideMenu.left.shouldStretchDrawer = [[Bool alloc] initWithBOOL:NO];
  38. self.options.sideMenu.right.shouldStretchDrawer = [[Bool alloc] initWithBOOL:NO];
  39. self.options.sideMenu.right.animationVelocity = [[Double alloc] initWithValue:@(100.0f)];
  40. self.options.sideMenu.left.animationVelocity = [[Double alloc] initWithValue:@(100.0f)];
  41. [[self.boundViewController expect] side:MMDrawerSideLeft enabled:NO];
  42. [[self.boundViewController expect] side:MMDrawerSideRight enabled:NO];
  43. [[self.boundViewController expect] setShouldStretchLeftDrawer:NO];
  44. [[self.boundViewController expect] setShouldStretchRightDrawer:NO];
  45. [[self.boundViewController expect] setAnimationVelocityLeft:100.0f];
  46. [[self.boundViewController expect] setAnimationVelocityRight:100.0f];
  47. [self.uut applyOptions:self.options];
  48. [self.boundViewController verify];
  49. }
  50. - (void)testApplyOptionsOnInitShouldSetWidthOptions {
  51. self.options.sideMenu.right.width = [[Double alloc] initWithValue:@(100.0f)];
  52. self.options.sideMenu.left.width = [[Double alloc] initWithValue:@(100.0f)];
  53. [[self.boundViewController expect] side:MMDrawerSideLeft width:100.0f];
  54. [[self.boundViewController expect] side:MMDrawerSideRight width:100.0f];
  55. [self.uut applyOptionsOnInit:self.options];
  56. [self.boundViewController verify];
  57. }
  58. - (void)testApplyOptionsOnInitShouldSetDefaultDrawerGestureMode {
  59. [[self.boundViewController expect] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
  60. [self.uut applyOptionsOnInit:self.options];
  61. [self.boundViewController verify];
  62. }
  63. - (void)testApplyOptionsOnInitShouldSetBezelDrawerGestureMode {
  64. self.options.sideMenu.openGestureMode = [[SideMenuOpenMode alloc] initWithValue:@(MMOpenDrawerGestureModeNone)];
  65. [[self.boundViewController expect] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
  66. [self.uut applyOptionsOnInit:self.options];
  67. [self.boundViewController verify];
  68. }
  69. - (void)testBackgroundColor_validColor {
  70. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  71. self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
  72. [self.uut applyOptions:self.options];
  73. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  74. XCTAssertTrue([((UIViewController *)self.boundViewController).view.backgroundColor isEqual:expectedColor]);
  75. }
  76. @end