diff --git a/src/pages/Entry/EntryPreAccount.vue b/src/pages/Entry/EntryPreAccount.vue index 8dbd7a4cd..2b5b42759 100644 --- a/src/pages/Entry/EntryPreAccount.vue +++ b/src/pages/Entry/EntryPreAccount.vue @@ -212,7 +212,7 @@ onBeforeMount(() => { watch(selectedRows, (nVal, oVal) => { const lastRow = nVal.at(-1); if (lastRow?.isBooked) selectedRows.value.pop(); - if (nVal.length > oVal.length && nVal.at(-1).invoiceInFk) + if (nVal.length > oVal.length && lastRow.invoiceInFk) quasar.dialog({ component: VnConfirm, componentProps: { title: t('entry.preAccount.hasInvoice') }, diff --git a/src/pages/Entry/__tests__/EntryPreAccount.spec.js b/src/pages/Entry/__tests__/EntryPreAccount.spec.js new file mode 100644 index 000000000..3cdb3cb02 --- /dev/null +++ b/src/pages/Entry/__tests__/EntryPreAccount.spec.js @@ -0,0 +1,58 @@ +import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; +import { createWrapper, axios } from 'app/test/vitest/helper'; +import EntryPreAccount from '../EntryPreAccount.vue'; + +describe('EntryPreAccount', () => { + let wrapper; + let vm; + + beforeAll(() => { + vi.spyOn(axios, 'get').mockImplementation(() => ({ data: [] })); + wrapper = createWrapper(EntryPreAccount); + vm = wrapper.vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('filterByDaysAgo()', () => { + it('should set daysAgo to DEFAULTDAYS if no value is provided', () => { + vm.filterByDaysAgo(); + expect(vm.daysAgo).toBe(vm.DEFAULTDAYS); + expect(vm.arrayData.store.userParams.daysAgo).toBe(vm.DEFAULTDAYS); + }); + + it('should set daysAgo to MAXDAYS if the value exceeds MAXDAYS', () => { + vm.filterByDaysAgo(500); + expect(vm.daysAgo).toBe(vm.MAXDAYS); + expect(vm.arrayData.store.userParams.daysAgo).toBe(vm.MAXDAYS); + }); + + it('should set daysAgo to the provided value if it is valid', () => { + vm.filterByDaysAgo(30); + expect(vm.daysAgo).toBe(30); + expect(vm.arrayData.store.userParams.daysAgo).toBe(30); + }); + }); + + describe('Dialog behavior when adding a new row', () => { + it('should open the dialog if the new row has invoiceInFk', async () => { + const dialogSpy = vi.spyOn(vm.quasar, 'dialog'); + const selectedRows = [{ id: 1, invoiceInFk: 123 }]; + vm.selectedRows = selectedRows; + await vm.$nextTick(); + expect(dialogSpy).toHaveBeenCalledWith({ + component: vm.VnConfirm, + componentProps: { title: vm.t('entry.preAccount.hasInvoice') }, + }); + }); + + it('should not open the dialog if the new row does not have invoiceInFk', async () => { + const dialogSpy = vi.spyOn(vm.quasar, 'dialog'); + vm.selectedRows = [{ id: 1, invoiceInFk: null }]; + await vm.$nextTick(); + expect(dialogSpy).not.toHaveBeenCalled(); + }); + }); +});