feat(SwipeCell): add open event (#4986)

This commit is contained in:
neverland
2019-11-12 21:03:48 +08:00
committed by GitHub
parent 2c6b5408d3
commit 9d21b53731
4 changed files with 35 additions and 3 deletions
+28 -3
View File
@@ -1,5 +1,10 @@
import SwipeCell from '..';
import { mount, triggerDrag, later, mockGetBoundingClientRect } from '../../../test/utils';
import {
mount,
triggerDrag,
later,
mockGetBoundingClientRect
} from '../../../test/utils';
const THRESHOLD = 0.15;
const defaultProps = {
@@ -92,7 +97,7 @@ it('name prop', done => {
it('should reset after drag', () => {
const wrapper = mount(SwipeCell, defaultProps);
triggerDrag(wrapper, (defaultProps.leftWidth * THRESHOLD - 1), 0);
triggerDrag(wrapper, defaultProps.leftWidth * THRESHOLD - 1, 0);
expect(wrapper.vm.offset).toEqual(0);
});
@@ -100,7 +105,7 @@ it('disabled prop', () => {
const wrapper = mount(SwipeCell, {
propsData: {
...defaultProps.propsData,
disabled: true,
disabled: true
}
});
@@ -141,3 +146,23 @@ it('render one side', async () => {
restoreMock();
});
it('trigger open event when open left side', () => {
const wrapper = mount(SwipeCell, defaultProps);
triggerDrag(wrapper, 50, 0);
expect(wrapper.emitted('open')[0][0]).toEqual({
detail: '',
position: 'left'
});
});
it('trigger open event when open right side', () => {
const wrapper = mount(SwipeCell, defaultProps);
triggerDrag(wrapper, -50, 0);
expect(wrapper.emitted('open')[0][0]).toEqual({
detail: '',
position: 'right'
});
});