From 2190a0c17dc7d5b6ba65deaf3b20cb548e8d9ef1 Mon Sep 17 00:00:00 2001 From: Javier Segarra <jsegarra@verdnatura.es> Date: Mon, 24 Mar 2025 14:41:44 +0100 Subject: [PATCH] test: refs #7356 removing unused mapper functions and updating default mapper logic --- src/components/FormModel.vue | 20 ++++----- src/pages/Customer/Card/CustomerBasicData.vue | 7 +--- .../Customer/Card/CustomerFiscalData.vue | 7 ---- .../components/CustomerNewPayment.vue | 12 ------ .../Ticket/Card/BasicData/TicketBasicData.vue | 10 ++--- .../Card/BasicData/TicketBasicDataView.vue | 8 ++-- .../ticket/ticketBasicData.spec.js | 42 ++++++++++++++++++- .../integration/ticket/ticketSms.spec.js | 12 +++++- 8 files changed, 72 insertions(+), 46 deletions(-) diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index c4d9a4149..663764ee6 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -69,7 +69,12 @@ const $props = defineProps({ }, mapper: { type: Function, - default: null, + default: (formData, originalData) => { + return getUpdatedValues( + Object.keys(getDifferences(formData, originalData)), + formData, + ); + }, }, clearStoreOnUnmount: { type: Boolean, @@ -221,9 +226,7 @@ async function save() { isLoading.value = true; try { formData.value = trimData(formData.value); - const body = $props.mapper - ? $props.mapper(formData.value, originalData.value) - : formData.value; + const body = $props.mapper(formData.value, originalData.value); const method = $props.urlCreate ? 'post' : 'patch'; const url = $props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url; @@ -289,12 +292,7 @@ function trimData(data) { } return data; } -function onBeforeSave(formData, originalData) { - return getUpdatedValues( - Object.keys(getDifferences(formData, originalData)), - formData, - ); -} + async function onKeyup(evt) { if (evt.key === 'Enter' && !('prevent-submit' in attrs)) { const input = evt.target; @@ -331,7 +329,7 @@ defineExpose({ class="q-pa-md" :style="maxWidth ? 'max-width: ' + maxWidth : ''" id="formModel" - :mapper="onBeforeSave" + :mapper="mapper" > <QCard> <slot diff --git a/src/pages/Customer/Card/CustomerBasicData.vue b/src/pages/Customer/Card/CustomerBasicData.vue index 9c9d1b50b..6d9110ed4 100644 --- a/src/pages/Customer/Card/CustomerBasicData.vue +++ b/src/pages/Customer/Card/CustomerBasicData.vue @@ -52,12 +52,7 @@ function onBeforeSave(formData, originalData) { @on-fetch="(data) => (businessTypes = data)" auto-load /> - <FormModel - :url-update="`Clients/${route.params.id}`" - auto-load - :mapper="onBeforeSave" - model="Customer" - > + <FormModel :url-update="`Clients/${route.params.id}`" auto-load model="Customer"> <template #form="{ data, validate }"> <VnRow> <VnInput diff --git a/src/pages/Customer/Card/CustomerFiscalData.vue b/src/pages/Customer/Card/CustomerFiscalData.vue index 93909eb9c..518bf1242 100644 --- a/src/pages/Customer/Card/CustomerFiscalData.vue +++ b/src/pages/Customer/Card/CustomerFiscalData.vue @@ -31,12 +31,6 @@ function handleLocation(data, location) { data.provinceFk = provinceFk; data.countryFk = countryFk; } -function onBeforeSave(formData, originalData) { - return getUpdatedValues( - Object.keys(getDifferences(formData, originalData)), - formData, - ); -} async function checkEtChanges(data, _, originalData) { const equalizatedHasChanged = originalData.isEqualizated != data.isEqualizated; @@ -75,7 +69,6 @@ async function acceptPropagate({ isEqualizated }) { :url-update="`Clients/${route.params.id}/updateFiscalData`" auto-load model="Customer" - :mapper="onBeforeSave" observe-form-changes @on-data-saved="checkEtChanges" > diff --git a/src/pages/Customer/components/CustomerNewPayment.vue b/src/pages/Customer/components/CustomerNewPayment.vue index ac80fdaa4..5b351d598 100644 --- a/src/pages/Customer/components/CustomerNewPayment.vue +++ b/src/pages/Customer/components/CustomerNewPayment.vue @@ -103,17 +103,6 @@ const calculateFromDeliveredAmount = (event) => { initialData.amountToReturn = parseFloat(event) - initialData.amountPaid; }; -function onBeforeSave(data) { - const exceededAmount = data.amountPaid > maxAmount.value; - if (isCash.value && exceededAmount) - return notify(t('Amount exceeded', { maxAmount: maxAmount.value }), 'negative'); - - if (isCash.value && shouldSendEmail.value && !data.email) - return notify(t('There is no assigned email for this client'), 'negative'); - - return data; -} - async function onDataSaved(formData, { id }) { try { if (shouldSendEmail.value && isCash.value) @@ -182,7 +171,6 @@ async function getAmountPaid() { ref="formModelRef" :form-initial-data="initialData" :url-create="urlCreate" - :mapper="onBeforeSave" @on-data-saved="onDataSaved" :prevent-submit="true" > diff --git a/src/pages/Ticket/Card/BasicData/TicketBasicData.vue b/src/pages/Ticket/Card/BasicData/TicketBasicData.vue index 055c9a0ff..83c621b20 100644 --- a/src/pages/Ticket/Card/BasicData/TicketBasicData.vue +++ b/src/pages/Ticket/Card/BasicData/TicketBasicData.vue @@ -91,7 +91,7 @@ const totalPrice = computed(() => { const totalNewPrice = computed(() => { return rows.value.reduce( (acc, item) => acc + item.component.newPrice * item.quantity, - 0 + 0, ); }); @@ -210,18 +210,18 @@ onMounted(async () => { flat > <template #body-cell-item="{ row }"> - <QTd @click.stop class="link"> - <QBtn flat> + <QTd align="center"> + <span @click.stop class="link"> {{ row.itemFk }} <ItemDescriptorProxy :id="row.itemFk" /> - </QBtn> + </span> </QTd> </template> <template #body-cell-description="{ row }"> <QTd style="min-width: 120px; max-width: 120px"> <div class="column q-pb-xs" style="min-width: 120px"> <span>{{ row.item.name }}</span> - <FetchedTags :item="row.item" class="full-width" /> + <FetchedTags :item="row.item" class="full-width" :columns="6" /> </div> </QTd> </template> diff --git a/src/pages/Ticket/Card/BasicData/TicketBasicDataView.vue b/src/pages/Ticket/Card/BasicData/TicketBasicDataView.vue index 3c2fe95e5..23c73a0cf 100644 --- a/src/pages/Ticket/Card/BasicData/TicketBasicDataView.vue +++ b/src/pages/Ticket/Card/BasicData/TicketBasicDataView.vue @@ -1,7 +1,7 @@ <script setup> import { ref, computed } from 'vue'; import { useI18n } from 'vue-i18n'; -import { useRouter } from 'vue-router'; +import { useRouter, useRoute } from 'vue-router'; import TicketBasicData from './TicketBasicData.vue'; import TicketBasicDataForm from './TicketBasicDataForm.vue'; @@ -13,6 +13,7 @@ import { useArrayData } from 'src/composables/useArrayData'; const { notify } = useNotify(); const router = useRouter(); +const route = useRoute(); const { t } = useI18n(); const stepperRef = ref(null); const { openConfirmationModal } = useVnConfirm(); @@ -21,6 +22,7 @@ const step = ref(1); const haveNegatives = ref(true); const ticket = computed(() => useArrayData('Ticket').store?.data); +const entityId = computed(() => +route?.params?.id); const isFormInvalid = () => { return ( @@ -44,7 +46,7 @@ const getPriceDifference = async () => { shipped: ticket.value.shipped, }; const { data } = await axios.post( - `tickets/${formData.value.id}/priceDifference`, + `tickets/${entityId.value}/priceDifference`, params, ); ticket.value.sale = data; @@ -71,7 +73,7 @@ const submit = async () => { }; const { data } = await axios.post( - `tickets/${formData.value.id}/componentUpdate`, + `tickets/${entityId.value}/componentUpdate`, params, ); diff --git a/test/cypress/integration/ticket/ticketBasicData.spec.js b/test/cypress/integration/ticket/ticketBasicData.spec.js index ac57e47e6..c5a8b0464 100644 --- a/test/cypress/integration/ticket/ticketBasicData.spec.js +++ b/test/cypress/integration/ticket/ticketBasicData.spec.js @@ -6,7 +6,47 @@ describe('TicketRequest', () => { cy.visit('/#/ticket/31/basic-data'); }); - it('Should load layout', () => { + it('Should redirect to customer basic data', () => { cy.get('.q-page').should('be.visible'); + cy.get(':nth-child(2) > div > .text-primary').click(); + cy.get('[data-cy="Address_select"]').click(); + cy.get('.q-btn-group > [data-v-d4506789=""] > .q-btn__content > .q-icon').click(); + cy.get( + '[data-cy="CustomerBasicData-menu-item"] > .q-item__section--main', + ).click(); + cy.url().should('include', '/customer/1104/basic-data'); + }); + it.only('stepper', () => { + cy.get('.q-stepper__tab--active').should('have.class', 'q-stepper__tab--active'); + + cy.get('.q-stepper__nav > .q-btn--standard').click(); + cy.get('.q-stepper__tab--done').should('have.class', 'q-stepper__tab--done'); + cy.get('.q-stepper__tab--active').should('have.class', 'q-stepper__tab--active'); + cy.get('tr:nth-child(1)>:nth-child(1)>span').should('have.class', 'link').click(); + cy.dataCy('ItemDescriptor').should('exist'); + cy.get('.q-drawer__content > :nth-child(1) > :nth-child(2) > span').should( + 'have.text', + 'Price: €34.40', + ); + cy.get('.q-drawer__content > :nth-child(1) > :nth-child(3) > span').should( + 'have.text', + 'New price: €34.20', + ); + cy.get('.q-drawer__content > :nth-child(1) > :nth-child(4) > span').should( + 'have.text', + 'Difference: €0.20', + ); + cy.get( + ':nth-child(3) > .q-radio > .q-radio__inner > .q-radio__bg > .q-radio__check', + ).should('have.class', 'q-radio__check'); + cy.get( + '.q-stepper__step-inner > .q-drawer-container > .q-drawer > .q-drawer__content', + ).click(); + cy.get(':nth-child(2) > :nth-child(1) > .text-weight-bold').click(); + cy.get(':nth-child(3) > .q-radio > .q-radio__inner').should( + 'have.class', + 'q-radio__inner--truthy', + ); + cy.get('.q-drawer__content > :nth-child(2)').click(); }); }); diff --git a/test/cypress/integration/ticket/ticketSms.spec.js b/test/cypress/integration/ticket/ticketSms.spec.js index 69a48b341..0978898d9 100644 --- a/test/cypress/integration/ticket/ticketSms.spec.js +++ b/test/cypress/integration/ticket/ticketSms.spec.js @@ -3,10 +3,20 @@ describe('TicketRequest', () => { beforeEach(() => { cy.login('developer'); cy.viewport(1920, 1080); - cy.visit('/#/ticket/31/sms'); + cy.visit('/#/ticket/32/sms'); }); it('Should load layout', () => { cy.get('.q-page').should('be.visible'); + cy.get('.q-infinite-scroll > :nth-child(1)').should( + 'have.text', + '0004 444444444Lorem ipsum dolor sit amet, consectetur adipiscing elit.2001-01-01 00:00:00OK', + ); + cy.get( + ':nth-child(1) > .q-item > .q-item__section--top > .column > .q-avatar > .q-avatar__content > .q-img > .q-img__container > .q-img__image', + ).should('have.class', 'q-img__image--loaded'); + cy.get( + ':nth-child(1) > .q-item > .q-item__section--side.justify-center > .center > .q-chip > .q-chip__content', + ).should('have.class', 'q-chip__content'); }); });