[bugfix] ImagePreview: wrong index (#1961)

This commit is contained in:
neverland
2018-10-24 21:11:37 +08:00
committed by GitHub
parent 4b63a62822
commit d0b8595b50
6 changed files with 188 additions and 1923 deletions

View File

@@ -1,7 +1,16 @@
import Vue from 'vue';
import ImagePreview from '..';
import ImagePreviewVue from '../ImagePreview';
import { mount, triggerDrag } from '../../../test/utils';
import { mount, trigger, triggerDrag } from '../../../test/utils';
function triggerZoom(el, x, y) {
trigger(el, 'touchstart', 0, 0, { x, y });
trigger(el, 'touchmove', -x / 4, -y / 4, { x, y });
trigger(el, 'touchmove', -x / 3, -y / 3, { x, y });
trigger(el, 'touchmove', -x / 2, -y / 2, { x, y });
trigger(el, 'touchmove', -x, -y, { x, y });
trigger(el, 'touchend', 0, 0, { touchList: [] });
}
const images = [
'https://img.yzcdn.cn/1.png',
@@ -60,3 +69,18 @@ test('register component', () => {
Vue.use(ImagePreview);
expect(Vue.component(ImagePreviewVue.name)).toBeTruthy();
});
test('zoom', async() => {
const getBoundingClientRect = Element.prototype.getBoundingClientRect;
Element.prototype.getBoundingClientRect = jest.fn(() => ({ width: 100 }));
const wrapper = mount(ImagePreviewVue, {
propsData: { images, value: true }
});
const image = wrapper.find('img');
triggerZoom(image, 300, 300);
triggerDrag(image, 300, 300);
expect(wrapper).toMatchSnapshot();
Element.prototype.getBoundingClientRect = getBoundingClientRect;
});