primevue-mirror/packages/primevue/src/galleria/Galleria.spec.js

65 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-09-06 12:03:37 +00:00
import { mount } from '@vue/test-utils';
2022-12-08 11:04:25 +00:00
import PrimeVue from 'primevue/config';
2022-09-06 12:03:37 +00:00
import Galleria from './Galleria.vue';
describe('Gallleria.vue', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(Galleria, {
global: {
plugins: [PrimeVue],
stubs: {
teleport: true
}
},
props: {
value: [
{
itemImageSrc: 'images/galleria/galleria1.jpg',
thumbnailImageSrc: 'images/galleria/galleria1s.jpg',
2022-09-14 11:26:01 +00:00
alt: 'Description for Image 1',
title: 'Title 1'
2022-09-06 12:03:37 +00:00
},
{
itemImageSrc: 'images/galleria/galleria2.jpg',
thumbnailImageSrc: 'images/galleria/galleria2s.jpg',
2022-09-14 11:26:01 +00:00
alt: 'Description for Image 2',
title: 'Title 2'
2022-09-06 12:03:37 +00:00
},
{
itemImageSrc: 'images/galleria/galleria3.jpg',
thumbnailImageSrc: 'images/galleria/galleria3s.jpg',
2022-09-14 11:26:01 +00:00
alt: 'Description for Image 3',
title: 'Title 3'
2022-09-06 12:03:37 +00:00
}
],
numVisible: 2
},
slots: {
item: `
<template #item="slotProps">
<img :src="slotProps.item.itemImageSrc" :alt="slotProps.item.alt" style="width: 100%" />
</template>
`
}
});
});
2022-09-14 11:26:01 +00:00
it('should exist', () => {
2022-09-06 12:03:37 +00:00
expect(wrapper.find('.p-galleria.p-component').exists()).toBe(true);
expect(wrapper.findAll('.p-galleria-item-container > .p-galleria-item').length).toBe(1);
expect(wrapper.findAll('.p-galleria-thumbnail-item-active').length).toBe(2);
});
2022-09-14 11:26:01 +00:00
it('should active item change', async () => {
2022-09-06 12:03:37 +00:00
expect(wrapper.find('.p-galleria-item-container img').attributes().alt).toBe('Description for Image 1');
wrapper.vm.onActiveItemChange(1);
2022-09-14 11:26:01 +00:00
await wrapper.setProps({ activeIndex: 1 });
2022-09-06 12:03:37 +00:00
expect(wrapper.find('.p-galleria-item-container img').attributes().alt).toBe('Description for Image 2');
expect(wrapper.emitted()['update:activeIndex'][0]).toEqual([1]);
});
2022-09-14 11:26:01 +00:00
});