[Improvement] CellSwipe: add test cases (#1193)

This commit is contained in:
neverland 2018-05-30 15:27:03 +08:00 committed by GitHub
parent 92c108e245
commit ee0055f24d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`drag and show left part 1`] = `
<div class="van-cell-swipe">
<div class="van-cell-swipe__wrapper">
<div class="van-cell-swipe__left"></div>
<div class="van-cell-swipe__right"></div>
</div>
</div>
`;
exports[`drag and show left part 2`] = `
<div class="van-cell-swipe">
<div class="van-cell-swipe__wrapper">
<div class="van-cell-swipe__left"></div>
<div class="van-cell-swipe__right"></div>
</div>
</div>
`;
exports[`drag and show left part 3`] = `
<div class="van-cell-swipe">
<div class="van-cell-swipe__wrapper">
<div class="van-cell-swipe__left"></div>
<div class="van-cell-swipe__right"></div>
</div>
</div>
`;
exports[`drag and show left part 4`] = `
<div class="van-cell-swipe">
<div class="van-cell-swipe__wrapper">
<div class="van-cell-swipe__left"></div>
<div class="van-cell-swipe__right"></div>
</div>
</div>
`;
exports[`drag and show left part 5`] = `
<div class="van-cell-swipe">
<div class="van-cell-swipe__wrapper">
<div class="van-cell-swipe__left"></div>
<div class="van-cell-swipe__right"></div>
</div>
</div>
`;

View File

@ -0,0 +1,67 @@
import CellSwipe from '..';
import { mount } from '@vue/test-utils';
import { triggerDrag } from '../../../test/utils';
const defaultProps = {
propsData: {
leftWidth: 100,
rightWidth: 100
}
};
it('drag and show left part', () => {
const wrapper = mount(CellSwipe, defaultProps);
triggerDrag(wrapper, 10, 0);
expect(wrapper.html()).toMatchSnapshot();
triggerDrag(wrapper, 50, 0);
expect(wrapper.html()).toMatchSnapshot();
triggerDrag(wrapper, 500, 0);
expect(wrapper.html()).toMatchSnapshot();
triggerDrag(wrapper, 0, 100);
expect(wrapper.html()).toMatchSnapshot();
});
it('drag and show left part', () => {
const wrapper = mount(CellSwipe, defaultProps);
triggerDrag(wrapper, -50, 0);
expect(wrapper.html()).toMatchSnapshot();
});
test('on close prop', () => {
let position;
let instance;
const wrapper = mount(CellSwipe, {
propsData: {
...defaultProps.propsData,
onClose(pos, ins) {
position = pos;
instance = ins;
}
}
});
wrapper.trigger('click');
expect(position).toEqual(undefined);
wrapper.setData({ offset: 100 });
wrapper.trigger('click');
expect(position).toEqual('cell');
wrapper.find('.van-cell-swipe__left').trigger('click');
expect(position).toEqual('left');
wrapper.find('.van-cell-swipe__right').trigger('click');
expect(position).toEqual('right');
instance.close();
expect(wrapper.vm.offset).toEqual(0);
wrapper.setData({ offset: 100, onClose: null });
wrapper.trigger('click');
expect(wrapper.vm.offset).toEqual(0);
});