test: refs #7058 improve test

This commit is contained in:
Javier Segarra 2024-12-30 12:34:13 +01:00
parent 6f31eeeeec
commit 4cc895b69c
1 changed files with 41 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import { describe, expect, it, beforeAll, beforeEach, vi } from 'vitest'; import { describe, expect, it, beforeAll, beforeEach, vi } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper'; import { createWrapper } from 'app/test/vitest/helper';
import LeftMenu from 'src/components/LeftMenu.vue'; import LeftMenu from 'src/components/LeftMenu.vue';
import { useNavigationStore } from 'src/stores/useNavigationStore';
describe('LeftMenu', () => { describe('LeftMenu', () => {
let wrapper; let wrapper;
@ -19,6 +20,10 @@ describe('LeftMenu', () => {
useNavigationStore: vi.fn(() => ({ useNavigationStore: vi.fn(() => ({
items: [], items: [],
expansionItemElements: {}, expansionItemElements: {},
addMenuItem: vi.fn(),
getModules: vi.fn(() => ({
value: [],
})),
})), })),
}; };
}); });
@ -52,4 +57,40 @@ describe('LeftMenu', () => {
new Map([['Item 2', { name: 'Item 2', isPinned: true }]]) new Map([['Item 2', { name: 'Item 2', isPinned: true }]])
); );
}); });
it('should find matches in routes', () => {
const search = 'child1';
const item = {
children: [
{ name: 'child1', children: [] },
{ name: 'child2', children: [] },
],
};
const matches = vm.findMatches(search, item);
expect(matches).toEqual([{ name: 'child1', children: [] }]);
});
it('should add children to navigation', () => {
const module = 'module1';
const route = {
meta: { menu: 'child1' },
children: [
{ name: 'child1', children: [] },
{ name: 'child2', children: [] },
],
};
const parent = 'parent1';
vm.addChildren(module, route, parent);
expect(useNavigationStore().addMenuItem).toHaveBeenCalledWith(
module,
{ name: 'child1', children: [] },
parent
);
});
it('should get routes for main source', () => {
vm.props.source = 'main';
vm.getRoutes();
expect(useNavigationStore().getModules).toHaveBeenCalled();
});
}); });