This commit is contained in:
parent
149cca37ef
commit
b466dfe034
|
@ -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,10 +15,20 @@ 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: [
|
||||||
|
@ -32,23 +42,15 @@ describe('FilterItemForm', () => {
|
||||||
|
|
||||||
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]);
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue