This commit is contained in:
2026-08-20 09:10:36 +08:00
parent 033b5df6b6
commit 508f76924e
58 changed files with 1790 additions and 628 deletions
@@ -0,0 +1,57 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import ElementPlus from 'element-plus'
import CarrierScheduleQueryPanel from './CarrierScheduleQueryPanel.vue'
import { getCarrierScheduleQuery, listCarrierScheduleQueries } from '../api/platformCarrierScheduleQueries'
import { getPortSchedule } from '../api/platformPortSchedules'
vi.mock('../api/platformCarrierScheduleQueries', () => ({
listCarrierScheduleQueries: vi.fn(),
getCarrierScheduleQuery: vi.fn(),
}))
vi.mock('../api/platformPortSchedules', () => ({ getPortSchedule: vi.fn() }))
const queryView = {
query: {
id: '11', queryNo: 'CSQ11', customerId: '1', oceanBookingId: '2', containerBookingId: '3',
carrierCode: 'COSCO', trackingType: 'CONTAINER_NO', trackingNo: 'CSNU1234567',
officialUrl: 'https://elines.coscoshipping.com/ebusiness/', accessMode: 'DYNAMIC_IFRAME',
status: 'MANUAL_REQUIRED' as const, attemptCount: 2, lastAttemptStatus: 'MANUAL_REQUIRED',
lastErrorCode: 'DYNAMIC_IFRAME_REQUIRED', lastErrorMessage: '必须人工查询',
resultPortScheduleId: '21', version: 1,
},
expired: true,
maxAttempts: 3,
nextAllowedAt: '2026-08-22T10:00:00',
}
describe('CarrierScheduleQueryPanel loading states', () => {
beforeEach(() => vi.clearAllMocks())
it('keeps list facts visible when history and linked schedule both fail', async () => {
vi.mocked(listCarrierScheduleQueries).mockResolvedValue({ records: [queryView], page: 1, size: 200, total: 1, pages: 1 })
vi.mocked(getCarrierScheduleQuery).mockRejectedValue(new Error('detail unavailable'))
vi.mocked(getPortSchedule).mockRejectedValue(new Error('schedule unavailable'))
const wrapper = mount(CarrierScheduleQueryPanel, { props: { oceanBookingId: '2', containerBookingId: '3' }, global: { plugins: [ElementPlus] } })
await flushPromises()
expect(listCarrierScheduleQueries).toHaveBeenCalledWith({ page: 1, size: 200, oceanBookingId: '2', containerBookingId: '3' })
expect(getCarrierScheduleQuery).toHaveBeenCalledWith('11')
expect(getPortSchedule).toHaveBeenCalledWith('21')
expect(wrapper.text()).toContain('CSQ11')
expect(wrapper.text()).toContain('查询尝试与变更历史暂不可用')
expect(wrapper.text()).toContain('关联船期结果暂不可用')
expect(wrapper.text()).toContain('DYNAMIC_IFRAME_REQUIRED')
})
it('shows an explicit non-fabricated empty state and performs no detail reads', async () => {
vi.mocked(listCarrierScheduleQueries).mockResolvedValue({ records: [], page: 1, size: 200, total: 0, pages: 0 })
const wrapper = mount(CarrierScheduleQueryPanel, { props: { oceanBookingId: '2' }, global: { plugins: [ElementPlus] } })
await flushPromises()
expect(wrapper.text()).toContain('不会模拟节点或自动创建任务')
expect(getCarrierScheduleQuery).not.toHaveBeenCalled()
expect(getPortSchedule).not.toHaveBeenCalled()
})
})