This commit is contained in:
parent
149cca37ef
commit
b466dfe034
|
@ -1,6 +1,6 @@
|
|||
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||
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', () => {
|
||||
let vm;
|
||||
|
@ -15,10 +15,20 @@ describe('FilterItemForm', () => {
|
|||
vm = wrapper.vm;
|
||||
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({
|
||||
itemFilter: {
|
||||
include: [
|
||||
|
@ -32,23 +42,15 @@ describe('FilterItemForm', () => {
|
|||
|
||||
await vm.onSubmit();
|
||||
|
||||
const expectedFilter = {
|
||||
include: [
|
||||
{ relation: 'producer', scope: { fields: ['name'] } },
|
||||
{ relation: 'ink', scope: { fields: ['name'] } },
|
||||
],
|
||||
where: {
|
||||
name: { like: '%bolas de madera%' },
|
||||
size: 'large',
|
||||
producerFk: 1,
|
||||
typeFk: 2,
|
||||
inkFk: 3,
|
||||
expect(vm.tableRows).toEqual([
|
||||
{
|
||||
id: 999996,
|
||||
name: 'Bolas de madera',
|
||||
size: 2,
|
||||
inkFk: null,
|
||||
producerFk: null,
|
||||
},
|
||||
};
|
||||
|
||||
expect(axios.get).toHaveBeenCalledWith('Items/withName', {
|
||||
params: { filter: JSON.stringify(expectedFilter) },
|
||||
});
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle an empty itemFilterParams correctly', async () => {
|
||||
|
@ -68,4 +70,9 @@ describe('FilterItemForm', () => {
|
|||
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]);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue