import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { createWrapper } from 'app/test/vitest/helper'; import EntryPreAccount from '../EntryPreAccount.vue'; import axios from 'axios'; describe('EntryPreAccount', () => { let wrapper; let vm; beforeAll(() => { vi.spyOn(axios, 'get').mockImplementation((url) => { if (url == 'EntryConfigs/findOne') return { data: { maxDays: 90, defaultDays: 30 } }; return { 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(); }); }); });