diff --git a/src/components/__tests__/FilterItemForm.spec.js b/src/components/__tests__/FilterItemForm.spec.js index f36a479d9..0c88bf421 100644 --- a/src/components/__tests__/FilterItemForm.spec.js +++ b/src/components/__tests__/FilterItemForm.spec.js @@ -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,40 +15,42 @@ 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: [ - { relation: 'producer', scope: { fields: ['name'] } }, - { relation: 'ink', scope: { fields: ['name'] } }, - ], - where: { name: { like: '%bolas de madera%' } }, + include: [ + { relation: 'producer', scope: { fields: ['name'] } }, + { relation: 'ink', scope: { fields: ['name'] } }, + ], + where: { name: { like: '%bolas de madera%' } }, }, 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%' }, - 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]); + }); +}); \ No newline at end of file