|
|
@ -1,5 +1,6 @@
|
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { asyncExpect } from '@/tests/utils';
|
|
|
|
import { h, createVNode } from 'vue';
|
|
|
|
|
|
|
|
import { asyncExpect, sleep } from '@/tests/utils';
|
|
|
|
import Carousel from '..';
|
|
|
|
import Carousel from '..';
|
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
|
|
|
|
|
|
|
|
|
@ -15,13 +16,13 @@ describe('Carousel', () => {
|
|
|
|
it('should has innerSlider', () => {
|
|
|
|
it('should has innerSlider', () => {
|
|
|
|
const props = {
|
|
|
|
const props = {
|
|
|
|
slots: {
|
|
|
|
slots: {
|
|
|
|
default: '<div />',
|
|
|
|
default: () => h('div'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sync: false,
|
|
|
|
sync: false,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const wrapper = mount(Carousel, props);
|
|
|
|
const wrapper = mount(Carousel, props);
|
|
|
|
const { innerSlider, $refs } = wrapper.vm;
|
|
|
|
const { innerSlider, slick } = wrapper.vm;
|
|
|
|
const innerSliderFromRefs = $refs.slick.innerSlider;
|
|
|
|
const innerSliderFromRefs = slick.innerSlider;
|
|
|
|
expect(innerSlider).toBe(innerSliderFromRefs);
|
|
|
|
expect(innerSlider).toBe(innerSliderFromRefs);
|
|
|
|
expect(typeof innerSlider.slickNext).toBe('function');
|
|
|
|
expect(typeof innerSlider.slickNext).toBe('function');
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -29,7 +30,11 @@ describe('Carousel', () => {
|
|
|
|
it('should has prev, next and go function', async () => {
|
|
|
|
it('should has prev, next and go function', async () => {
|
|
|
|
const props = {
|
|
|
|
const props = {
|
|
|
|
slots: {
|
|
|
|
slots: {
|
|
|
|
default: '<div>1</div><div>2</div><div>3</div>',
|
|
|
|
default: () => [
|
|
|
|
|
|
|
|
createVNode('div', null, '1'),
|
|
|
|
|
|
|
|
createVNode('div', null, '2'),
|
|
|
|
|
|
|
|
createVNode('div', null, '3'),
|
|
|
|
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sync: false,
|
|
|
|
sync: false,
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -38,7 +43,7 @@ describe('Carousel', () => {
|
|
|
|
expect(typeof prev).toBe('function');
|
|
|
|
expect(typeof prev).toBe('function');
|
|
|
|
expect(typeof next).toBe('function');
|
|
|
|
expect(typeof next).toBe('function');
|
|
|
|
expect(typeof goTo).toBe('function');
|
|
|
|
expect(typeof goTo).toBe('function');
|
|
|
|
const slick = wrapper.vm.$refs.slick;
|
|
|
|
const slick = wrapper.vm.slick;
|
|
|
|
|
|
|
|
|
|
|
|
expect(slick.innerSlider.currentSlide).toBe(0);
|
|
|
|
expect(slick.innerSlider.currentSlide).toBe(0);
|
|
|
|
wrapper.vm.goTo(2);
|
|
|
|
wrapper.vm.goTo(2);
|
|
|
@ -56,24 +61,29 @@ describe('Carousel', () => {
|
|
|
|
expect(slick.innerSlider.currentSlide).toBe(2);
|
|
|
|
expect(slick.innerSlider.currentSlide).toBe(2);
|
|
|
|
}, 1000);
|
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
// it('should trigger autoPlay after window resize', async () => {
|
|
|
|
|
|
|
|
// const props = {
|
|
|
|
|
|
|
|
// props: {
|
|
|
|
|
|
|
|
// autoplay: true,
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// slots: {
|
|
|
|
|
|
|
|
// default: () => [
|
|
|
|
|
|
|
|
// createVNode('div', null, '1'),
|
|
|
|
|
|
|
|
// createVNode('div', null, '2'),
|
|
|
|
|
|
|
|
// createVNode('div', null, '3'),
|
|
|
|
|
|
|
|
// ],
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// sync: false,
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// const wrapper = mount(Carousel, props);
|
|
|
|
|
|
|
|
|
|
|
|
it('should trigger autoPlay after window resize', async () => {
|
|
|
|
// const spy = jest.spyOn(wrapper.vm.slick.innerSlider, 'handleAutoPlay');
|
|
|
|
const props = {
|
|
|
|
// window.resizeTo(1000);
|
|
|
|
props: {
|
|
|
|
// expect(spy).not.toHaveBeenCalled();
|
|
|
|
autoplay: true,
|
|
|
|
// await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
},
|
|
|
|
// expect(spy).toHaveBeenCalled();
|
|
|
|
slots: {
|
|
|
|
// });
|
|
|
|
default: '<div>1</div><div>2</div><div>3</div>',
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
sync: false,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = mount(Carousel, props);
|
|
|
|
|
|
|
|
const spy = jest.spyOn(wrapper.vm.$refs.slick.innerSlider, 'handleAutoPlay');
|
|
|
|
|
|
|
|
window.resizeTo(1000);
|
|
|
|
|
|
|
|
expect(spy).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('cancel resize listener when unmount', async () => {
|
|
|
|
it('cancel resize listener when unmount', async () => {
|
|
|
|
const props = {
|
|
|
|
const props = {
|
|
|
@ -81,7 +91,11 @@ describe('Carousel', () => {
|
|
|
|
autoplay: true,
|
|
|
|
autoplay: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
slots: {
|
|
|
|
slots: {
|
|
|
|
default: '<div>1</div><div>2</div><div>3</div>',
|
|
|
|
default: () => [
|
|
|
|
|
|
|
|
createVNode('div', null, '1'),
|
|
|
|
|
|
|
|
createVNode('div', null, '2'),
|
|
|
|
|
|
|
|
createVNode('div', null, '3'),
|
|
|
|
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sync: false,
|
|
|
|
sync: false,
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -96,16 +110,20 @@ describe('Carousel', () => {
|
|
|
|
|
|
|
|
|
|
|
|
describe('should works for dotPosition', () => {
|
|
|
|
describe('should works for dotPosition', () => {
|
|
|
|
['left', 'right', 'top', 'bottom'].forEach(dotPosition => {
|
|
|
|
['left', 'right', 'top', 'bottom'].forEach(dotPosition => {
|
|
|
|
it(dotPosition, () => {
|
|
|
|
it(dotPosition, async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
const wrapper = mount(
|
|
|
|
render() {
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
render() {
|
|
|
|
<Carousel dotPosition={dotPosition}>
|
|
|
|
return (
|
|
|
|
<div />
|
|
|
|
<Carousel dotPosition={dotPosition}>
|
|
|
|
</Carousel>
|
|
|
|
<div />
|
|
|
|
);
|
|
|
|
</Carousel>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
{ sync: false, attachTo: 'body' },
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await sleep(100);
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|