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 { createWrapper } from 'app/test/vitest/helper';
|
||||||
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
|
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
|
||||||
|
|
||||||
describe('VnSearchbar', () => {
|
describe('VnSearchbar', () => {
|
||||||
let vm;
|
let vm;
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
let applyFilterSpy;
|
||||||
|
const searchText = 'Bolas de madera';
|
||||||
|
const userParams = {staticKey: 'staticValue'};
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
wrapper = createWrapper(VnSearchbar, {
|
wrapper = createWrapper(VnSearchbar, {
|
||||||
|
@ -18,36 +21,39 @@ describe('VnSearchbar', () => {
|
||||||
wrapper = wrapper.wrapper;
|
wrapper = wrapper.wrapper;
|
||||||
vm = wrapper.vm;
|
vm = wrapper.vm;
|
||||||
|
|
||||||
vm.searchText = 'Bolas de madera';
|
vm.searchText = searchText;
|
||||||
vm.arrayData.store.userParams = { staticKey: 'staticValue' };
|
vm.arrayData.store.userParams = userParams;
|
||||||
|
applyFilterSpy = vi.spyOn(vm.arrayData, 'applyFilter').mockImplementation(() => {});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
it('search resets pagination and applies filter', async () => {
|
it('search resets pagination and applies filter', async () => {
|
||||||
const applyFilterSpy = vi.spyOn(vm.arrayData, 'applyFilter').mockImplementation(() => {});
|
|
||||||
const resetPaginationSpy = vi.spyOn(vm.arrayData, 'resetPagination').mockImplementation(() => {});
|
const resetPaginationSpy = vi.spyOn(vm.arrayData, 'resetPagination').mockImplementation(() => {});
|
||||||
await vm.search();
|
await vm.search();
|
||||||
|
|
||||||
expect(resetPaginationSpy).toHaveBeenCalled();
|
expect(resetPaginationSpy).toHaveBeenCalled();
|
||||||
expect(applyFilterSpy).toHaveBeenCalledWith({
|
expect(applyFilterSpy).toHaveBeenCalledWith({
|
||||||
params: { search: 'Bolas de madera' },
|
params: { search: searchText },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('search includes static params if searchRemoveParams is false', async () => {
|
it('search includes static params if searchRemoveParams is false', async () => {
|
||||||
const applyFilterSpy = vi.spyOn(vm.arrayData, 'applyFilter').mockImplementation(() => {});
|
|
||||||
wrapper.setProps({ searchRemoveParams: false });
|
wrapper.setProps({ searchRemoveParams: false });
|
||||||
await vm.$nextTick();
|
await vm.$nextTick();
|
||||||
await vm.search();
|
await vm.search();
|
||||||
|
|
||||||
expect(applyFilterSpy).toHaveBeenCalledWith({
|
expect(applyFilterSpy).toHaveBeenCalledWith({
|
||||||
params: { staticKey: 'staticValue', search: 'Bolas de madera' },
|
params: { staticKey: 'staticValue', search: searchText },
|
||||||
filter: {skip: 0},
|
filter: {skip: 0},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates store when dataKey changes', async () => {
|
it('updates store when dataKey changes', async () => {
|
||||||
expect(vm.store.userParams).toEqual({ staticKey: 'staticValue' });
|
expect(vm.store.userParams).toEqual(userParams);
|
||||||
wrapper.setProps({ dataKey: 'newTestKey' });
|
wrapper.setProps({ dataKey: 'newTestKey' });
|
||||||
await vm.$nextTick();
|
await vm.$nextTick();
|
||||||
expect(vm.store.userParams).toEqual({});
|
expect(vm.store.userParams).toEqual({});
|
||||||
|
@ -58,7 +64,7 @@ describe('VnSearchbar', () => {
|
||||||
vm.arrayData.store.currentFilter = { category: 'plants' };
|
vm.arrayData.store.currentFilter = { category: 'plants' };
|
||||||
const expectedQuery = JSON.stringify({
|
const expectedQuery = JSON.stringify({
|
||||||
...vm.arrayData.store.currentFilter,
|
...vm.arrayData.store.currentFilter,
|
||||||
search: 'Bolas de madera',
|
search: searchText,
|
||||||
});
|
});
|
||||||
expect(vm.to.query.searchParam).toBe(expectedQuery);
|
expect(vm.to.query.searchParam).toBe(expectedQuery);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue