revert: refs #7058 component changes

This commit is contained in:
Javier Segarra 2024-12-31 18:13:39 +01:00
parent 072deeea5e
commit 3c5b8d4fbf
2 changed files with 50 additions and 82 deletions

View File

@ -33,18 +33,13 @@ const pinnedModules = computed(() => {
const search = ref(null); const search = ref(null);
const filteredItems = computed(() => { const filteredItems = computed(() => {
console.error('filterItems');
return filterItems();
});
function filterItems() {
console.error('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;
@ -108,14 +103,7 @@ function addChildren(module, route, parent) {
} }
function getRoutes() { function getRoutes() {
const handleRoutes = { if (props.source === 'main') {
main: getMainRoutes,
card: getCardRoutes,
};
console.log(props.source);
handleRoutes[props.source]();
}
function getMainRoutes() {
const modules = Object.assign([], navigation.getModules().value); const modules = Object.assign([], navigation.getModules().value);
for (const item of modules) { for (const item of modules) {
@ -131,16 +119,18 @@ function getMainRoutes() {
items.value = modules; items.value = modules;
} }
function getCardRoutes() { if (props.source === 'card') {
console.log('getCardRoutes');
const currentRoute = route.matched[1]; const currentRoute = route.matched[1];
const currentModule = toLowerCamel(currentRoute.name); const currentModule = toLowerCamel(currentRoute.name);
let moduleDef = routes.find((route) => toLowerCamel(route.name) === currentModule); let moduleDef = routes.find(
(route) => toLowerCamel(route.name) === currentModule
);
if (!moduleDef) return; if (!moduleDef) return;
if (!moduleDef?.menus) moduleDef = betaGetRoutes(); if (!moduleDef?.menus) moduleDef = betaGetRoutes();
addChildren(currentModule, moduleDef, items.value); addChildren(currentModule, moduleDef, items.value);
} }
}
function betaGetRoutes() { function betaGetRoutes() {
let menuRoute; let menuRoute;

View File

@ -132,37 +132,40 @@ function mount(source) {
return wrapper; return wrapper;
} }
describe('getRoutes', () => { describe.only('getRoutes', () => {
afterEach(() => vi.clearAllMocks()); beforeEach(() => {});
const getRoutes = vi // afterEach(() => vi.clearAllMocks());
.fn() // const getRoutes = vi
.mockImplementation((props, getMainRoutes, getCardRoutes) => { // .fn()
const handleRoutes = { // .mockImplementation((props, getMainRoutes, getCardRoutes) => {
main: getMainRoutes, // const handleRoutes = {
card: getCardRoutes, // main: getMainRoutes,
}; // card: getCardRoutes,
console.log(props.source); // };
handleRoutes[props.source](); // console.log(props.source);
}); // handleRoutes[props.source]();
// });
const getMainRoutes = vi.fn(); // const getMainRoutes = vi.fn();
const getCardRoutes = vi.fn(); // const getCardRoutes = vi.fn();
it('should call getCardRoutes when source is card', () => { it('should call getCardRoutes when source is card', () => {
vm = mount('card').vm;
let props = { source: 'card' }; let props = { source: 'card' };
vi.spyOn(vm, 'getCardRoutes');
vm.getRoutes();
// getRoutes(props, getMainRoutes, getCardRoutes);
getRoutes(props, getMainRoutes, getCardRoutes); expect(vm.getCardRoutes).toHaveBeenCalled();
// expect(vm.getMainRoutes).not.toHaveBeenCalled();
expect(getCardRoutes).toHaveBeenCalled();
expect(getMainRoutes).not.toHaveBeenCalled();
}); });
it('should call getMainRoutes when source is main', () => { // it.skip('should call getMainRoutes when source is main', () => {
let props = { source: 'main' }; // let props = { source: 'main' };
getRoutes(props, getMainRoutes, getCardRoutes); // getRoutes(props, getMainRoutes, getCardRoutes);
expect(getMainRoutes).toHaveBeenCalled(); // expect(getMainRoutes).toHaveBeenCalled();
expect(getCardRoutes).not.toHaveBeenCalled(); // expect(getCardRoutes).not.toHaveBeenCalled();
}); // });
}); });
describe.skip('Leftmenu as card', () => { describe.skip('Leftmenu as card', () => {
beforeAll(() => { beforeAll(() => {
@ -372,11 +375,6 @@ describe.only('addChildren', () => {
vm.addChildren(module, route, parent); vm.addChildren(module, route, parent);
expect(useNavigationStore().addMenuItem).toHaveBeenCalled(); expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
// expect(useNavigationStore().addMenuItem).toHaveBeenCalledWith(
// module,
// { name: 'child1' },
// parent
// );
}); });
it.only('should not add menu items if no matches are found', () => { it.only('should not add menu items if no matches are found', () => {
@ -389,24 +387,14 @@ describe.only('addChildren', () => {
vm.addChildren(module, route, parent); vm.addChildren(module, route, parent);
expect(useNavigationStore().addMenuItem).toHaveBeenCalled(); expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
// expect(useNavigationStore().addMenuItem).not.toHaveBeenCalled();
}); });
it('should handle routes with no meta menu', () => { it('should handle routes with no meta menu', () => {
const module = 'testModule'; const module = 'testModule';
// const route = {
// menus: { main: 'child1' },
// children: [{ name: 'child1' }, { name: 'child2' }],
// };
const parent = []; const parent = [];
vm.addChildren(module, route, parent); vm.addChildren(module, route, parent);
expect(useNavigationStore().addMenuItem).toHaveBeenCalled(); expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
// expect(useNavigationStore().addMenuItem).toHaveBeenCalledWith(
// module,
// { name: 'child1' },
// parent
// );
}); });
it('should handle routes with no matches', () => { it('should handle routes with no matches', () => {
@ -419,23 +407,13 @@ describe.only('addChildren', () => {
vm.addChildren(module, route, parent); vm.addChildren(module, route, parent);
expect(useNavigationStore().addMenuItem).toHaveBeenCalled(); expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
// expect(useNavigationStore().addMenuItem).not.toHaveBeenCalled();
}); });
it('should handle empty parent array', () => { it('should handle empty parent array', () => {
const module = 'testModule'; const module = 'testModule';
// const route = {
// meta: { menu: 'child1' },
// children: [{ name: 'child1' }, { name: 'child2' }],
// };
const parent = []; const parent = [];
vm.addChildren(module, route, parent); vm.addChildren(module, route, parent);
expect(useNavigationStore().addMenuItem).toHaveBeenCalled(); expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
// expect(useNavigationStore().addMenuItem).toHaveBeenCalledWith(
// module,
// { name: 'child1' },
// parent
// );
}); });
}); });