From 1193eaa07344e018a98b8b6550c79d8b06a209f1 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 18 Dec 2024 09:04:37 +0100 Subject: [PATCH 1/5] test: refs #7052 add unit tests for EditTableCellValueForm component --- .../components/EditTableCellValueForm.spec.js | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/vitest/__tests__/components/EditTableCellValueForm.spec.js diff --git a/test/vitest/__tests__/components/EditTableCellValueForm.spec.js b/test/vitest/__tests__/components/EditTableCellValueForm.spec.js new file mode 100644 index 000000000..a0a4142fa --- /dev/null +++ b/test/vitest/__tests__/components/EditTableCellValueForm.spec.js @@ -0,0 +1,55 @@ +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', () => { + 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: {} }, + ]; + const editUrl = '/api/edit'; + + beforeAll(() => { + vi.spyOn(axios, 'post').mockResolvedValue({ status: 200 }); + vm = createWrapper(EditForm, { + props: { + rows: mockRows, + fieldsOptions: mockFieldsOptions, + editUrl, + }, + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('onSubmit()', () => { + it('should call axios.post with the correct parameters in the payload', async () => { + const selectedField = { field: 'fieldA', component: 'input', attrs: {} }; + const newValue = 'Test Value'; + + vm.selectedField = selectedField; + vm.newValue = newValue; + + await vm.onSubmit(); + + 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.lines).toContainEqual( + expect.objectContaining({ id: 1, itemFk: 101 }) + ); + + expect(vm.isLoading).toEqual(false); + }); + }); +}); From 53c1040cd8b479f788ea738f8c2685b098b798b8 Mon Sep 17 00:00:00 2001 From: jgallego Date: Sun, 29 Dec 2024 10:05:56 +0100 Subject: [PATCH 2/5] 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); }); From 1e0d444e85a59c5e3a892fc77bff47d8f0317b53 Mon Sep 17 00:00:00 2001 From: jgallego Date: Sun, 29 Dec 2024 10:06:30 +0100 Subject: [PATCH 3/5] refactor: refs #7052 remove unnecessary console logs from EditTableCellValueForm tests --- src/components/__tests__/EditTableCellValueForm.spec.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/__tests__/EditTableCellValueForm.spec.js b/src/components/__tests__/EditTableCellValueForm.spec.js index 8cd8140ef..54f4c0a1a 100644 --- a/src/components/__tests__/EditTableCellValueForm.spec.js +++ b/src/components/__tests__/EditTableCellValueForm.spec.js @@ -49,8 +49,6 @@ describe.only('EditForm', () => { expect(payload.newValue).toEqual(newValue); expect(payload.lines).toEqual(expect.arrayContaining(mockRows)); - console.log('payload.lines', payload.lines); - console.log('mockRows', expect.arrayContaining(mockRows)); expect(vm.isLoading).toEqual(false); }); From 55ab9fea3e2f10f05df78aa12f133af9bc5bf013 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 30 Dec 2024 08:55:00 +0100 Subject: [PATCH 4/5] test: refs #7052 remove .only from EditTableCellValueForm test suite --- src/components/__tests__/EditTableCellValueForm.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/__tests__/EditTableCellValueForm.spec.js b/src/components/__tests__/EditTableCellValueForm.spec.js index 54f4c0a1a..fa47d8f73 100644 --- a/src/components/__tests__/EditTableCellValueForm.spec.js +++ b/src/components/__tests__/EditTableCellValueForm.spec.js @@ -5,7 +5,7 @@ import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; const fieldA = 'fieldA'; const fieldB = 'fieldB'; -describe.only('EditForm', () => { +describe('EditForm', () => { let vm; const mockRows = [ { id: 1, itemFk: 101 }, From d67ae3cafb06b09876a65b7e8083e43a456377c9 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 30 Dec 2024 14:53:08 +0100 Subject: [PATCH 5/5] style: update CustomerBalance.vue to set label color --- src/pages/Customer/Card/CustomerBalance.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/Customer/Card/CustomerBalance.vue b/src/pages/Customer/Card/CustomerBalance.vue index 712be5e09..04ef5f882 100644 --- a/src/pages/Customer/Card/CustomerBalance.vue +++ b/src/pages/Customer/Card/CustomerBalance.vue @@ -84,6 +84,7 @@ const columns = computed(() => [ label: t('Creation date'), format: ({ created }) => toDateHourMin(created), cardVisible: true, + style: 'color: var(--vn-label-color)', }, { align: 'left',