refactor: refs #7052 move EditTableCellValueForm tests to a new location and enhance test coverage
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javi Gallego 2024-12-29 10:05:56 +01:00
parent 6acf6f8131
commit 53c1040cd8
1 changed files with 12 additions and 9 deletions

View File

@ -2,15 +2,18 @@ import { createWrapper, axios } from 'app/test/vitest/helper';
import EditForm from 'components/EditTableCellValueForm.vue';
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';
describe('EditForm', () => {
const fieldA = 'fieldA';
const fieldB = 'fieldB';
describe.only('EditForm', () => {
let vm;
const mockRows = [
{ id: 1, itemFk: 101 },
{ id: 2, itemFk: 102 },
];
const mockFieldsOptions = [
{ label: 'Field A', field: 'fieldA', component: 'input', attrs: {} },
{ label: 'Field B', field: 'fieldB', component: 'date', attrs: {} },
{ label: 'Field A', field: fieldA, component: 'input', attrs: {} },
{ label: 'Field B', field: fieldB, component: 'date', attrs: {} },
];
const editUrl = '/api/edit';
@ -31,7 +34,7 @@ describe('EditForm', () => {
describe('onSubmit()', () => {
it('should call axios.post with the correct parameters in the payload', async () => {
const selectedField = { field: 'fieldA', component: 'input', attrs: {} };
const selectedField = { field: fieldA, component: 'input', attrs: {} };
const newValue = 'Test Value';
vm.selectedField = selectedField;
@ -42,12 +45,12 @@ describe('EditForm', () => {
const payload = axios.post.mock.calls[0][1];
expect(axios.post).toHaveBeenCalledWith(editUrl, expect.any(Object));
expect(payload.field).toEqual('fieldA');
expect(payload.newValue).toEqual('Test Value');
expect(payload.field).toEqual(fieldA);
expect(payload.newValue).toEqual(newValue);
expect(payload.lines).toContainEqual(
expect.objectContaining({ id: 1, itemFk: 101 })
);
expect(payload.lines).toEqual(expect.arrayContaining(mockRows));
console.log('payload.lines', payload.lines);
console.log('mockRows', expect.arrayContaining(mockRows));
expect(vm.isLoading).toEqual(false);
});