From 271e33a999d54cf06788aa41dce6164658aaf6ab Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 20 Sep 2024 11:57:15 +0200 Subject: [PATCH 1/3] feat: formatLocation when field is null --- src/components/common/VnLocation.vue | 40 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/components/common/VnLocation.vue b/src/components/common/VnLocation.vue index b6cbfbafd..c3b07c72c 100644 --- a/src/components/common/VnLocation.vue +++ b/src/components/common/VnLocation.vue @@ -12,14 +12,46 @@ const props = defineProps({ default: null, }, }); +const formatLocation = (obj, properties) => { + // Crear un array con las propiedades del objeto + const parts = properties.map((prop) => { + if (typeof prop === 'string') { + return obj[prop]; + } else if (typeof prop === 'function') { + return prop(obj); + } + return null; + }); + + // Filtrar los valores que no son null o undefined + const filteredParts = parts.filter( + (part) => part !== null && part !== undefined && part !== '' + ); + + // Unir los valores filtrados con el formato deseado + return filteredParts.join(', '); +}; + +const locationProperties = [ + 'postcode', + (obj) => + obj.city + ? `${obj.city}${obj.province?.name ? `(${obj.province.name})` : ''}` + : null, + (obj) => obj.country?.name, +]; const modelValue = ref( - props.location - ? `${props.location?.postcode} - ${props.location?.city}(${props.location?.province?.name}), ${props.location?.country?.name}` - : null + props.location ? formatLocation(props.location, locationProperties) : null ); function showLabel(data) { - return `${data.code} - ${data.town}(${data.province}), ${data.country}`; + const dataProperties = [ + 'code', + (obj) => (obj.town ? `${obj.town}(${obj.province})` : null), + 'country', + ]; + return formatLocation(data, dataProperties); } + const handleModelValue = (data) => { emit('update:model-value', data); }; From f06723a9192a158bbdff8fb160e664d994692f68 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 23 Sep 2024 11:39:10 +0200 Subject: [PATCH 2/3] test: VnLocation --- .../integration/vnComponent/vnLocation.spec.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/cypress/integration/vnComponent/vnLocation.spec.js b/test/cypress/integration/vnComponent/vnLocation.spec.js index 3533a3c1f..15ab53d17 100644 --- a/test/cypress/integration/vnComponent/vnLocation.spec.js +++ b/test/cypress/integration/vnComponent/vnLocation.spec.js @@ -36,20 +36,23 @@ describe('VnLocation', () => { }); it('Fin by postalCode', () => { const postCode = '46600'; + const postCodeLabel = '46600, Valencia(Province one), España'; const firstOption = '[role="listbox"] .q-item:nth-child(1)'; cy.get(inputLocation).click(); cy.get(inputLocation).clear(); cy.get(inputLocation).type(postCode); - cy.get(locationOptions).should('have.length.at.least', 2); + cy.get(locationOptions) + .get(':nth-child(1)') + .should('have.length.at.least', 2); + cy.get( + firstOption.concat(' > .q-item__section > .q-item__label--caption') + ).should('have.text', postCodeLabel); cy.get(firstOption).click(); cy.get('.q-btn-group > .q-btn--standard > .q-btn__content > .q-icon').click(); cy.reload(); cy.waitForElement('.q-form'); - cy.get(inputLocation).should( - 'have.value', - '46600 - Valencia(Province one), España' - ); + cy.get(inputLocation).should('have.value', postCodeLabel); }); it('Create postCode', () => { From 013a76cbce074ef727b371ce949bbf79b8f75f7e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 23 Sep 2024 11:48:00 +0200 Subject: [PATCH 3/3] test: VnLocation --- src/components/common/VnLocation.vue | 3 --- test/cypress/integration/vnComponent/vnLocation.spec.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/common/VnLocation.vue b/src/components/common/VnLocation.vue index c3b07c72c..633d32b85 100644 --- a/src/components/common/VnLocation.vue +++ b/src/components/common/VnLocation.vue @@ -13,7 +13,6 @@ const props = defineProps({ }, }); const formatLocation = (obj, properties) => { - // Crear un array con las propiedades del objeto const parts = properties.map((prop) => { if (typeof prop === 'string') { return obj[prop]; @@ -23,12 +22,10 @@ const formatLocation = (obj, properties) => { return null; }); - // Filtrar los valores que no son null o undefined const filteredParts = parts.filter( (part) => part !== null && part !== undefined && part !== '' ); - // Unir los valores filtrados con el formato deseado return filteredParts.join(', '); }; diff --git a/test/cypress/integration/vnComponent/vnLocation.spec.js b/test/cypress/integration/vnComponent/vnLocation.spec.js index 15ab53d17..1872d3591 100644 --- a/test/cypress/integration/vnComponent/vnLocation.spec.js +++ b/test/cypress/integration/vnComponent/vnLocation.spec.js @@ -34,7 +34,7 @@ describe('VnLocation', () => { cy.visit('/#/supplier/567/fiscal-data', { timeout: 7000 }); cy.waitForElement('.q-form'); }); - it('Fin by postalCode', () => { + it('Find by postalCode', () => { const postCode = '46600'; const postCodeLabel = '46600, Valencia(Province one), España'; const firstOption = '[role="listbox"] .q-item:nth-child(1)';