|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
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 mountTest from '../../../tests/shared/mountTest';
|
|
|
|
|
|
|
|
|
@ -15,13 +16,13 @@ describe('Carousel', () => {
|
|
|
|
|
it('should has innerSlider', () => {
|
|
|
|
|
const props = {
|
|
|
|
|
slots: {
|
|
|
|
|
default: '<div />',
|
|
|
|
|
default: () => h('div'),
|
|
|
|
|
},
|
|
|
|
|
sync: false,
|
|
|
|
|
};
|
|
|
|
|
const wrapper = mount(Carousel, props);
|
|
|
|
|
const { innerSlider, $refs } = wrapper.vm;
|
|
|
|
|
const innerSliderFromRefs = $refs.slick.innerSlider;
|
|
|
|
|
const { innerSlider, slick } = wrapper.vm;
|
|
|
|
|
const innerSliderFromRefs = slick.innerSlider;
|
|
|
|
|
expect(innerSlider).toBe(innerSliderFromRefs);
|
|
|
|
|
expect(typeof innerSlider.slickNext).toBe('function');
|
|
|
|
|
});
|
|
|
|
@ -29,7 +30,11 @@ describe('Carousel', () => {
|
|
|
|
|
it('should has prev, next and go function', async () => {
|
|
|
|
|
const props = {
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
@ -38,7 +43,7 @@ describe('Carousel', () => {
|
|
|
|
|
expect(typeof prev).toBe('function');
|
|
|
|
|
expect(typeof next).toBe('function');
|
|
|
|
|
expect(typeof goTo).toBe('function');
|
|
|
|
|
const slick = wrapper.vm.$refs.slick;
|
|
|
|
|
const slick = wrapper.vm.slick;
|
|
|
|
|
|
|
|
|
|
expect(slick.innerSlider.currentSlide).toBe(0);
|
|
|
|
|
wrapper.vm.goTo(2);
|
|
|
|
@ -56,24 +61,29 @@ describe('Carousel', () => {
|
|
|
|
|
expect(slick.innerSlider.currentSlide).toBe(2);
|
|
|
|
|
}, 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 props = {
|
|
|
|
|
props: {
|
|
|
|
|
autoplay: true,
|
|
|
|
|
},
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
// const spy = jest.spyOn(wrapper.vm.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 () => {
|
|
|
|
|
const props = {
|
|
|
|
@ -81,7 +91,11 @@ describe('Carousel', () => {
|
|
|
|
|
autoplay: true,
|
|
|
|
|
},
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
@ -96,16 +110,20 @@ describe('Carousel', () => {
|
|
|
|
|
|
|
|
|
|
describe('should works for dotPosition', () => {
|
|
|
|
|
['left', 'right', 'top', 'bottom'].forEach(dotPosition => {
|
|
|
|
|
it(dotPosition, () => {
|
|
|
|
|
const wrapper = mount({
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<Carousel dotPosition={dotPosition}>
|
|
|
|
|
<div />
|
|
|
|
|
</Carousel>
|
|
|
|
|
);
|
|
|
|
|
it(dotPosition, async () => {
|
|
|
|
|
const wrapper = mount(
|
|
|
|
|
{
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<Carousel dotPosition={dotPosition}>
|
|
|
|
|
<div />
|
|
|
|
|
</Carousel>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
{ sync: false, attachTo: 'body' },
|
|
|
|
|
);
|
|
|
|
|
await sleep(100);
|
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|