forked from verdnatura/salix-front
fix: refs #7103 used consts for repeated variables
This commit is contained in:
parent
d33909ad01
commit
ea4a46d9c7
|
@ -1,10 +1,13 @@
|
|||
import { vi, describe, expect, it, beforeEach } from 'vitest';
|
||||
import { vi, describe, expect, it, beforeEach, afterEach } from 'vitest';
|
||||
import { createWrapper } from 'app/test/vitest/helper';
|
||||
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
|
||||
|
||||
describe('VnSearchbar', () => {
|
||||
let vm;
|
||||
let wrapper;
|
||||
let applyFilterSpy;
|
||||
const searchText = 'Bolas de madera';
|
||||
const userParams = {staticKey: 'staticValue'};
|
||||
|
||||
beforeEach(async () => {
|
||||
wrapper = createWrapper(VnSearchbar, {
|
||||
|
@ -18,36 +21,39 @@ describe('VnSearchbar', () => {
|
|||
wrapper = wrapper.wrapper;
|
||||
vm = wrapper.vm;
|
||||
|
||||
vm.searchText = 'Bolas de madera';
|
||||
vm.arrayData.store.userParams = { staticKey: 'staticValue' };
|
||||
vm.searchText = searchText;
|
||||
vm.arrayData.store.userParams = userParams;
|
||||
applyFilterSpy = vi.spyOn(vm.arrayData, 'applyFilter').mockImplementation(() => {});
|
||||
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
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' },
|
||||
params: { search: searchText },
|
||||
});
|
||||
});
|
||||
|
||||
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' },
|
||||
params: { staticKey: 'staticValue', search: searchText },
|
||||
filter: {skip: 0},
|
||||
});
|
||||
});
|
||||
|
||||
it('updates store when dataKey changes', async () => {
|
||||
expect(vm.store.userParams).toEqual({ staticKey: 'staticValue' });
|
||||
expect(vm.store.userParams).toEqual(userParams);
|
||||
wrapper.setProps({ dataKey: 'newTestKey' });
|
||||
await vm.$nextTick();
|
||||
expect(vm.store.userParams).toEqual({});
|
||||
|
@ -58,7 +64,7 @@ describe('VnSearchbar', () => {
|
|||
vm.arrayData.store.currentFilter = { category: 'plants' };
|
||||
const expectedQuery = JSON.stringify({
|
||||
...vm.arrayData.store.currentFilter,
|
||||
search: 'Bolas de madera',
|
||||
search: searchText,
|
||||
});
|
||||
expect(vm.to.query.searchParam).toBe(expectedQuery);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue