test: #7136 new VnSelect test
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
commit
bc056eb274
|
@ -71,7 +71,7 @@ const myOptionsOriginal = ref([]);
|
||||||
const vnSelectRef = ref();
|
const vnSelectRef = ref();
|
||||||
const dataRef = ref();
|
const dataRef = ref();
|
||||||
|
|
||||||
const value = computed({
|
const selectValue = computed({
|
||||||
get() {
|
get() {
|
||||||
return $props.modelValue;
|
return $props.modelValue;
|
||||||
},
|
},
|
||||||
|
@ -212,7 +212,7 @@ async function onScroll(scrollEv) {
|
||||||
<QSelect
|
<QSelect
|
||||||
:loading="isLoading"
|
:loading="isLoading"
|
||||||
@virtual-scroll="onScroll"
|
@virtual-scroll="onScroll"
|
||||||
v-model="value"
|
v-model="selectValue"
|
||||||
:options="myOptions"
|
:options="myOptions"
|
||||||
:option-label="optionLabel"
|
:option-label="optionLabel"
|
||||||
:option-value="optionValue"
|
:option-value="optionValue"
|
||||||
|
|
|
@ -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,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue