From 3948b26f6b4eebc7e869fc84bdaaaa6be1f3701f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 6 Dec 2024 13:35:35 +0100 Subject: [PATCH 1/4] feat: init directive --- src/boot/dataCy.js | 17 +++++++++++++++++ src/boot/quasar.js | 2 ++ 2 files changed, 19 insertions(+) create mode 100644 src/boot/dataCy.js diff --git a/src/boot/dataCy.js b/src/boot/dataCy.js new file mode 100644 index 000000000..18f200ae6 --- /dev/null +++ b/src/boot/dataCy.js @@ -0,0 +1,17 @@ +export default { + mounted: function (el, binding, { ctx }) { + const { innerText, localName } = el; + const { type, attrs } = ctx; + + el.setAttribute( + 'data-cy', + `${attrs?.label ?? innerText}_${type.name.replace('Q', '').toLowerCase()}` + ); + console.error('dataCy', el.getAttribute('data-cy')); + }, + unmounted: function (el) { + if (el._handleKeydown) { + window.removeEventListener('keydown', el._handleKeydown); + } + }, +}; diff --git a/src/boot/quasar.js b/src/boot/quasar.js index 01fe68d8b..f6c6c3331 100644 --- a/src/boot/quasar.js +++ b/src/boot/quasar.js @@ -3,12 +3,14 @@ import qFormMixin from './qformMixin'; import keyShortcut from './keyShortcut'; import useNotify from 'src/composables/useNotify.js'; import { CanceledError } from 'axios'; +import dataCy from './dataCy'; const { notify } = useNotify(); export default boot(({ app }) => { app.mixin(qFormMixin); app.directive('shortcut', keyShortcut); + app.directive('dataCy', dataCy); app.config.errorHandler = (error) => { let message; const response = error.response; -- 2.40.1 From 160fbfca440ea730ac0cf2322043bd9710a9a873 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 6 Dec 2024 13:35:52 +0100 Subject: [PATCH 2/4] feat: add v-dataCy for some components --- src/components/common/VnDate.vue | 2 +- src/components/common/VnInput.vue | 2 +- src/components/common/VnInputDate.vue | 1 + src/components/common/VnSelect.vue | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/common/VnDate.vue b/src/components/common/VnDate.vue index 761ac995e..6959ad754 100644 --- a/src/components/common/VnDate.vue +++ b/src/components/common/VnDate.vue @@ -2,7 +2,7 @@ const model = defineModel({ type: [String, Number], required: true });