54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
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';
|
|
|
|
|
|
describe('VnSearchBar', () => {
|
|
let vm;
|
|
let wrapper;
|
|
|
|
beforeAll(() => {
|
|
wrapper = createWrapper(VnSearchbar, {
|
|
propsData: {
|
|
dataKey: 'CustomerList',
|
|
label: 'Search customer',
|
|
info: 'Info customer',
|
|
},
|
|
});
|
|
vm = wrapper.vm;
|
|
vm.route.matched = [
|
|
{
|
|
path: '/',
|
|
},
|
|
{
|
|
path: '/customer',
|
|
},
|
|
{
|
|
path: '/customer/:id',
|
|
},
|
|
{
|
|
path: '/customer/:id/basic-data',
|
|
},
|
|
];
|
|
});
|
|
|
|
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');
|
|
});
|
|
});
|