test: refs #8277 add unit tests for EntryPreAccount component
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
e127c4cec9
commit
e8af2b6a74
|
@ -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') },
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue