From c817ed9e6341e5db424e69ce8a3351d8d968be2f Mon Sep 17 00:00:00 2001 From: Paul Thiel Date: Sun, 28 May 2023 17:26:12 +0200 Subject: [PATCH 1/3] fix(TreeNode): stop keydown event propagation from content --- components/lib/tree/TreeNode.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/lib/tree/TreeNode.vue b/components/lib/tree/TreeNode.vue index 263a00617..b49a1a8d9 100755 --- a/components/lib/tree/TreeNode.vue +++ b/components/lib/tree/TreeNode.vue @@ -27,7 +27,7 @@ - + From 8c58ad2a2b9a7dd67d4a10960f2527eb28e0f469 Mon Sep 17 00:00:00 2001 From: Paul Thiel Date: Sun, 28 May 2023 17:26:41 +0200 Subject: [PATCH 2/3] test(Tree): keydown event propagation --- components/lib/tree/Tree.spec.js | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 components/lib/tree/Tree.spec.js diff --git a/components/lib/tree/Tree.spec.js b/components/lib/tree/Tree.spec.js new file mode 100644 index 000000000..aaa24880b --- /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() + }); +}); From 9d9ab2667eb96e8aced7d97ee959fa2b4535f631 Mon Sep 17 00:00:00 2001 From: Paul Thiel Date: Mon, 29 May 2023 19:49:36 +0200 Subject: [PATCH 3/3] chore: formatting --- components/lib/tree/Tree.spec.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/components/lib/tree/Tree.spec.js b/components/lib/tree/Tree.spec.js index aaa24880b..dbeeec934 100644 --- a/components/lib/tree/Tree.spec.js +++ b/components/lib/tree/Tree.spec.js @@ -11,17 +11,17 @@ describe('Tree.vue', () => { props: { value: [ { - key: "0", - label: "Documents", - data: "Documents Folder", - icon: "pi pi-fw pi-inbox", - children: [], - }, - ], + key: '0', + label: 'Documents', + data: 'Documents Folder', + icon: 'pi pi-fw pi-inbox', + children: [] + } + ] }, slots: { default: `` - }, + } }); }); @@ -30,16 +30,16 @@ describe('Tree.vue', () => { }); it('triggers event', async () => { - wrapper.trigger('keydown.space') - expect(wrapper.emitted('keydown')).toBeTruthy() + 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]') + let textInput = wrapper.find('input[data-tree-input]'); - await textInput.trigger('keydown.space') + await textInput.trigger('keydown.space'); - expect(wrapper.emitted('keydown')).toBeFalsy() + expect(wrapper.emitted('keydown')).toBeFalsy(); }); });