fix(admin): consume booking link actions when cached pages reactivate

This commit is contained in:
2026-09-09 12:15:24 +08:00
parent d6a69ea157
commit 4ccad3bc3c
2 changed files with 69 additions and 14 deletions
@@ -1,6 +1,7 @@
import ElementPlus from 'element-plus'
import { createPinia, setActivePinia } from 'pinia'
import { createMemoryHistory, createRouter } from 'vue-router'
import { defineComponent } from 'vue'
import { flushPromises, mount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { readFileSync } from 'node:fs'
@@ -34,7 +35,7 @@ const drayage = {
function createTestRouter() {
return createRouter({ history: createMemoryHistory(), routes: [
{ path: '/', component: ContainersView },
{ path: '/', name: 'domestic-container-workbench', component: ContainersView },
{ path: '/container-loading/domestic/:containerId/smart-loading', name: 'smart-loading-workbench', component: { template: '<div />' } },
{ path: '/loading-plans', name: 'loading-plans', component: { template: '<div />' } },
{ path: '/container-loading/domestic/:containerId', name: 'domestic-container-detail', component: { template: '<div />' } },
@@ -417,12 +418,57 @@ describe('ContainersView', () => {
wrapper.unmount()
})
it('opens the existing released-booking workflow when entered from container detail', () => {
const source = readFileSync(resolve(process.cwd(), 'src/modules/container-loading/pages/ContainersView.vue'), 'utf8')
expect(source).toContain('route.query.linkContainerId')
expect(source).toContain("const target = await getContainer(linkContainerId, 'DOMESTIC')")
expect(source).toContain('await openLink(target)')
expect(source).toContain("void router.replace({ name: 'domestic-container-workbench' })")
it('consumes the booking-link action once when returning to a cached list and preserves other query state', async () => {
vi.mocked(getContainer).mockClear()
vi.mocked(listContainers).mockClear()
vi.mocked(listOceanBookingLinkCandidates).mockClear().mockResolvedValue({ records: [], page: 1, size: 200, total: 0, pages: 0 })
const router = createTestRouter()
await router.push('/'); await router.isReady()
const shell = defineComponent({ template: '<router-view v-slot="{ Component }"><keep-alive><component :is="Component" /></keep-alive></router-view>' })
const wrapper = mount(shell, { global: { plugins: [ElementPlus, router] } })
await flushPromises()
const initial = wrapper.findComponent(ContainersView).vm.$.uid
await router.push('/container-loading/domestic/9001')
await flushPromises()
await router.push({ name: 'domestic-container-workbench', query: { linkContainerId: '9001', keyword: 'CB-1' }, hash: '#table' })
await flushPromises()
expect(wrapper.findComponent(ContainersView).vm.$.uid).toBe(initial)
expect(getContainer).toHaveBeenCalledTimes(1)
expect(listOceanBookingLinkCandidates).toHaveBeenCalledTimes(1)
expect(listContainers).toHaveBeenCalledTimes(1)
expect(router.currentRoute.value.query).toEqual({ keyword: 'CB-1' })
expect(router.currentRoute.value.hash).toBe('#table')
const dialog = wrapper.findAllComponents(AppDialog).find((item) => item.props('title') === '关联已放舱订舱')!
expect(dialog.props('modelValue')).toBe(true)
dialog.vm.$emit('update:modelValue', false)
await flushPromises()
await router.push('/container-loading/domestic/9001')
await router.push({ name: 'domestic-container-workbench' })
await flushPromises()
expect(dialog.props('modelValue')).toBe(false)
expect(getContainer).toHaveBeenCalledTimes(1)
expect(listOceanBookingLinkCandidates).toHaveBeenCalledTimes(1)
wrapper.unmount()
})
it('ignores a stale linking response after leaving the list', async () => {
const target = await vi.mocked(getContainer).getMockImplementation()!('9001', 'DOMESTIC')
let finish!: (value: typeof target) => void
vi.mocked(getContainer).mockClear().mockImplementationOnce(() => new Promise((resolve) => { finish = resolve }))
vi.mocked(listOceanBookingLinkCandidates).mockClear()
const router = createTestRouter()
await router.push({ name: 'domestic-container-workbench', query: { linkContainerId: '9001' } }); await router.isReady()
const wrapper = mount(ContainersView, { global: { plugins: [ElementPlus, router] } })
await flushPromises()
await router.replace({ query: { linkContainerId: '9001', keyword: 'updated' } })
await flushPromises()
expect(getContainer).toHaveBeenCalledTimes(1)
await router.push('/container-loading/domestic/9001')
finish(target)
await flushPromises()
expect(listOceanBookingLinkCandidates).not.toHaveBeenCalled()
expect(router.currentRoute.value.name).toBe('domestic-container-detail')
wrapper.unmount()
})
it('normalizes an optional booking-link container number', async () => {