revert: refs #7058 component changes
This commit is contained in:
parent
072deeea5e
commit
3c5b8d4fbf
|
@ -33,18 +33,13 @@ const pinnedModules = computed(() => {
|
|||
const search = ref(null);
|
||||
|
||||
const filteredItems = computed(() => {
|
||||
console.error('filterItems');
|
||||
return filterItems();
|
||||
});
|
||||
function filterItems() {
|
||||
console.error('filterItems');
|
||||
if (!search.value) return items.value;
|
||||
const normalizedSearch = normalize(search.value);
|
||||
return items.value.filter((item) => {
|
||||
const locale = normalize(t(item.title));
|
||||
return locale.includes(normalizedSearch);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const filteredPinnedModules = computed(() => {
|
||||
if (!search.value) return pinnedModules.value;
|
||||
|
@ -108,38 +103,33 @@ function addChildren(module, route, parent) {
|
|||
}
|
||||
|
||||
function getRoutes() {
|
||||
const handleRoutes = {
|
||||
main: getMainRoutes,
|
||||
card: getCardRoutes,
|
||||
};
|
||||
console.log(props.source);
|
||||
handleRoutes[props.source]();
|
||||
}
|
||||
function getMainRoutes() {
|
||||
const modules = Object.assign([], navigation.getModules().value);
|
||||
if (props.source === 'main') {
|
||||
const modules = Object.assign([], navigation.getModules().value);
|
||||
|
||||
for (const item of modules) {
|
||||
const moduleDef = routes.find(
|
||||
(route) => toLowerCamel(route.name) === item.module
|
||||
);
|
||||
if (!moduleDef) continue;
|
||||
item.children = [];
|
||||
for (const item of modules) {
|
||||
const moduleDef = routes.find(
|
||||
(route) => toLowerCamel(route.name) === item.module
|
||||
);
|
||||
if (!moduleDef) continue;
|
||||
item.children = [];
|
||||
|
||||
addChildren(item.module, moduleDef, item.children);
|
||||
addChildren(item.module, moduleDef, item.children);
|
||||
}
|
||||
|
||||
items.value = modules;
|
||||
}
|
||||
|
||||
items.value = modules;
|
||||
}
|
||||
if (props.source === 'card') {
|
||||
const currentRoute = route.matched[1];
|
||||
const currentModule = toLowerCamel(currentRoute.name);
|
||||
let moduleDef = routes.find(
|
||||
(route) => toLowerCamel(route.name) === currentModule
|
||||
);
|
||||
|
||||
function getCardRoutes() {
|
||||
console.log('getCardRoutes');
|
||||
const currentRoute = route.matched[1];
|
||||
const currentModule = toLowerCamel(currentRoute.name);
|
||||
let moduleDef = routes.find((route) => toLowerCamel(route.name) === currentModule);
|
||||
|
||||
if (!moduleDef) return;
|
||||
if (!moduleDef?.menus) moduleDef = betaGetRoutes();
|
||||
addChildren(currentModule, moduleDef, items.value);
|
||||
if (!moduleDef) return;
|
||||
if (!moduleDef?.menus) moduleDef = betaGetRoutes();
|
||||
addChildren(currentModule, moduleDef, items.value);
|
||||
}
|
||||
}
|
||||
|
||||
function betaGetRoutes() {
|
||||
|
|
|
@ -132,37 +132,40 @@ function mount(source) {
|
|||
return wrapper;
|
||||
}
|
||||
|
||||
describe('getRoutes', () => {
|
||||
afterEach(() => vi.clearAllMocks());
|
||||
const getRoutes = vi
|
||||
.fn()
|
||||
.mockImplementation((props, getMainRoutes, getCardRoutes) => {
|
||||
const handleRoutes = {
|
||||
main: getMainRoutes,
|
||||
card: getCardRoutes,
|
||||
};
|
||||
console.log(props.source);
|
||||
handleRoutes[props.source]();
|
||||
});
|
||||
describe.only('getRoutes', () => {
|
||||
beforeEach(() => {});
|
||||
// afterEach(() => vi.clearAllMocks());
|
||||
// const getRoutes = vi
|
||||
// .fn()
|
||||
// .mockImplementation((props, getMainRoutes, getCardRoutes) => {
|
||||
// const handleRoutes = {
|
||||
// main: getMainRoutes,
|
||||
// card: getCardRoutes,
|
||||
// };
|
||||
// console.log(props.source);
|
||||
// handleRoutes[props.source]();
|
||||
// });
|
||||
|
||||
const getMainRoutes = vi.fn();
|
||||
const getCardRoutes = vi.fn();
|
||||
// const getMainRoutes = vi.fn();
|
||||
// const getCardRoutes = vi.fn();
|
||||
it('should call getCardRoutes when source is card', () => {
|
||||
vm = mount('card').vm;
|
||||
let props = { source: 'card' };
|
||||
vi.spyOn(vm, 'getCardRoutes');
|
||||
vm.getRoutes();
|
||||
// getRoutes(props, getMainRoutes, getCardRoutes);
|
||||
|
||||
getRoutes(props, getMainRoutes, getCardRoutes);
|
||||
|
||||
expect(getCardRoutes).toHaveBeenCalled();
|
||||
expect(getMainRoutes).not.toHaveBeenCalled();
|
||||
expect(vm.getCardRoutes).toHaveBeenCalled();
|
||||
// expect(vm.getMainRoutes).not.toHaveBeenCalled();
|
||||
});
|
||||
it('should call getMainRoutes when source is main', () => {
|
||||
let props = { source: 'main' };
|
||||
// it.skip('should call getMainRoutes when source is main', () => {
|
||||
// let props = { source: 'main' };
|
||||
|
||||
getRoutes(props, getMainRoutes, getCardRoutes);
|
||||
// getRoutes(props, getMainRoutes, getCardRoutes);
|
||||
|
||||
expect(getMainRoutes).toHaveBeenCalled();
|
||||
expect(getCardRoutes).not.toHaveBeenCalled();
|
||||
});
|
||||
// expect(getMainRoutes).toHaveBeenCalled();
|
||||
// expect(getCardRoutes).not.toHaveBeenCalled();
|
||||
// });
|
||||
});
|
||||
describe.skip('Leftmenu as card', () => {
|
||||
beforeAll(() => {
|
||||
|
@ -372,11 +375,6 @@ describe.only('addChildren', () => {
|
|||
vm.addChildren(module, route, parent);
|
||||
|
||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
||||
// expect(useNavigationStore().addMenuItem).toHaveBeenCalledWith(
|
||||
// module,
|
||||
// { name: 'child1' },
|
||||
// parent
|
||||
// );
|
||||
});
|
||||
|
||||
it.only('should not add menu items if no matches are found', () => {
|
||||
|
@ -389,24 +387,14 @@ describe.only('addChildren', () => {
|
|||
|
||||
vm.addChildren(module, route, parent);
|
||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
||||
// expect(useNavigationStore().addMenuItem).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should handle routes with no meta menu', () => {
|
||||
const module = 'testModule';
|
||||
// const route = {
|
||||
// menus: { main: 'child1' },
|
||||
// children: [{ name: 'child1' }, { name: 'child2' }],
|
||||
// };
|
||||
const parent = [];
|
||||
|
||||
vm.addChildren(module, route, parent);
|
||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
||||
// expect(useNavigationStore().addMenuItem).toHaveBeenCalledWith(
|
||||
// module,
|
||||
// { name: 'child1' },
|
||||
// parent
|
||||
// );
|
||||
});
|
||||
|
||||
it('should handle routes with no matches', () => {
|
||||
|
@ -419,23 +407,13 @@ describe.only('addChildren', () => {
|
|||
|
||||
vm.addChildren(module, route, parent);
|
||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
||||
// expect(useNavigationStore().addMenuItem).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should handle empty parent array', () => {
|
||||
const module = 'testModule';
|
||||
// const route = {
|
||||
// meta: { menu: 'child1' },
|
||||
// children: [{ name: 'child1' }, { name: 'child2' }],
|
||||
// };
|
||||
const parent = [];
|
||||
|
||||
vm.addChildren(module, route, parent);
|
||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
||||
// expect(useNavigationStore().addMenuItem).toHaveBeenCalledWith(
|
||||
// module,
|
||||
// { name: 'child1' },
|
||||
// parent
|
||||
// );
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue