2024-01-09 15:54:07 +00:00
|
|
|
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;
|
2024-01-09 16:01:11 +00:00
|
|
|
vm.route.matched = [
|
|
|
|
{
|
|
|
|
path: '/',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/customer',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/customer/:id',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/customer/:id/basic-data',
|
|
|
|
},
|
|
|
|
];
|
2024-01-09 15:54:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|