From b42385d7d6113455def4ab4fc024d440e439f1bd Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 2 Sep 2024 16:47:54 +0200 Subject: [PATCH] refactor: refs #6900 create new expense form --- src/components/CreateNewExpenseForm.vue | 52 ++++++++ src/pages/InvoiceIn/Card/InvoiceInVat.vue | 118 ++---------------- .../invoiceIn/invoiceInBasicData.spec.js | 3 +- .../invoiceIn/invoiceInVat.spec.js | 20 ++- 4 files changed, 73 insertions(+), 120 deletions(-) create mode 100644 src/components/CreateNewExpenseForm.vue diff --git a/src/components/CreateNewExpenseForm.vue b/src/components/CreateNewExpenseForm.vue new file mode 100644 index 000000000..a04033540 --- /dev/null +++ b/src/components/CreateNewExpenseForm.vue @@ -0,0 +1,52 @@ + + + + +es: + New expense: Nuevo gasto + Code: Código + It's a withholding: Es una retención + Description: Descripción + diff --git a/src/pages/InvoiceIn/Card/InvoiceInVat.vue b/src/pages/InvoiceIn/Card/InvoiceInVat.vue index 6142e3a15..f0f637a5c 100644 --- a/src/pages/InvoiceIn/Card/InvoiceInVat.vue +++ b/src/pages/InvoiceIn/Card/InvoiceInVat.vue @@ -2,19 +2,17 @@ import { ref, computed } from 'vue'; import { useRoute } from 'vue-router'; import { useI18n } from 'vue-i18n'; -import { useQuasar } from 'quasar'; -import axios from 'axios'; import { useArrayData } from 'src/composables/useArrayData'; import { getTotal } from 'src/composables/getTotal'; import { toCurrency } from 'src/filters'; import FetchData from 'src/components/FetchData.vue'; import VnSelect from 'src/components/common/VnSelect.vue'; import CrudModel from 'src/components/CrudModel.vue'; -import VnInput from 'src/components/common/VnInput.vue'; import VnInputNumber from 'src/components/common/VnInputNumber.vue'; +import VnSelectDialog from 'src/components/common/VnSelectDialog.vue'; +import CreateNewExpenseForm from 'src/components/CreateNewExpenseForm.vue'; const { t } = useI18n(); -const quasar = useQuasar(); const arrayData = useArrayData(); const invoiceIn = computed(() => arrayData.store.data); @@ -24,15 +22,7 @@ const expenses = ref([]); const sageTaxTypes = ref([]); const sageTransactionTypes = ref([]); const rowsSelected = ref([]); -const newExpense = ref({ - code: undefined, - isWithheld: false, - description: undefined, -}); - const invoiceInFormRef = ref(); -const expensesRef = ref(); -const newExpenseRef = ref(); defineProps({ actionIcon: { @@ -133,37 +123,6 @@ function taxRate(invoiceInTax) { return (taxTypeSage / 100) * taxableBase; } -async function addExpense() { - try { - if (!newExpense.value.code) throw new Error(t(`The code can't be empty`)); - if (isNaN(newExpense.value.code)) - throw new Error(t(`The code have to be a number`)); - if (!newExpense.value.description) - throw new Error(t(`The description can't be empty`)); - - const data = [ - { - id: newExpense.value.code, - isWithheld: newExpense.value.isWithheld, - name: newExpense.value.description, - }, - ]; - - await axios.post(`Expenses`, data); - await expensesRef.value.fetch(); - quasar.notify({ - type: 'positive', - message: t('globals.dataSaved'), - }); - newExpenseRef.value.hide(); - } catch (error) { - quasar.notify({ - type: 'negative', - message: t(`${error.message}`), - }); - } -} - const formatOpt = (row, { model, options }, prop) => { const obj = row[model]; const option = options.find(({ id }) => id == obj); @@ -205,7 +164,7 @@ const formatOpt = (row, { model, options }, prop) => { > - - + - + + { - - - - - - - {{ t('New expense') }} - - - - - - - - - - - - - - - - - - - { }); it('should throw an error creating a new dms if a file is not attached', () => { - cy.get(formInputs).eq(5).click(); - cy.get(formInputs).eq(5).type('{selectall}{backspace}'); + cy.get(formInputs).eq(7).type('{selectall}{backspace}'); cy.get(documentBtns).eq(0).click(); cy.get(dialogActionBtns).eq(1).click(); cy.get('.q-notification__message').should( diff --git a/test/cypress/integration/invoiceIn/invoiceInVat.spec.js b/test/cypress/integration/invoiceIn/invoiceInVat.spec.js index 018ae7a53..b84d743d1 100644 --- a/test/cypress/integration/invoiceIn/invoiceInVat.spec.js +++ b/test/cypress/integration/invoiceIn/invoiceInVat.spec.js @@ -3,13 +3,14 @@ describe('InvoiceInVat', () => { const thirdRow = 'tbody > :nth-child(3)'; const firstLineVat = 'tbody > :nth-child(1) > :nth-child(4)'; const dialogInputs = '.q-dialog label input'; - const dialogBtns = '.q-dialog button'; - const acrossInput = 'tbody tr:nth-child(1) td:nth-child(2) .default-icon'; + const addBtn = 'tbody tr:nth-child(1) td:nth-child(2) .--add-icon'; const randomInt = Math.floor(Math.random() * 100); beforeEach(() => { cy.login('developer'); cy.visit(`/#/invoice-in/1/vat`); + cy.intercept('GET', '/api/InvoiceIns/1/getTotals').as('lastCall'); + cy.wait('@lastCall'); }); it('should edit the sage iva', () => { @@ -26,22 +27,15 @@ describe('InvoiceInVat', () => { }); it('should remove the first line', () => { - cy.removeRow(2); - }); - - it('should throw an error if there are fields undefined', () => { - cy.get(acrossInput).click(); - cy.get(dialogBtns).eq(2).click(); - cy.get('.q-notification__message').should('have.text', "The code can't be empty"); + cy.removeRow(1); }); it('should correctly handle expense addition', () => { - cy.get(acrossInput).click(); + cy.get(addBtn).click(); cy.get(dialogInputs).eq(0).type(randomInt); - cy.get(dialogInputs).eq(1).click(); cy.get(dialogInputs).eq(1).type('This is a dummy expense'); - cy.get(dialogBtns).eq(2).click(); - cy.get('.q-notification__message').should('have.text', 'Data saved'); + cy.get('button[type="submit"]').click(); + cy.get('.q-notification__message').should('have.text', 'Data created'); }); });