react-native-navigation的迁移库

RNNSideMenuPresenterTest.m 3.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 new]];
  15. [self.uut bindViewController:self.boundViewController];
  16. self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
  17. }
  18. - (void)testApplyOptionsShouldSetDefaultValues {
  19. [[self.boundViewController expect] side:MMDrawerSideLeft enabled:YES];
  20. [[self.boundViewController expect] side:MMDrawerSideRight enabled:YES];
  21. [[self.boundViewController expect] setShouldStretchLeftDrawer:YES];
  22. [[self.boundViewController expect] setShouldStretchRightDrawer:YES];
  23. [[self.boundViewController expect] setAnimationVelocityLeft:840.0f];
  24. [[self.boundViewController expect] setAnimationVelocityRight:840.0f];
  25. [[self.boundViewController reject] side:MMDrawerSideLeft width:0];
  26. [[self.boundViewController reject] side:MMDrawerSideRight width:0];
  27. [[self.boundViewController expect] setAnimationType:nil];
  28. [self.uut applyOptions:self.options];
  29. [self.boundViewController verify];
  30. }
  31. - (void)testApplyOptionsShouldSetInitialValues {
  32. self.options.sideMenu.left.enabled = [[Bool alloc] initWithBOOL:NO];
  33. self.options.sideMenu.right.enabled = [[Bool alloc] initWithBOOL:NO];
  34. self.options.sideMenu.left.shouldStretchDrawer = [[Bool alloc] initWithBOOL:NO];
  35. self.options.sideMenu.right.shouldStretchDrawer = [[Bool alloc] initWithBOOL:NO];
  36. self.options.sideMenu.right.animationVelocity = [[Double alloc] initWithValue:@(100.0f)];
  37. self.options.sideMenu.left.animationVelocity = [[Double alloc] initWithValue:@(100.0f)];
  38. [[self.boundViewController expect] side:MMDrawerSideLeft enabled:NO];
  39. [[self.boundViewController expect] side:MMDrawerSideRight enabled:NO];
  40. [[self.boundViewController expect] setShouldStretchLeftDrawer:NO];
  41. [[self.boundViewController expect] setShouldStretchRightDrawer:NO];
  42. [[self.boundViewController expect] setAnimationVelocityLeft:100.0f];
  43. [[self.boundViewController expect] setAnimationVelocityRight:100.0f];
  44. [self.uut applyOptions:self.options];
  45. [self.boundViewController verify];
  46. }
  47. - (void)testApplyOptionsOnInitShouldSetWidthOptions {
  48. self.options.sideMenu.right.width = [[Double alloc] initWithValue:@(100.0f)];
  49. self.options.sideMenu.left.width = [[Double alloc] initWithValue:@(100.0f)];
  50. [[self.boundViewController expect] side:MMDrawerSideLeft width:100.0f];
  51. [[self.boundViewController expect] side:MMDrawerSideRight width:100.0f];
  52. [self.uut applyOptionsOnInit:self.options];
  53. [self.boundViewController verify];
  54. }
  55. - (void)testApplyOptionsOnInitShouldSetDefaultDrawerGestureMode {
  56. [[self.boundViewController expect] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
  57. [self.uut applyOptionsOnInit:self.options];
  58. [self.boundViewController verify];
  59. }
  60. - (void)testApplyOptionsOnInitShouldSetBezelDrawerGestureMode {
  61. self.options.sideMenu.openGestureMode = [[SideMenuOpenMode alloc] initWithValue:@(MMOpenDrawerGestureModeNone)];
  62. [[self.boundViewController expect] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
  63. [self.uut applyOptionsOnInit:self.options];
  64. [self.boundViewController verify];
  65. }
  66. - (void)testBackgroundColor_validColor {
  67. UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
  68. self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
  69. [self.uut applyOptions:self.options];
  70. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  71. XCTAssertTrue([((UIViewController *)self.boundViewController).view.backgroundColor isEqual:expectedColor]);
  72. }
  73. @end