test: refs #5926 improve VnDmsList tests with mock and data structure adjustments

This commit is contained in:
Alex Moreno 2025-03-21 11:15:53 +01:00
parent ab697c951d
commit 5e0c133eb3
1 changed files with 24 additions and 22 deletions

View File

@ -4,12 +4,15 @@ import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';
describe('VnDmsList', () => { describe('VnDmsList', () => {
let vm; let vm;
const dms = { const dms = {
userFk: 1, userFk: 1,
name: 'DMS 1' name: 'DMS 1',
}; };
beforeAll(() => { beforeAll(() => {
vi.mock('src/composables/getUrl', () => ({
getUrl: vi.fn().mockResolvedValue(''),
}));
vi.spyOn(axios, 'get').mockResolvedValue({ data: [] }); vi.spyOn(axios, 'get').mockResolvedValue({ data: [] });
vm = createWrapper(VnDmsList, { vm = createWrapper(VnDmsList, {
props: { props: {
@ -18,8 +21,8 @@ describe('VnDmsList', () => {
filter: 'wd.workerFk', filter: 'wd.workerFk',
updateModel: 'Workers', updateModel: 'Workers',
deleteModel: 'WorkerDms', deleteModel: 'WorkerDms',
downloadModel: 'WorkerDms' downloadModel: 'WorkerDms',
} },
}).vm; }).vm;
}); });
@ -29,46 +32,45 @@ describe('VnDmsList', () => {
describe('setData()', () => { describe('setData()', () => {
const data = [ const data = [
{ {
userFk: 1, userFk: 1,
name: 'Jessica', name: 'Jessica',
lastName: 'Jones', lastName: 'Jones',
file: '4.jpg', file: '4.jpg',
created: '2021-07-28 21:00:00' created: '2021-07-28 21:00:00',
}, },
{ {
userFk: 2, userFk: 2,
name: 'Bruce', name: 'Bruce',
lastName: 'Banner', lastName: 'Banner',
created: '2022-07-28 21:00:00', created: '2022-07-28 21:00:00',
dms: { dms: {
userFk: 2, userFk: 2,
name: 'Bruce', name: 'Bruce',
lastName: 'BannerDMS', lastName: 'BannerDMS',
created: '2022-07-28 21:00:00', created: '2022-07-28 21:00:00',
file: '4.jpg', file: '4.jpg',
} },
}, },
{ {
userFk: 3, userFk: 3,
name: 'Natasha', name: 'Natasha',
lastName: 'Romanoff', lastName: 'Romanoff',
file: '4.jpg', file: '4.jpg',
created: '2021-10-28 21:00:00' 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', () => { it('Should replace objects that contain the "dms" property with the value of the same and sort by creation date', () => {
vm.setData(data); vm.setData(data);
expect([vm.rows][0][0].lastName).toEqual('BannerDMS'); expect([vm.rows][0][0].lastName).toEqual('BannerDMS');
expect([vm.rows][0][1].lastName).toEqual('Romanoff'); expect([vm.rows][0][1].lastName).toEqual('Romanoff');
}); });
}); });
describe('parseDms()', () => { describe('parseDms()', () => {
const resultDms = { ...dms, userId:1}; const resultDms = { ...dms, userId: 1 };
it('Should add properties that end with "Fk" by changing the suffix to "Id"', () => { it('Should add properties that end with "Fk" by changing the suffix to "Id"', () => {
const parsedDms = vm.parseDms(dms); const parsedDms = vm.parseDms(dms);
expect(parsedDms).toEqual(resultDms); expect(parsedDms).toEqual(resultDms);
@ -76,12 +78,12 @@ describe('VnDmsList', () => {
}); });
describe('showFormDialog()', () => { describe('showFormDialog()', () => {
const resultDms = { ...dms, userId:1}; const resultDms = { ...dms, userId: 1 };
it('should call fn parseDms() and set show true if dms is defined', () => { it('should call fn parseDms() and set show true if dms is defined', () => {
vm.showFormDialog(dms); vm.showFormDialog(dms);
expect(vm.formDialog.show).toEqual(true); expect(vm.formDialog.show).toEqual(true);
expect(vm.formDialog.dms).toEqual(resultDms); expect(vm.formDialog.dms).toEqual(resultDms);
}); });
}); });
}); });