primevue-mirror/components/lib/tree/Tree.spec.js

85 lines
2.3 KiB
JavaScript
Raw Normal View History

2023-05-28 15:26:41 +00:00
import { mount } from '@vue/test-utils';
import Tree from './Tree.vue';
describe('Tree.vue', () => {
let wrapper;
beforeEach(async () => {
wrapper = mount(Tree, {
props: {
value: [
{
2023-05-29 17:49:36 +00:00
key: '0',
label: 'Documents',
data: 'Documents Folder',
icon: 'pi pi-fw pi-inbox',
children: []
}
]
2023-05-28 15:26:41 +00:00
},
slots: {
default: `<input data-tree-input />`
2023-05-29 17:49:36 +00:00
}
2023-05-28 15:26:41 +00:00
});
});
it('should exists', () => {
expect(wrapper.find('.p-tree.p-component').exists()).toBe(true);
});
it('triggers event', async () => {
2023-05-29 17:49:36 +00:00
wrapper.trigger('keydown.space');
expect(wrapper.emitted('keydown')).toBeTruthy();
2023-05-28 15:26:41 +00:00
});
it('stops event propagation from content', async () => {
// If the event propagation is not stopped from content, then inputs would not work as expected
2023-05-29 17:49:36 +00:00
let textInput = wrapper.find('input[data-tree-input]');
2023-05-28 15:26:41 +00:00
2023-05-29 17:49:36 +00:00
await textInput.trigger('keydown.space');
2023-05-28 15:26:41 +00:00
2023-05-29 17:49:36 +00:00
expect(wrapper.emitted('keydown')).toBeFalsy();
2023-05-28 15:26:41 +00:00
});
2023-11-23 15:48:14 +00:00
it('emits update:filterValue on filter input', async () => {
wrapper = mount(Tree, {
props: {
2023-12-01 09:04:05 +00:00
filter: true
}
2023-11-23 15:48:14 +00:00
});
let searchField = wrapper.find('input.p-tree-filter');
await searchField.trigger('keydown.space');
expect(wrapper.emitted('filter')).toBeTruthy();
2023-12-01 09:04:05 +00:00
});
2024-03-13 13:10:35 +00:00
it('should render icon', ({ expect }) => {
expect(wrapper.find('span.pi-inbox').exists()).toBeTruthy();
2024-03-13 13:10:35 +00:00
expect(wrapper.find('span.pi-inbox').classes('p-treenode-icon')).toBeTruthy();
});
2024-03-13 13:10:35 +00:00
it('should render icon slot', ({ expect }) => {
let wrapper = mount(Tree, {
slots: {
2024-03-21 09:35:28 +00:00
nodeicon: `<i data-node-icon/>`
},
props: {
value: [
{
key: '0',
label: 'Documents',
data: 'Documents Folder',
children: []
}
]
}
});
const nodeIcon = wrapper.find('i[data-node-icon]');
expect(nodeIcon.exists()).toBeTruthy();
2024-03-13 13:10:35 +00:00
});
2023-05-28 15:26:41 +00:00
});