0
0
Fork 0

test: refs #7058 chnges requested

This commit is contained in:
Javier Segarra 2025-02-05 08:29:08 +01:00
parent 629b89fe2f
commit 5e2158daf4
2 changed files with 22 additions and 13 deletions

View File

@ -34,17 +34,13 @@ const pinnedModules = computed(() => {
const search = ref(null); const search = ref(null);
const filteredItems = computed(() => { const filteredItems = computed(() => {
return filterItems();
});
function filterItems() {
if (!search.value) return items.value; if (!search.value) return items.value;
const normalizedSearch = normalize(search.value); const normalizedSearch = normalize(search.value);
return items.value.filter((item) => { return items.value.filter((item) => {
const locale = normalize(t(item.title)); const locale = normalize(t(item.title));
return locale.includes(normalizedSearch); return locale.includes(normalizedSearch);
}); });
} });
const filteredPinnedModules = computed(() => { const filteredPinnedModules = computed(() => {
if (!search.value) return pinnedModules.value; if (!search.value) return pinnedModules.value;
const normalizedSearch = search.value const normalizedSearch = search.value
@ -75,7 +71,7 @@ watch(
items.value = []; items.value = [];
getRoutes(); getRoutes();
}, },
{ deep: true } { deep: true },
); );
function findMatches(search, item) { function findMatches(search, item) {
@ -122,7 +118,7 @@ function getMainRoutes() {
for (const item of modules) { for (const item of modules) {
const moduleDef = routes.find( const moduleDef = routes.find(
(route) => toLowerCamel(route.name) === item.module (route) => toLowerCamel(route.name) === item.module,
); );
if (!moduleDef) continue; if (!moduleDef) continue;
item.children = []; item.children = [];
@ -233,9 +229,16 @@ const searchModule = () => {
</template> </template>
<template v-for="(item, index) in filteredItems" :key="item.name"> <template v-for="(item, index) in filteredItems" :key="item.name">
<template <template
v-if="search ||item.children && !filteredPinnedModules.has(item.name)" v-if="
search ||
(item.children && !filteredPinnedModules.has(item.name))
"
>
<LeftMenuItem
:item="item"
group="modules"
:class="search && index === 0 ? 'searched' : ''"
> >
<LeftMenuItem :item="item" group="modules" :class="search && index === 0 ? 'searched' : ''">
<template #side> <template #side>
<QBtn <QBtn
v-if="item.isPinned === true" v-if="item.isPinned === true"

View File

@ -166,7 +166,7 @@ describe('getRoutes', () => {
expect(getMethodB).not.toHaveBeenCalled(); expect(getMethodB).not.toHaveBeenCalled();
}); });
it('should call getMethodA when source is main', () => { it('should call getMethodA when source is not exists or undefined', () => {
let props = { source: 'methodC' }; let props = { source: 'methodC' };
expect(() => fn(props)).toThrowError('Method not defined'); expect(() => fn(props)).toThrowError('Method not defined');
@ -193,10 +193,16 @@ describe('Leftmenu as main', () => {
expect(vm.source).toBe('main'); expect(vm.source).toBe('main');
}); });
it('should filter items based on search input', async () => {
vm.search = 'cust';
await vm.$nextTick();
expect(vm.filteredItems[0].name).toEqual('customer');
expect(vm.filteredItems[0].module).toEqual('customer');
});
it('should filter items based on search input', async () => { it('should filter items based on search input', async () => {
vm.search = 'Rou'; vm.search = 'Rou';
await vm.$nextTick(); await vm.$nextTick();
expect(vm.filterItems()).toEqual([]); expect(vm.filteredItems).toEqual([]);
}); });
it('should return pinned items', () => { it('should return pinned items', () => {
@ -205,7 +211,7 @@ describe('Leftmenu as main', () => {
{ name: 'Item 2', isPinned: true }, { name: 'Item 2', isPinned: true },
]; ];
expect(vm.pinnedModules).toEqual( expect(vm.pinnedModules).toEqual(
new Map([['Item 2', { name: 'Item 2', isPinned: true }]]) new Map([['Item 2', { name: 'Item 2', isPinned: true }]]),
); );
}); });