primevue-mirror/components/lib/inputchips/InputChips.spec.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-09-06 12:03:37 +00:00
import { mount } from '@vue/test-utils';
2024-04-18 14:18:40 +00:00
import InputChips from './InputChips.vue';
2022-09-06 12:03:37 +00:00
2024-04-18 14:18:40 +00:00
describe('InputChips.vue', () => {
2022-09-06 12:03:37 +00:00
let wrapper;
beforeEach(() => {
2024-04-18 14:18:40 +00:00
wrapper = mount(InputChips, {
2022-09-06 12:03:37 +00:00
props: {
modelValue: null
}
});
});
it('should exist', () => {
2024-04-18 14:18:40 +00:00
expect(wrapper.find('.p-inputchips.p-component.p-inputwrapper').exists()).toBe(true);
expect(wrapper.find('ul.p-inputchips-multiple-container').exists()).toBe(true);
expect(wrapper.find('li.p-inputchips-input-token').exists()).toBe(true);
2022-09-06 12:03:37 +00:00
});
2022-09-14 11:26:01 +00:00
it('should add item', async () => {
2022-12-08 14:13:16 +00:00
const addItem = vi.spyOn(wrapper.vm, 'addItem');
2022-09-14 11:26:01 +00:00
await wrapper.vm.addItem({}, 'PrimeVue', false);
2022-09-06 12:03:37 +00:00
await wrapper.setProps({ modelValue: ['PrimeVue'] });
expect(addItem).toHaveBeenCalled();
2024-04-18 14:18:40 +00:00
expect(wrapper.findAll('.p-inputchips-token').length).toBe(1);
expect(wrapper.find('.p-inputchips-token-label').exists()).toBe(true);
expect(wrapper.find('.p-inputchips-token-label').text()).toBe('PrimeVue');
2022-09-06 12:03:37 +00:00
});
2022-12-08 11:04:25 +00:00
it('should have correct custom chip removal icon', async () => {
await wrapper.setProps({
modelValue: ['foo', 'bar'],
removeTokenIcon: 'pi pi-discord'
});
2024-04-18 14:18:40 +00:00
const icon = wrapper.find('.p-inputchips-token-icon');
2022-12-08 11:04:25 +00:00
expect(icon.classes()).toContain('pi-discord');
});
2022-09-14 11:26:01 +00:00
});