primevue-mirror/components/toast/Toast.spec.js

144 lines
5.2 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 Toast from './Toast.vue';
describe('Toast.vue', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(Toast, {
global: {
2022-12-08 11:04:25 +00:00
plugins: [PrimeVue],
2022-09-06 12:03:37 +00:00
stubs: {
2022-12-08 11:04:25 +00:00
teleport: true,
transition: true
2022-09-06 12:03:37 +00:00
}
},
data() {
return {
2022-09-14 11:26:01 +00:00
messages: [{ severity: 'success', summary: 'Success Message', detail: 'Message Content', life: 3000 }]
};
2022-09-06 12:03:37 +00:00
}
2022-09-14 11:26:01 +00:00
});
2022-09-06 12:03:37 +00:00
});
it('should exist', () => {
expect(wrapper.find('.p-toast.p-component').exists()).toBe(true);
expect(wrapper.find('.p-toast-message').classes()).toContain('p-toast-message-success');
expect(wrapper.find('.p-toast-summary').text()).toBe('Success Message');
expect(wrapper.find('.p-toast-detail').text()).toBe('Message Content');
});
it('should position is changed', async () => {
await wrapper.setProps({ position: 'bottom-left' });
2022-12-08 11:04:25 +00:00
setTimeout(() => {
expect(wrapper.find('.p-toast.p-component').classes()).toContain('p-toast-bottom-left');
}, 200);
2022-09-06 12:03:37 +00:00
});
it('should show grouped toast', async () => {
await wrapper.setProps({ group: 'br' });
expect(wrapper.find('.p-toast.p-component').exists()).toBe(true);
});
it('should close toast', async () => {
await wrapper.vm.remove({ message: { severity: 'success', summary: 'Success Message', detail: 'Message Content', life: 3000 }, type: 'close' });
2022-09-06 12:03:37 +00:00
expect(wrapper.emitted()['close'][0][0].message).not.toBe({});
2022-09-06 12:03:37 +00:00
expect(wrapper.find('.p-toast-message').exists()).toBe(false);
});
it('should show multiple toast', async () => {
await wrapper.setData({
messages: [
2022-09-14 11:26:01 +00:00
{ severity: 'info', summary: 'Message 1', detail: 'Message 1 Content', life: 3000 },
{ severity: 'info', summary: 'Message 2', detail: 'Message 2 Content', life: 3000 },
{ severity: 'info', summary: 'Message 3', detail: 'Message 3 Content', life: 3000 }
2022-09-06 12:03:37 +00:00
]
});
expect(wrapper.findAll('.p-toast-message').length).toBe(3);
});
it('should close multiple toast', async () => {
await wrapper.setData({
messages: [
2022-09-14 11:26:01 +00:00
{ severity: 'info', summary: 'Message 1', detail: 'Message 1 Content', life: 3000 },
{ severity: 'info', summary: 'Message 2', detail: 'Message 2 Content', life: 3000 },
{ severity: 'info', summary: 'Message 3', detail: 'Message 3 Content', life: 3000 }
2022-09-06 12:03:37 +00:00
]
});
await wrapper.vm.onRemoveAllGroups();
expect(wrapper.findAll('.p-toast-message').length).toBe(0);
});
it('should close grouped toast', async () => {
await wrapper.setProps({ group: 'br' });
await wrapper.vm.onRemoveGroup('br');
expect(wrapper.findAll('.p-toast-message').length).toBe(0);
});
2022-12-08 11:04:25 +00:00
describe('custom icons', () => {
it('should have custom close icon', async () => {
await wrapper.setProps({ closeIcon: 'pi pi-discord' });
await wrapper.setData({
messages: [{ severity: 'info', summary: 'Message 1', detail: 'Message 1 Content', life: 3000 }]
});
const icon = wrapper.find('.p-toast-icon-close-icon');
expect(icon.classes()).toContain('pi-discord');
});
it('should have custom info severity icon', async () => {
await wrapper.setProps({ infoIcon: 'pi pi-discord' });
await wrapper.setData({
messages: [{ severity: 'info', summary: 'Message', detail: 'Message Content', life: 3000 }]
});
const icon = wrapper.find('.p-toast-message-icon');
expect(icon.classes()).toContain('pi-discord');
});
it('should have custom warn severity icon', async () => {
await wrapper.setProps({ warnIcon: 'pi pi-discord' });
await wrapper.setData({
messages: [{ severity: 'warn', summary: 'Message', detail: 'Message Content', life: 3000 }]
});
const icon = wrapper.find('.p-toast-message-icon');
expect(icon.classes()).toContain('pi-discord');
});
it('should have custom error severity icon', async () => {
await wrapper.setProps({ errorIcon: 'pi pi-discord' });
await wrapper.setData({
messages: [{ severity: 'error', summary: 'Message', detail: 'Message Content', life: 3000 }]
});
const icon = wrapper.find('.p-toast-message-icon');
expect(icon.classes()).toContain('pi-discord');
});
it('should have custom success severity icon', async () => {
await wrapper.setProps({ successIcon: 'pi pi-discord' });
await wrapper.setData({
messages: [{ severity: 'success', summary: 'Message', detail: 'Message Content', life: 3000 }]
});
const icon = wrapper.find('.p-toast-message-icon');
expect(icon.classes()).toContain('pi-discord');
});
});
2022-09-14 11:26:01 +00:00
});