test: #7136 new VnSelect test
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-05-29 09:58:58 +02:00
commit bc056eb274
2 changed files with 89 additions and 2 deletions

View File

@ -71,7 +71,7 @@ const myOptionsOriginal = ref([]);
const vnSelectRef = ref();
const dataRef = ref();
const value = computed({
const selectValue = computed({
get() {
return $props.modelValue;
},
@ -212,7 +212,7 @@ async function onScroll(scrollEv) {
<QSelect
:loading="isLoading"
@virtual-scroll="onScroll"
v-model="value"
v-model="selectValue"
:options="myOptions"
:option-label="optionLabel"
:option-value="optionValue"

View File

@ -0,0 +1,87 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper';
import VnSelect from 'src/components/common/VnSelect.vue';
describe('VnSelect use options as arguments', () => {
let vm;
const options = [
{ id: 1, name: 'Option 1' },
{ id: 2, name: 'Option 2' },
{ id: 3, name: 'Option 3' },
];
beforeAll(() => {
vm = createWrapper(VnSelect, {
propsData: {
options,
optionLabel: 'name',
optionValue: 'id',
},
global: {
stubs: ['FetchData'],
mocks: {},
},
}).vm;
});
afterEach(() => {
vi.clearAllMocks();
});
it('should mounted correctly', () => {
expect(vm).toBeDefined();
});
it('should pass options and not CALL URL', async () => {
expect(vm.myOptions.length).toEqual(options.length);
expect(vm.useURL).toBeFalsy();
vm.selectValue = 'Option 2';
const optionsFiltered = vm.filter('Option 2', options);
// vm.filterHandler('Option 2', vi.fn());
vm.filterHandler('Option 2', () => {
vm.myOptions = optionsFiltered;
});
expect(vm.myOptions.length).toEqual(1);
});
});
describe('VnSelect FETCH URL', () => {
let vm;
beforeAll(async () => {
vi.spyOn(axios, 'get').mockResolvedValue({
data: [
{ id: 1, name: 'Tony Stark' },
{ id: 2, name: 'Jessica Jones' },
{ id: 3, name: 'Bruce Wayne' },
],
});
vm = createWrapper(VnSelect, {
propsData: {
optionLabel: 'name',
optionValue: 'id',
url: 'Suppliers',
},
global: {
stubs: ['FetchData'],
mocks: { fetch: vi.fn() },
},
}).vm;
});
afterEach(() => {
vi.clearAllMocks();
});
it('should CALL URL', async () => {
vm.selectValue = '';
expect(vm.options.length).toEqual(0);
expect(vm.useURL).toBeTruthy();
expect(vm.myOptions.length).toEqual(3);
const canceller = new AbortController();
expect(axios.get).toHaveBeenCalledWith('Suppliers', {
params: {
filter: '{"order":"","limit":"30","skip":0}',
},
signal: canceller.signal,
});
});
});