test: refs #8647 fix warning

This commit is contained in:
Javier Segarra 2025-02-28 10:07:45 +01:00
parent 092e6e427f
commit f64c2a2854
5 changed files with 22 additions and 23 deletions

View File

@ -11,6 +11,9 @@ describe('VnTable', () => {
propsData: {
columns: [],
},
attrs: {
'data-key': 'test',
},
});
vm = wrapper.vm;

View File

@ -58,7 +58,7 @@ function onFileChange(files) {
function mapperDms(data) {
const formData = new FormData();
const { files } = data;
if (files) formData.append(files?.name, files);
if (files) files.forEach((file) => formData.append(file?.name, file));
const dms = {
hasFile: !!data.hasFile,

View File

@ -40,7 +40,12 @@ describe('VnDms', () => {
companyFk: 2,
dmsTypeFk: 3,
description: 'This is a test description',
files: { name: 'example.txt', content: new Blob(['file content'], { type: 'text/plain' })},
files: [
{
name: 'example.txt',
content: new Blob(['file content'], { type: 'text/plain' }),
},
],
};
const expectedBody = {
@ -59,7 +64,7 @@ describe('VnDms', () => {
url: '/test',
formInitialData: { id: 1, reference: 'test' },
model: 'Worker',
}
},
});
wrapper = wrapper.wrapper;
vm = wrapper.vm;
@ -79,7 +84,7 @@ describe('VnDms', () => {
it('should map DMS data correctly and add file to FormData', () => {
const [formData, params] = vm.mapperDms(data);
expect(formData.get('example.txt')).toBe(data.files);
expect([formData.get('example.txt')]).toStrictEqual(data.files);
expect(expectedBody).toEqual(params.params);
});
@ -98,7 +103,7 @@ describe('VnDms', () => {
expect(vm.getUrl()).toBe('/test');
});
it('should returns url dms/"props.formInitialData.id"/updateFile when prop url is null', async () => {
it('should returns url dms/"props.formInitialData.id"/updateFile when prop url is null', async () => {
await wrapper.setProps({ url: null });
expect(vm.getUrl()).toBe('dms/1/updateFile');
});
@ -113,7 +118,9 @@ describe('VnDms', () => {
describe('save', () => {
it('should save data correctly', async () => {
await vm.save();
expect(postMock).toHaveBeenCalledWith(vm.getUrl(), expect.any(FormData), { params: expectedBody });
expect(postMock).toHaveBeenCalledWith(vm.getUrl(), expect.any(FormData), {
params: expectedBody,
});
expect(wrapper.emitted('onDataSaved')).toBeTruthy();
});
});
@ -127,8 +134,8 @@ describe('VnDms', () => {
warehouseFk: 2,
companyFk: 3,
dmsTypeFk: 2,
description: 'This is a test description'
}
description: 'This is a test description',
};
await wrapper.setProps({ formInitialData: testData });
vm.defaultData();
@ -137,10 +144,10 @@ describe('VnDms', () => {
it('should add reference with "route.params.id" to dms if formInitialData is null', async () => {
await wrapper.setProps({ formInitialData: null });
vm.route.params.id= '111';
vm.route.params.id = '111';
vm.defaultData();
expect(vm.dms.reference).toBe('111');
});
});
});
});

View File

@ -1,16 +1,6 @@
import {
describe,
it,
expect,
vi,
beforeAll,
afterEach,
beforeEach,
afterAll,
} from 'vitest';
import { describe, it, expect, vi, afterEach, beforeEach, afterAll } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper';
import VnNotes from 'src/components/ui/VnNotes.vue';
import vnDate from 'src/boot/vnDate';
describe('VnNotes', () => {
let vm;
@ -34,7 +24,7 @@ describe('VnNotes', () => {
) {
vi.spyOn(axios, 'get').mockResolvedValue({ data: [] });
wrapper = createWrapper(VnNotes, {
propsData: options,
propsData: { ...defaultOptions, ...options },
});
wrapper = wrapper.wrapper;
vm = wrapper.vm;

View File

@ -110,7 +110,6 @@ export function createWrapper(component, options) {
mocks: {
t: (tKey) => tKey,
$t: (tKey) => tKey,
$route: () => vi.fn(),
},
};