refs #6384 test: vitest
gitea/salix-front/pipeline/head There was a failure building this commit
Details
gitea/salix-front/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
b4f330a237
commit
ef8e77904d
|
@ -0,0 +1,70 @@
|
||||||
|
import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest';
|
||||||
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
|
import VnSearchbar from 'components/ui/VnSearchbar.vue';
|
||||||
|
|
||||||
|
vi.mock('vue-router', () => ({
|
||||||
|
useRouter: () => ({
|
||||||
|
push: vi.fn( ),
|
||||||
|
currentRoute: {
|
||||||
|
value: {
|
||||||
|
params: {
|
||||||
|
id: 11,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
useRoute: () => ({
|
||||||
|
matched: [
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/customer',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/customer/:id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/customer/:id/basic-data',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
query: {},
|
||||||
|
params: {},
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('VnSearchBar', () => {
|
||||||
|
let vm;
|
||||||
|
let wrapper;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
wrapper = createWrapper(VnSearchbar, {
|
||||||
|
propsData: {
|
||||||
|
dataKey: 'CustomerList',
|
||||||
|
label: 'Search customer',
|
||||||
|
info: 'Info customer',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
vm = wrapper.vm;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
it('should be defined', async () => {
|
||||||
|
expect(vm.searchText).toBeDefined();
|
||||||
|
expect(vm.searchText).toEqual('');
|
||||||
|
});
|
||||||
|
it('should redirect', async () => {
|
||||||
|
vi.spyOn(vm.router,'push');
|
||||||
|
vm.searchText = '1';
|
||||||
|
await vm.search();
|
||||||
|
expect(vm.router.push).toHaveBeenCalledWith('/customer/1/basic-data');
|
||||||
|
vm.searchText = '1112';
|
||||||
|
expect(vm.searchText).toEqual('1112');
|
||||||
|
vi.spyOn(vm.router,'push');
|
||||||
|
await vm.search();
|
||||||
|
expect(vm.router.push).toHaveBeenCalledWith('/customer/1112/basic-data');
|
||||||
|
});
|
||||||
|
});
|
|
@ -14,25 +14,6 @@ installQuasarPlugin({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false });
|
const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false });
|
||||||
const mockPush = vi.fn();
|
|
||||||
|
|
||||||
vi.mock('vue-router', () => ({
|
|
||||||
useRouter: () => ({
|
|
||||||
push: mockPush,
|
|
||||||
currentRoute: {
|
|
||||||
value: {
|
|
||||||
params: {
|
|
||||||
id: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
useRoute: () => ({
|
|
||||||
matched: [],
|
|
||||||
query: {},
|
|
||||||
params: {},
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock('axios');
|
vi.mock('axios');
|
||||||
|
|
||||||
|
@ -74,6 +55,7 @@ export function createWrapper(component, options) {
|
||||||
mocks: {
|
mocks: {
|
||||||
t: (tKey) => tKey,
|
t: (tKey) => tKey,
|
||||||
$t: (tKey) => tKey,
|
$t: (tKey) => tKey,
|
||||||
|
customRouter: false
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue