diff --git a/components/lib/tree/Tree.spec.js b/components/lib/tree/Tree.spec.js new file mode 100644 index 000000000..dbeeec934 --- /dev/null +++ b/components/lib/tree/Tree.spec.js @@ -0,0 +1,45 @@ +import { mount } from '@vue/test-utils'; +import PrimeVue from 'primevue/config'; +import { nextTick } from 'vue'; +import Tree from './Tree.vue'; + +describe('Tree.vue', () => { + let wrapper; + + beforeEach(async () => { + wrapper = mount(Tree, { + props: { + value: [ + { + key: '0', + label: 'Documents', + data: 'Documents Folder', + icon: 'pi pi-fw pi-inbox', + children: [] + } + ] + }, + slots: { + default: `` + } + }); + }); + + it('should exists', () => { + expect(wrapper.find('.p-tree.p-component').exists()).toBe(true); + }); + + it('triggers event', async () => { + wrapper.trigger('keydown.space'); + expect(wrapper.emitted('keydown')).toBeTruthy(); + }); + + it('stops event propagation from content', async () => { + // If the event propagation is not stopped from content, then inputs would not work as expected + let textInput = wrapper.find('input[data-tree-input]'); + + await textInput.trigger('keydown.space'); + + expect(wrapper.emitted('keydown')).toBeFalsy(); + }); +}); diff --git a/components/lib/tree/TreeNode.vue b/components/lib/tree/TreeNode.vue index a76f4d918..78dfbaaed 100755 --- a/components/lib/tree/TreeNode.vue +++ b/components/lib/tree/TreeNode.vue @@ -27,7 +27,7 @@ - +