From c3ea54dcd46ce135059d65110732a3fd8bf2ecd4 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Tue, 25 Aug 2026 19:56:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/components/AdminSidebarMenu.test.ts | 45 ++++-- src/app/components/AdminSidebarMenu.vue | 28 +++- src/core/routing/navigationRecovery.test.ts | 80 ++++++++++ src/core/routing/navigationRecovery.ts | 74 +++++++++ src/main.ts | 29 +++- .../api/platformContainerLoading.test.ts | 6 +- .../api/platformContainerLoading.ts | 1 + .../pages/ContainersView.test.ts | 145 +++++++++++++++--- .../pages/ContainersView.vue | 107 +++++++++---- .../pages/GlobalSmartLoadingView.test.ts | 2 +- .../pages/SmartLoadingWorkbenchView.test.ts | 2 +- src/modules/container-loading/types.ts | 2 + .../api/platformOceanBookings.test.ts | 12 +- .../api/platformOceanBookings.ts | 23 ++- src/modules/ocean-bookings/index.ts | 2 +- src/modules/ocean-bookings/types.ts | 24 +++ 16 files changed, 511 insertions(+), 71 deletions(-) create mode 100644 src/core/routing/navigationRecovery.test.ts create mode 100644 src/core/routing/navigationRecovery.ts diff --git a/src/app/components/AdminSidebarMenu.test.ts b/src/app/components/AdminSidebarMenu.test.ts index 8b259de6..116661c4 100644 --- a/src/app/components/AdminSidebarMenu.test.ts +++ b/src/app/components/AdminSidebarMenu.test.ts @@ -1,4 +1,6 @@ -import { mount } from '@vue/test-utils' +import { flushPromises, mount } from '@vue/test-utils' +import { defineComponent } from 'vue' +import { createMemoryHistory, createRouter } from 'vue-router' import { describe, expect, it } from 'vitest' import { adminNavigation, filterAdminNavigation, type AdminNavigationNode } from '@/core/navigation/adminNavigation' import AdminSidebarMenu from './AdminSidebarMenu.vue' @@ -19,10 +21,12 @@ const visibleNavigation = filterAdminNavigation(adminNavigation, new Set([ ])) const stubs = { - 'el-menu': { + 'el-menu': defineComponent({ props: ['defaultActive', 'defaultOpeneds', 'collapse'], - template: '', - }, + emits: ['select'], + methods: { updateActiveIndex() {} }, + template: '', + }), 'el-sub-menu': { props: ['index'], template: '
', @@ -34,10 +38,20 @@ const stubs = { } describe('AdminSidebarMenu', () => { + function routerPlugin() { + return createRouter({ + history: createMemoryHistory(), + routes: [ + { path: '/', component: { template: '

' } }, + { path: '/warehouses', component: { template: '

' } }, + ], + }) + } + it('renders the visible phase-one modules and forwards the active route', () => { const wrapper = mount(AdminSidebarMenu, { props: { items: visibleNavigation, activePath: '/system/users', collapsed: false }, - global: { stubs }, + global: { stubs, plugins: [routerPlugin()] }, }) expect(wrapper.get('nav').attributes('data-active')).toBe('/system/users') @@ -62,7 +76,7 @@ describe('AdminSidebarMenu', () => { it('forwards desktop collapse state to Element Plus', () => { const wrapper = mount(AdminSidebarMenu, { props: { items: visibleNavigation, activePath: '/', collapsed: true }, - global: { stubs }, + global: { stubs, plugins: [routerPlugin()] }, }) expect(wrapper.get('nav').attributes('data-collapsed')).toBe('true') @@ -72,7 +86,7 @@ describe('AdminSidebarMenu', () => { const items = filterAdminNavigation(adminNavigation, new Set(['platform:permission:list'])) const wrapper = mount(AdminSidebarMenu, { props: { items, activePath: '/', collapsed: false }, - global: { stubs }, + global: { stubs, plugins: [routerPlugin()] }, }) expect(wrapper.text()).toContain('菜单权限') @@ -100,7 +114,7 @@ describe('AdminSidebarMenu', () => { }] const wrapper = mount(AdminSidebarMenu, { props: { items, activePath: '/tracking', collapsed: false }, - global: { stubs }, + global: { stubs, plugins: [routerPlugin()] }, }) expect(wrapper.findAll('[data-kind="group"]')).toHaveLength(2) @@ -110,7 +124,7 @@ describe('AdminSidebarMenu', () => { it('recreates the menu when asynchronously loaded groups change', async () => { const wrapper = mount(AdminSidebarMenu, { props: { items: [adminNavigation[0]], activePath: '/dashboard', collapsed: false }, - global: { stubs }, + global: { stubs, plugins: [routerPlugin()] }, }) const initialMenu = wrapper.get('nav').element @@ -119,4 +133,17 @@ describe('AdminSidebarMenu', () => { expect(wrapper.get('nav').element).not.toBe(initialMenu) expect(wrapper.text()).toContain('系统管理') }) + + it('navigates explicitly when a leaf menu item is selected', async () => { + const router = routerPlugin() + await router.push('/') + const wrapper = mount(AdminSidebarMenu, { + props: { items: visibleNavigation, activePath: '/', collapsed: false }, + global: { stubs, plugins: [router] }, + }) + + await wrapper.get('nav').trigger('click') + await flushPromises() + expect(router.currentRoute.value.path).toBe('/warehouses') + }) }) diff --git a/src/app/components/AdminSidebarMenu.vue b/src/app/components/AdminSidebarMenu.vue index 7577593e..b34e9ec6 100644 --- a/src/app/components/AdminSidebarMenu.vue +++ b/src/app/components/AdminSidebarMenu.vue @@ -1,5 +1,7 @@