From 14ca6d73f1a992bdbfe7134e6fac5f73cdfa9fe2 Mon Sep 17 00:00:00 2001 From: Jtubau Date: Tue, 17 Dec 2024 07:36:16 +0100 Subject: [PATCH 1/2] feat: refs #7074 tests for fns setData(), parseDms() and showFormDialog() --- .../components/common/VnDmsList.spec.js | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 test/vitest/__tests__/components/common/VnDmsList.spec.js diff --git a/test/vitest/__tests__/components/common/VnDmsList.spec.js b/test/vitest/__tests__/components/common/VnDmsList.spec.js new file mode 100644 index 000000000..49228ddf8 --- /dev/null +++ b/test/vitest/__tests__/components/common/VnDmsList.spec.js @@ -0,0 +1,93 @@ +import { createWrapper, axios } from 'app/test/vitest/helper'; +import VnDmsList from 'src/components/common/VnDmsList.vue'; +import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; + +describe('VnDmsList', () => { + let vm; + + beforeAll(() => { + vi.spyOn(axios, 'get').mockResolvedValue({ data: [] }); + vm = createWrapper(VnDmsList, { + props: { + model: 'WorkerDms/1110/filter', + defaultDmsCode: 'hhrrData', + filter: 'wd.workerFk', + updateModel: 'Workers', + deleteModel: 'WorkerDms', + downloadModel: 'WorkerDms' + } + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('setData()', () => { + const data = [ + { + userFk: 1, + name: 'Jessica', + lastName: 'Jones', + file: '4.jpg', + created: '2021-07-28 21:00:00' + }, + { + userFk: 2, + name: 'Bruce', + lastName: 'Banner', + created: '2022-07-28 21:00:00', + dms: { + userFk: 2, + name: 'Bruce', + lastName: 'BannerDMS', + created: '2022-07-28 21:00:00', + file: '4.jpg', + } + }, + { + userFk: 3, + name: 'Natasha', + lastName: 'Romanoff', + file: '4.jpg', + created: '2021-10-28 21:00:00' + } + ] + + it('Should replace objects that contain the "dms" property with the value of the same and sort by creation date', () => { + vm.setData(data); + expect([vm.rows][0][0].lastName).toEqual('BannerDMS'); + expect([vm.rows][0][1].lastName).toEqual('Romanoff'); + + }); + }); + + describe('parseDms()', () => { + const dms = { + userFk: 1, + name: 'DMS 1' + }; + + const resultDms = { ...dms, userId:1}; + + it('Should add properties that end with "Fk" by changing the suffix to "Id"', () => { + const parsedDms = vm.parseDms(dms); + expect(parsedDms).toEqual(resultDms); + }); + }); + + describe('showFormDialog()', () => { + const dms = { + userFk: 1, + name: 'DMS 1' + }; + + const resultDms = { ...dms, userId:1}; + + it('should call fn parseDms() and set show true if dms is defined', () => { + vm.showFormDialog(dms); + expect(vm.formDialog.show).toEqual(true); + expect(vm.formDialog.dms).toEqual(resultDms); + }); + }); +}); \ No newline at end of file From 8ab10dda1b8e6461ed5392baa4d6ceb9bf28f286 Mon Sep 17 00:00:00 2001 From: Jtubau Date: Wed, 18 Dec 2024 08:07:44 +0100 Subject: [PATCH 2/2] refactor: refs #7074 move dms constant to global scope --- .../__tests__/components/common/VnDmsList.spec.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/test/vitest/__tests__/components/common/VnDmsList.spec.js b/test/vitest/__tests__/components/common/VnDmsList.spec.js index 49228ddf8..9649943a2 100644 --- a/test/vitest/__tests__/components/common/VnDmsList.spec.js +++ b/test/vitest/__tests__/components/common/VnDmsList.spec.js @@ -4,6 +4,10 @@ import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; describe('VnDmsList', () => { let vm; + const dms = { + userFk: 1, + name: 'DMS 1' + }; beforeAll(() => { vi.spyOn(axios, 'get').mockResolvedValue({ data: [] }); @@ -63,11 +67,6 @@ describe('VnDmsList', () => { }); describe('parseDms()', () => { - const dms = { - userFk: 1, - name: 'DMS 1' - }; - const resultDms = { ...dms, userId:1}; it('Should add properties that end with "Fk" by changing the suffix to "Id"', () => { @@ -77,11 +76,6 @@ describe('VnDmsList', () => { }); describe('showFormDialog()', () => { - const dms = { - userFk: 1, - name: 'DMS 1' - }; - const resultDms = { ...dms, userId:1}; it('should call fn parseDms() and set show true if dms is defined', () => {