forked from verdnatura/salix-front
test: refs #7058 pass both tests
This commit is contained in:
parent
5e2158daf4
commit
fcdc69d7c8
|
@ -272,7 +272,7 @@ describe('Leftmenu as main', () => {
|
||||||
it('should get routes for main source', () => {
|
it('should get routes for main source', () => {
|
||||||
vm.props.source = 'main';
|
vm.props.source = 'main';
|
||||||
vm.getRoutes();
|
vm.getRoutes();
|
||||||
expect(useNavigationStore().getModules).toHaveBeenCalled();
|
expect(navigation.getModules).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should find direct child matches', () => {
|
it('should find direct child matches', () => {
|
||||||
|
@ -328,6 +328,10 @@ describe('normalize', () => {
|
||||||
expect(vm.normalize(input)).toBe(expected);
|
expect(vm.normalize(input)).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// describe('addMenuItem', () => {
|
||||||
|
// const findMatches = vi.fn().mockImplementation(() => []);
|
||||||
|
//
|
||||||
|
// });
|
||||||
|
|
||||||
describe('addChildren', () => {
|
describe('addChildren', () => {
|
||||||
const module = 'testModule';
|
const module = 'testModule';
|
||||||
|
@ -346,7 +350,7 @@ describe('addChildren', () => {
|
||||||
};
|
};
|
||||||
vm.addChildren(module, route, parent);
|
vm.addChildren(module, route, parent);
|
||||||
|
|
||||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
expect(navigation.addMenuItem).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle routes with no meta menu', () => {
|
it('should handle routes with no meta menu', () => {
|
||||||
|
@ -358,7 +362,7 @@ describe('addChildren', () => {
|
||||||
const parent = [];
|
const parent = [];
|
||||||
|
|
||||||
vm.addChildren(module, route, parent);
|
vm.addChildren(module, route, parent);
|
||||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
expect(navigation.addMenuItem).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle empty parent array', () => {
|
it('should handle empty parent array', () => {
|
||||||
|
@ -383,6 +387,6 @@ describe('addChildren', () => {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
vm.addChildren(module, route, parent);
|
vm.addChildren(module, route, parent);
|
||||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
expect(navigation.addMenuItem).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,171 @@
|
||||||
|
import { setActivePinia, createPinia } from 'pinia';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest';
|
||||||
|
import { useNavigationStore } from '../useNavigationStore';
|
||||||
|
import axios from 'axios';
|
||||||
|
// import { axios } from 'app/test/vitest/helper';
|
||||||
|
// vi.mock('axios');
|
||||||
|
|
||||||
|
vi.mock('src/router/modules', () => [
|
||||||
|
{ name: 'Item', meta: {} },
|
||||||
|
{ name: 'Shelving', meta: {} },
|
||||||
|
{ name: 'Order', meta: {} },
|
||||||
|
]);
|
||||||
|
|
||||||
|
vi.mock('src/filters', () => ({
|
||||||
|
toLowerCamel: vi.fn((name) => name.toLowerCase()),
|
||||||
|
}));
|
||||||
|
const modulesMock = [
|
||||||
|
{
|
||||||
|
name: 'Item',
|
||||||
|
children: null,
|
||||||
|
title: 'globals.pageTitles.undefined',
|
||||||
|
icon: undefined,
|
||||||
|
module: 'item',
|
||||||
|
isPinned: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Shelving',
|
||||||
|
children: null,
|
||||||
|
title: 'globals.pageTitles.undefined',
|
||||||
|
icon: undefined,
|
||||||
|
module: 'shelving',
|
||||||
|
isPinned: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Order',
|
||||||
|
children: null,
|
||||||
|
title: 'globals.pageTitles.undefined',
|
||||||
|
icon: undefined,
|
||||||
|
module: 'order',
|
||||||
|
isPinned: false,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const pinnedModulesMock = [
|
||||||
|
{
|
||||||
|
name: 'Item',
|
||||||
|
children: null,
|
||||||
|
title: 'globals.pageTitles.undefined',
|
||||||
|
icon: undefined,
|
||||||
|
module: 'item',
|
||||||
|
isPinned: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
let store;
|
||||||
|
describe('useNavigationStore', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
setActivePinia(createPinia());
|
||||||
|
vi.spyOn(axios, 'get').mockResolvedValue({ data: true });
|
||||||
|
store = useNavigationStore();
|
||||||
|
store.getModules = vi.fn().mockReturnValue({
|
||||||
|
value: modulesMock,
|
||||||
|
});
|
||||||
|
store.getPinnedModules = vi.fn().mockReturnValue({
|
||||||
|
value: pinnedModulesMock,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return modules with correct structure', () => {
|
||||||
|
const store = useNavigationStore();
|
||||||
|
// store.pinnedModules = ref(['item']);
|
||||||
|
|
||||||
|
const modules = store.getModules();
|
||||||
|
|
||||||
|
expect(modules.value).toEqual(modulesMock);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return pinned modules', () => {
|
||||||
|
const store = useNavigationStore();
|
||||||
|
// store.pinnedModules = ref(['item']);
|
||||||
|
|
||||||
|
const pinnedModules = store.getPinnedModules();
|
||||||
|
|
||||||
|
expect(pinnedModules.value).toEqual(pinnedModulesMock);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should toggle pinned modules', () => {
|
||||||
|
const store = useNavigationStore();
|
||||||
|
store.togglePinned('item');
|
||||||
|
store.togglePinned('shelving');
|
||||||
|
expect(store.pinnedModules).toEqual(['item', 'shelving']);
|
||||||
|
|
||||||
|
store.togglePinned('item');
|
||||||
|
expect(store.pinnedModules).toEqual(['shelving']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fetch pinned modules', async () => {
|
||||||
|
// vi.mock('axios', () => ({
|
||||||
|
// get: vi.fn(() =>
|
||||||
|
// Promise.resolve({
|
||||||
|
// data: [{ id: 1, workerFk: 9, moduleFk: 'item', position: 1 }],
|
||||||
|
// }),
|
||||||
|
// ),
|
||||||
|
// }));
|
||||||
|
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||||
|
data: [{ id: 1, workerFk: 9, moduleFk: 'order', position: 1 }],
|
||||||
|
});
|
||||||
|
const store = useNavigationStore();
|
||||||
|
// vi.spyOn(axios, 'get').mockResolvedValue({
|
||||||
|
|
||||||
|
// });
|
||||||
|
// store.togglePinned('shelving');
|
||||||
|
// store.togglePinned('shelving');
|
||||||
|
|
||||||
|
await store.fetchPinned();
|
||||||
|
|
||||||
|
expect(store.pinnedModules).toEqual(['order']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add menu item correctly', () => {
|
||||||
|
const store = useNavigationStore();
|
||||||
|
const module = 'customer';
|
||||||
|
const route = {
|
||||||
|
name: 'customer',
|
||||||
|
title: 'Customer',
|
||||||
|
icon: 'customer',
|
||||||
|
meta: {
|
||||||
|
keyBinding: 'ctrl+shift+c',
|
||||||
|
name: 'customer',
|
||||||
|
title: 'Customer',
|
||||||
|
icon: 'customer',
|
||||||
|
menu: 'customer',
|
||||||
|
menuChildren: [{ name: 'customer', title: 'Customer', icon: 'customer' }],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const parent = 'testParent';
|
||||||
|
|
||||||
|
// Mock de console.log para verificar la salida
|
||||||
|
// const consoleLogSpy = vi.spyOn(console, 'log');
|
||||||
|
|
||||||
|
const result = store.addMenuItem(module, route, []);
|
||||||
|
expect(result).toEqual({
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
icon: 'customer',
|
||||||
|
name: 'customer',
|
||||||
|
title: 'globals.pageTitles.Customer',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
icon: 'customer',
|
||||||
|
keyBinding: 'ctrl+shift+c',
|
||||||
|
name: 'customer',
|
||||||
|
title: 'globals.pageTitles.Customer',
|
||||||
|
});
|
||||||
|
// expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||||
|
// 'Adding menu item: child1 to parent: testParent',
|
||||||
|
// );
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not add menu item if condition is not met', () => {
|
||||||
|
const store = useNavigationStore();
|
||||||
|
const module = 'testModule';
|
||||||
|
const route = { meta: { hidden: true, menuchildren: {} } };
|
||||||
|
const parent = 'testParent';
|
||||||
|
|
||||||
|
const result = store.addMenuItem(module, route, []);
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue