feat: #7103 created test for VnSearchbar #1256

Merged
provira merged 14 commits from 7103-testVnSearchbar into dev 2025-01-22 11:15:21 +00:00
1 changed files with 7 additions and 9 deletions
Showing only changes of commit 5e6a83c001 - Show all commits

View File

@ -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

porque functions?

porque functions?
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

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);
});