primevue-mirror/packages/primevue/src/dialog/Dialog.spec.js

123 lines
3.3 KiB
JavaScript
Raw Normal View History

2022-12-08 11:04:25 +00:00
import PrimeVue from 'primevue/config';
2022-09-14 11:26:01 +00:00
import { mount } from '@vue/test-utils';
2022-09-06 12:03:37 +00:00
import Dialog from './Dialog.vue';
describe('Dialog.vue', () => {
2022-09-14 11:26:01 +00:00
it('is Dialog element exist', async () => {
const wrapper = mount(Dialog, {
global: {
2022-09-06 12:03:37 +00:00
plugins: [PrimeVue],
stubs: {
2022-12-08 11:04:25 +00:00
teleport: true,
transition: false
2022-09-06 12:03:37 +00:00
}
},
props: {
visible: false
2022-12-08 11:04:25 +00:00
},
data() {
return {
containerVisible: true
};
2022-09-06 12:03:37 +00:00
}
2022-09-14 11:26:01 +00:00
});
2022-09-06 12:03:37 +00:00
2022-09-14 11:26:01 +00:00
expect(wrapper.find('.p-dialog.p-component').exists()).toBe(false);
2022-09-06 12:03:37 +00:00
2022-09-14 11:26:01 +00:00
await wrapper.setProps({ visible: true });
2022-09-06 12:03:37 +00:00
2022-09-14 11:26:01 +00:00
expect(wrapper.find('.p-dialog.p-component').exists()).toBe(true);
});
2022-09-06 12:03:37 +00:00
2022-09-14 11:26:01 +00:00
it('slot checks', async () => {
const wrapper = mount(Dialog, {
global: {
2022-09-06 12:03:37 +00:00
plugins: [PrimeVue],
stubs: {
teleport: true
}
},
2022-09-14 11:26:01 +00:00
slots: {
default: '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>',
footer: '<p>Dialog Footer</p>'
2022-12-08 11:04:25 +00:00
},
data() {
return {
containerVisible: true
};
}
});
await wrapper.setProps({ visible: true });
expect(wrapper.find('.p-dialog-content').exists()).toBe(true);
expect(wrapper.find('.p-dialog-footer').exists()).toBe(true);
});
});
describe('closable', () => {
it('should have custom close icon when provided', async () => {
const wrapper = mount(Dialog, {
global: {
plugins: [PrimeVue],
stubs: {
teleport: true
}
},
props: {
closable: true,
closeIcon: 'pi pi-discord',
showHeader: true,
visible: false
},
data() {
return {
containerVisible: true
};
2022-09-14 11:26:01 +00:00
}
});
2022-09-06 12:03:37 +00:00
2022-12-08 11:04:25 +00:00
await wrapper.setProps({ visible: true });
const icon = wrapper.find('.p-dialog-header-close-icon');
expect(icon.classes()).toContain('pi-discord');
});
});
describe('maximizable', () => {
it('should have custom maximize and minimize icons when provided', async () => {
const wrapper = mount(Dialog, {
global: {
plugins: [PrimeVue],
stubs: {
teleport: true
}
},
props: {
maximizable: true,
maximizeIcon: 'pi pi-discord',
minimizeIcon: 'pi pi-facebook',
showHeader: true,
visible: false
},
data() {
return {
containerVisible: true
};
}
});
await wrapper.setProps({ visible: true });
await wrapper.setData({ maximized: false });
const icon = wrapper.find('.p-dialog-header-maximize-icon');
expect(icon.classes()).toContain('pi-discord');
await wrapper.setData({ maximized: true });
expect(icon.classes()).toContain('pi-facebook');
2022-09-14 11:26:01 +00:00
});
});