feat: #7103 created test for VnSearchbar #1256

Open
provira wants to merge 10 commits from 7103-testVnSearchbar into dev
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
import { vi, describe, expect, it, beforeEach } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
describe('VnSearchbar', () => {
provira marked this conversation as resolved Outdated

porque functions?

porque functions?
let vm;
let wrapper;
beforeEach(async () => {
wrapper = createWrapper(VnSearchbar, {
propsData: {
dataKey: 'testKey',
filter: null,
whereFilter: null,
searchRemoveParams: true,
},
});
wrapper = wrapper.wrapper;
vm = wrapper.vm;
vm.searchText = 'Bolas de madera';
vm.arrayData.store.userParams = { staticKey: 'staticValue' };
});
provira marked this conversation as resolved Outdated

Promise.resolve(), vacio?

Promise.resolve(), vacio?
it('search resets pagination and applies filter', async () => {
const applyFilterSpy = vi.spyOn(vm.arrayData, 'applyFilter').mockImplementation(() => {});
const resetPaginationSpy = vi.spyOn(vm.arrayData, 'resetPagination').mockImplementation(() => {});
await vm.search();
expect(resetPaginationSpy).toHaveBeenCalled();
expect(applyFilterSpy).toHaveBeenCalledWith({
params: { search: 'Bolas de madera' },
});
});
it('search includes static params if searchRemoveParams is false', async () => {
const applyFilterSpy = vi.spyOn(vm.arrayData, 'applyFilter').mockImplementation(() => {});
wrapper.setProps({ searchRemoveParams: false });
await vm.$nextTick();
await vm.search();
expect(applyFilterSpy).toHaveBeenCalledWith({
params: { staticKey: 'staticValue', search: 'Bolas de madera' },
filter: {skip: 0},
});
});
it('updates store when dataKey changes', async () => {
expect(vm.store.userParams).toEqual({ staticKey: 'staticValue' });
wrapper.setProps({ dataKey: 'newTestKey' });
await vm.$nextTick();
expect(vm.store.userParams).toEqual({});
});
it('computes the "to" property correctly for redirection', () => {
vm.arrayData.store.searchUrl = 'searchParam';
vm.arrayData.store.currentFilter = { category: 'plants' };
const expectedQuery = JSON.stringify({
...vm.arrayData.store.currentFilter,
search: 'Bolas de madera',
});
expect(vm.to.query.searchParam).toBe(expectedQuery);
});
});