From 53c1040cd8b479f788ea738f8c2685b098b798b8 Mon Sep 17 00:00:00 2001 From: jgallego Date: Sun, 29 Dec 2024 10:05:56 +0100 Subject: [PATCH] refactor: refs #7052 move EditTableCellValueForm tests to a new location and enhance test coverage --- .../__tests__}/EditTableCellValueForm.spec.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) rename {test/vitest/__tests__/components => src/components/__tests__}/EditTableCellValueForm.spec.js (66%) diff --git a/test/vitest/__tests__/components/EditTableCellValueForm.spec.js b/src/components/__tests__/EditTableCellValueForm.spec.js similarity index 66% rename from test/vitest/__tests__/components/EditTableCellValueForm.spec.js rename to src/components/__tests__/EditTableCellValueForm.spec.js index a0a4142fa..8cd8140ef 100644 --- a/test/vitest/__tests__/components/EditTableCellValueForm.spec.js +++ b/src/components/__tests__/EditTableCellValueForm.spec.js @@ -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); });