2023-01-03 13:17:22 +00:00
|
|
|
import { vi, describe, expect, it, beforeAll } from 'vitest';
|
|
|
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
|
|
|
import Leftmenu from 'components/LeftMenu.vue';
|
|
|
|
|
|
|
|
import { useNavigationStore } from 'src/stores/useNavigationStore';
|
|
|
|
|
|
|
|
vi.mock('src/router/modules', () => ({
|
|
|
|
default: [
|
|
|
|
{
|
|
|
|
path: '/customer',
|
|
|
|
name: 'Customer',
|
|
|
|
meta: {
|
|
|
|
title: 'customers',
|
|
|
|
icon: 'vn:client',
|
|
|
|
},
|
|
|
|
menus: {
|
|
|
|
main: ['CustomerList', 'CustomerCreate'],
|
|
|
|
card: ['CustomerBasicData'],
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: '',
|
|
|
|
name: 'CustomerMain',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: 'list',
|
|
|
|
name: 'CustomerList',
|
|
|
|
meta: {
|
|
|
|
title: 'list',
|
|
|
|
icon: 'view_list',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'create',
|
|
|
|
name: 'CustomerCreate',
|
|
|
|
meta: {
|
|
|
|
title: 'createCustomer',
|
|
|
|
icon: 'vn:addperson',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
|
2023-08-10 05:26:50 +00:00
|
|
|
describe('Leftmenu', () => {
|
2023-01-03 13:17:22 +00:00
|
|
|
let vm;
|
|
|
|
let navigation;
|
|
|
|
beforeAll(() => {
|
|
|
|
vi.spyOn(axios, 'get').mockResolvedValue({
|
|
|
|
data: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
vm = createWrapper(Leftmenu, {
|
|
|
|
propsData: {
|
|
|
|
source: 'main',
|
|
|
|
},
|
|
|
|
}).vm;
|
|
|
|
|
|
|
|
navigation = useNavigationStore();
|
|
|
|
navigation.fetchPinned = vi.fn().mockReturnValue(Promise.resolve(true));
|
|
|
|
navigation.getModules = vi.fn().mockReturnValue({
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
name: 'customer',
|
|
|
|
title: 'customer.pageTitles.customers',
|
|
|
|
icon: 'vn:customer',
|
|
|
|
module: 'customer',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a proper formated object with two child items', async () => {
|
|
|
|
const expectedMenuItem = [
|
|
|
|
{
|
2024-02-08 11:32:35 +00:00
|
|
|
children: null,
|
2023-01-03 13:17:22 +00:00
|
|
|
name: 'CustomerList',
|
|
|
|
title: 'customer.pageTitles.list',
|
|
|
|
icon: 'view_list',
|
|
|
|
},
|
|
|
|
{
|
2024-02-08 11:32:35 +00:00
|
|
|
children: null,
|
2023-01-03 13:17:22 +00:00
|
|
|
name: 'CustomerCreate',
|
|
|
|
title: 'customer.pageTitles.createCustomer',
|
|
|
|
icon: 'vn:addperson',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const firstMenuItem = vm.items[0];
|
|
|
|
expect(firstMenuItem.children).toEqual(expect.arrayContaining(expectedMenuItem));
|
|
|
|
});
|
|
|
|
});
|