feat: refs #7055 created FilterItemForm test #1187

Merged
provira merged 8 commits from 7055-testFilterItemForm into dev 2025-01-14 06:03:51 +00:00
1 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,82 @@
import { createWrapper, axios } from 'app/test/vitest/helper';
import FilterItemForm from 'src/components/FilterItemForm.vue';
jsegarra marked this conversation as resolved Outdated

src
así seguimos el standard de los test
Por ejemplo en la #1197 hemos puesto src/components

src así seguimos el standard de los test Por ejemplo en la #1197 hemos puesto src/components

arreglado

arreglado
import { vi, beforeAll, describe, expect, it } from 'vitest';
describe('FilterItemForm', () => {
let vm;
let wrapper;
beforeAll(() => {
wrapper = createWrapper(FilterItemForm, {
props: {
url: 'Items/withName',
},
});
vm = wrapper.vm;
wrapper = wrapper.wrapper;
vi.spyOn(axios, 'get').mockResolvedValue({
data: [
{
id: 999996,
name: 'bolas de madera',
size: 2,
inkFk: null,
producerFk: null,
},
],
});
});
it('should filter data and populate tableRows for table display', async () => {
Review

Este it, debería comprobar el filtro que se le pasa a la petición de axios.
En el siguiente it, si que se comprueba estando vacío, y aquí que tiene valores no se comprueba? Tendría que haber expect en ambos casos

Este it, debería comprobar el filtro que se le pasa a la petición de axios. En el siguiente it, si que se comprueba estando vacío, y aquí que tiene valores no se comprueba? Tendría que haber expect en ambos casos
Review

añadido

añadido
vm.itemFilterParams.name = 'bolas de madera';
await vm.onSubmit();
const expectedFilter = {
include: [
{ relation: 'producer', scope: { fields: ['name'] } },
{ relation: 'ink', scope: { fields: ['name'] } },
],
where: {"name":{"like":"%bolas de madera%"}},
};
expect(axios.get).toHaveBeenCalledWith('Items/withName', {
Review

Es el mismo expect, pero creo que 2 ocurrencias se puede dar como bueno

Es el mismo expect, pero creo que 2 ocurrencias se puede dar como bueno
params: { filter: JSON.stringify(expectedFilter) },
});
expect(vm.tableRows).toEqual([
{
id: 999996,
name: 'bolas de madera',
size: 2,
inkFk: null,
producerFk: null,
},
]);
});
it('should handle an empty itemFilterParams correctly', async () => {
vm.itemFilterParams.name = null;
vm.itemFilterParams = {};
await vm.onSubmit();
const expectedFilter = {
include: [
{ relation: 'producer', scope: { fields: ['name'] } },
{ relation: 'ink', scope: { fields: ['name'] } },
],
where: {},
};
expect(axios.get).toHaveBeenCalledWith('Items/withName', {
params: { filter: JSON.stringify(expectedFilter) },
});
});
it('should emit "itemSelected" with the correct id and close the form', () => {
vm.selectItem({ id: 12345 });
expect(wrapper.emitted('itemSelected')[0]).toEqual([12345]);
});
});