From 37e557264c8a3f414a41640832dc961a02428dfd Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 29 Nov 2024 22:45:32 +0100 Subject: [PATCH 1/4] fix: useRequired composable --- src/composables/useRequired.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/composables/useRequired.js b/src/composables/useRequired.js index e650c91f5..d211b96b4 100644 --- a/src/composables/useRequired.js +++ b/src/composables/useRequired.js @@ -2,8 +2,14 @@ import { useValidator } from 'src/composables/useValidator'; export function useRequired($attrs) { const { validations } = useValidator(); - - const isRequired = Object.keys($attrs).includes('required'); + const hasRequired = Object.keys($attrs).includes('required'); + let isRequired = false; + if (hasRequired) { + const required = $attrs['required']; + if (typeof required === 'boolean') { + isRequired = required; + } + } const requiredFieldRule = (val) => validations().required(isRequired, val); return { From 883104f1f1519d807e72ac0f67e7942cb7296457 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 29 Nov 2024 22:45:42 +0100 Subject: [PATCH 2/4] fix: dataByOrder when is null composable --- src/utils/dataByOrder.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/dataByOrder.js b/src/utils/dataByOrder.js index 1bdedb8a1..eb4a4f586 100644 --- a/src/utils/dataByOrder.js +++ b/src/utils/dataByOrder.js @@ -1,6 +1,7 @@ function orderData(data, order) { if (typeof order === 'function') return data.sort(data); if (typeof order === 'string') order = [order]; + if (!Array.isArray(data)) return []; if (Array.isArray(order)) { let orderComp = []; From 0c7be99ecb332963c184b0a7efae890e8f945421 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 29 Nov 2024 22:46:15 +0100 Subject: [PATCH 3/4] fix: input sage required --- src/components/common/VnSelect.vue | 9 ++++++++- src/pages/Customer/Card/CustomerFiscalData.vue | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue index 14005e1cc..1a41d261a 100644 --- a/src/components/common/VnSelect.vue +++ b/src/components/common/VnSelect.vue @@ -8,7 +8,14 @@ import dataByOrder from 'src/utils/dataByOrder'; const emit = defineEmits(['update:modelValue', 'update:options', 'remove']); const $attrs = useAttrs(); const { t } = useI18n(); -const { isRequired, requiredFieldRule } = useRequired($attrs); + +const isRequired = computed(() => { + return useRequired($attrs).isRequired; +}); +const requiredFieldRule = computed(() => { + return useRequired($attrs).requiredFieldRule; +}); + const $props = defineProps({ modelValue: { type: [String, Number, Object], diff --git a/src/pages/Customer/Card/CustomerFiscalData.vue b/src/pages/Customer/Card/CustomerFiscalData.vue index 24d8d1e5d..673c7dda9 100644 --- a/src/pages/Customer/Card/CustomerFiscalData.vue +++ b/src/pages/Customer/Card/CustomerFiscalData.vue @@ -67,6 +67,7 @@ function handleLocation(data, location) { option-label="vat" option-value="id" v-model="data.sageTaxTypeFk" + data-cy="sageTaxTypeFk" :required="data.isTaxDataChecked" /> From 918c8bea6007ef1e97e06afd30e92c0b4a3dc8d9 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 29 Nov 2024 22:46:26 +0100 Subject: [PATCH 4/4] test: input sage required --- test/cypress/integration/client/clientFiscalData.spec.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/cypress/integration/client/clientFiscalData.spec.js b/test/cypress/integration/client/clientFiscalData.spec.js index e337c26f8..05e0772e9 100644 --- a/test/cypress/integration/client/clientFiscalData.spec.js +++ b/test/cypress/integration/client/clientFiscalData.spec.js @@ -3,11 +3,16 @@ describe('Client fiscal data', () => { beforeEach(() => { cy.viewport(1280, 720); cy.login('developer'); - cy.visit('#/customer/1110/fiscal-data', { + cy.visit('#/customer/1107/fiscal-data', { timeout: 5000, }); }); - it('Should load layout', () => { + it('Should change required value when change customer', () => { cy.get('.q-card').should('be.visible'); + cy.dataCy('sageTaxTypeFk').filter('input').should('not.have.attr', 'required'); + cy.get('#searchbar input').clear(); + cy.get('#searchbar input').type('1{enter}'); + cy.get('.q-item > .q-item__label').should('have.text', ' #1'); + cy.dataCy('sageTaxTypeFk').filter('input').should('have.attr', 'required'); }); });