feat: #7103 created test for VnSearchbar #1256
|
@ -2,9 +2,10 @@ 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 - Functions', () => {
|
||||
describe('VnSearchbar', () => {
|
||||
provira marked this conversation as resolved
Outdated
|
||||
let vm;
|
||||
let wrapper;
|
||||
let applyFilterSpy;
|
||||
|
||||
beforeEach(async () => {
|
||||
wrapper = createWrapper(VnSearchbar, {
|
||||
|
@ -17,13 +18,14 @@ describe('VnSearchbar - Functions', () => {
|
|||
});
|
||||
wrapper = wrapper.wrapper;
|
||||
vm = wrapper.vm;
|
||||
|
||||
vm.searchText = 'Bolas de madera';
|
||||
vm.arrayData.store.userParams = { staticKey: 'staticValue' };
|
||||
applyFilterSpy = vi.spyOn(vm.arrayData, 'applyFilter').mockImplementation(() => {});
|
||||
provira marked this conversation as resolved
Outdated
jsegarra
commented
Promise.resolve(), vacio? Promise.resolve(), vacio?
|
||||
});
|
||||
|
||||
it('search resets pagination and applies filter', async () => {
|
||||
const resetPaginationSpy = vi.spyOn(vm.arrayData, 'resetPagination').mockImplementation(() => {});
|
||||
const applyFilterSpy = vi.spyOn(vm.arrayData, 'applyFilter').mockImplementation(() => Promise.resolve());
|
||||
|
||||
vm.searchText = 'Bolas de madera';
|
||||
await vm.search();
|
||||
|
||||
expect(resetPaginationSpy).toHaveBeenCalled();
|
||||
|
@ -36,9 +38,6 @@ describe('VnSearchbar - Functions', () => {
|
|||
it('search includes static params if searchRemoveParams is false', async () => {
|
||||
wrapper.setProps({ searchRemoveParams: false });
|
||||
await vm.$nextTick();
|
||||
const applyFilterSpy = vi.spyOn(vm.arrayData, 'applyFilter').mockImplementation(() => Promise.resolve());
|
||||
vm.arrayData.store.userParams = { staticKey: 'staticValue' };
|
||||
vm.searchText = 'Bolas de madera';
|
||||
await vm.search();
|
||||
|
||||
expect(applyFilterSpy).toHaveBeenCalledWith({
|
||||
|
@ -55,12 +54,11 @@ describe('VnSearchbar - Functions', () => {
|
|||
});
|
||||
|
||||
it('computes the "to" property correctly for redirection', () => {
|
||||
vm.searchText = 'testRedirect';
|
||||
vm.arrayData.store.searchUrl = 'searchParam';
|
||||
vm.arrayData.store.currentFilter = { category: 'plants' };
|
||||
const expectedQuery = JSON.stringify({
|
||||
...vm.arrayData.store.currentFilter,
|
||||
search: 'testRedirect',
|
||||
search: 'Bolas de madera',
|
||||
});
|
||||
expect(vm.to.query.searchParam).toBe(expectedQuery);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
porque functions?