feat: refs #7055 added new test case
gitea/salix-front/pipeline/pr-dev Build queued... Details

This commit is contained in:
PAU ROVIRA ROSALENY 2025-01-09 08:25:23 +01:00
parent 149cca37ef
commit b466dfe034
1 changed files with 33 additions and 26 deletions

View File

@ -1,6 +1,6 @@
import { createWrapper, axios } from 'app/test/vitest/helper'; import { createWrapper, axios } from 'app/test/vitest/helper';
import FilterItemForm from 'components/FilterItemForm.vue'; import FilterItemForm from 'components/FilterItemForm.vue';
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; import { vi, beforeAll, describe, expect, it } from 'vitest';
describe('FilterItemForm', () => { describe('FilterItemForm', () => {
let vm; let vm;
@ -15,40 +15,42 @@ describe('FilterItemForm', () => {
vm = wrapper.vm; vm = wrapper.vm;
wrapper = wrapper.wrapper; wrapper = wrapper.wrapper;
vi.spyOn(axios, 'get').mockResolvedValue({ data: [] }); vi.spyOn(axios, 'get').mockResolvedValue({
data: [
{
id: 999996,
name: 'Bolas de madera',
size: 2,
inkFk: null,
producerFk: null,
},
],
});
}); });
it('should set up itemFilter and itemFilterParams correctly', async () => { it('should filter data and populate tableRows for table display', async () => {
wrapper.setProps({ wrapper.setProps({
itemFilter: { itemFilter: {
include: [ include: [
{ relation: 'producer', scope: { fields: ['name'] } }, { relation: 'producer', scope: { fields: ['name'] } },
{ relation: 'ink', scope: { fields: ['name'] } }, { relation: 'ink', scope: { fields: ['name'] } },
], ],
where: { name: { like: '%bolas de madera%' } }, where: { name: { like: '%bolas de madera%' } },
}, },
itemFilterParams: { name: 'bolas de madera' }, itemFilterParams: { name: 'bolas de madera' },
}); });
await vm.onSubmit(); await vm.onSubmit();
const expectedFilter = { expect(vm.tableRows).toEqual([
include: [ {
{ relation: 'producer', scope: { fields: ['name'] } }, id: 999996,
{ relation: 'ink', scope: { fields: ['name'] } }, name: 'Bolas de madera',
], size: 2,
where: { inkFk: null,
name: { like: '%bolas de madera%' }, producerFk: null,
size: 'large',
producerFk: 1,
typeFk: 2,
inkFk: 3,
}, },
}; ]);
expect(axios.get).toHaveBeenCalledWith('Items/withName', {
params: { filter: JSON.stringify(expectedFilter) },
});
}); });
it('should handle an empty itemFilterParams correctly', async () => { it('should handle an empty itemFilterParams correctly', async () => {
@ -68,4 +70,9 @@ describe('FilterItemForm', () => {
params: { filter: JSON.stringify(expectedFilter) }, 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]);
});
});