2022-09-06 12:03:37 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { h } from 'vue';
|
2022-12-08 14:13:16 +00:00
|
|
|
import Button from './Button.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
describe('Button.vue', () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
it('is Button element exist', () => {
|
|
|
|
const wrapper = mount(Button);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
expect(wrapper.find('.p-button.p-component').exists()).toBe(true);
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.find('.p-button-label').exists()).toBe(true);
|
2022-09-14 11:26:01 +00:00
|
|
|
});
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Button.vue', () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
it('is icon exist and right position', () => {
|
2022-09-06 12:03:37 +00:00
|
|
|
const icon = 'pi pi-discord';
|
|
|
|
const iconPos = 'right';
|
|
|
|
const label = 'Save';
|
|
|
|
const props = { icon, iconPos };
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
wrapper = mount(Button, {
|
|
|
|
props
|
|
|
|
});
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
expect(wrapper.find('.p-button-icon-only').exists()).toBe(true);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
wrapper = mount(Button, {
|
|
|
|
props: { ...props, label }
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find('.p-button-icon.p-button-icon-' + iconPos).exists()).toBe(true);
|
2022-09-14 11:26:01 +00:00
|
|
|
});
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Button.vue', () => {
|
|
|
|
it('is badge working', () => {
|
|
|
|
const badge = '5';
|
2022-09-14 11:26:01 +00:00
|
|
|
const badgeClass = 'p-badge-danger';
|
2022-09-06 12:03:37 +00:00
|
|
|
const wrapper = mount(Button, {
|
|
|
|
props: { badge, badgeClass }
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find('.p-badge').text()).toEqual(badge);
|
|
|
|
expect(wrapper.find('.' + badgeClass).exists()).toBe(true);
|
2022-09-14 11:26:01 +00:00
|
|
|
});
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Button.vue', () => {
|
|
|
|
it('is loading working', async () => {
|
|
|
|
const loadingIcon = 'pi pi-discord';
|
|
|
|
const wrapper = mount(Button, {
|
|
|
|
props: {
|
|
|
|
loading: false,
|
|
|
|
loadingIcon
|
|
|
|
}
|
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.find('.p-disabled').exists()).toBe(false);
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.setProps({ loading: true });
|
2022-09-06 12:03:37 +00:00
|
|
|
const array = loadingIcon.split(' ');
|
2022-09-14 11:26:01 +00:00
|
|
|
const lastIcon = '.' + array.join('.');
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
expect(wrapper.find('.p-button-loading').exists()).toBe(true);
|
|
|
|
expect(wrapper.find('.p-button-loading-icon' + lastIcon).exists()).toBe(true);
|
|
|
|
|
|
|
|
await wrapper.setProps({ loading: false });
|
|
|
|
|
|
|
|
expect(wrapper.find('.p-button-loading').exists()).toBe(false);
|
2022-09-14 11:26:01 +00:00
|
|
|
});
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Button.vue', () => {
|
|
|
|
it('should render default slot', () => {
|
|
|
|
const wrapper = mount(Button, {
|
|
|
|
slots: {
|
2022-09-14 11:26:01 +00:00
|
|
|
default: h('span', { class: 'ml-2 font-bold' }, 'Default PrimeVue Button')
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-09-04 08:18:26 +00:00
|
|
|
expect(wrapper.html()).toBe(`<button class="p-button p-component" type="button" data-pc-name="button" data-pc-section="root" data-pd-ripple="true"><span class="ml-2 font-bold">Default PrimeVue Button</span></button>`);
|
2022-09-14 11:26:01 +00:00
|
|
|
});
|
|
|
|
});
|