Files
admin-web/src/modules/loading-lists/components/LoadingListsView.test.ts
T

200 lines
11 KiB
TypeScript
Raw Normal View History

2026-08-10 15:36:53 +08:00
import { describe, expect, it } from 'vitest'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
const source = readFileSync(resolve(process.cwd(), 'src/modules/loading-lists/components/LoadingListsView.vue'), 'utf8')
const detailSource = readFileSync(resolve(process.cwd(), 'src/modules/loading-lists/components/LoadingListDetailDrawer.vue'), 'utf8')
2026-08-12 16:31:46 +08:00
const preloadDetailSource = readFileSync(resolve(process.cwd(), 'src/modules/loading-lists/pages/PreloadPlanDetailView.vue'), 'utf8')
2026-08-15 12:33:29 +08:00
const confirmedDetailSource = readFileSync(resolve(process.cwd(), 'src/modules/loading-lists/pages/ConfirmedLoadingListDetailView.vue'), 'utf8')
const routesSource = readFileSync(resolve(process.cwd(), 'src/modules/loading-lists/routes.ts'), 'utf8')
2026-08-10 15:36:53 +08:00
describe('LoadingListsView', () => {
2026-08-14 13:03:11 +08:00
it('filters both list modes by an active name-only customer selector', () => {
expect(source).toContain("listPlatformTenants({ page: 1, size: 200, status: 'ACTIVE' })")
2026-08-14 14:27:03 +08:00
expect(source).toContain("label: customer.tenantName")
2026-08-14 13:03:11 +08:00
expect(source).toContain("customerId: String(query.customerId || '').trim() || undefined")
expect(source).not.toContain('customer.tenantCode')
})
2026-08-10 15:36:53 +08:00
it('keeps the operation column first and fixed left in both lists', () => {
const actionColumns = [...source.matchAll(/key: 'actions', label: '操作', fixed: 'left'/g)]
expect(actionColumns).toHaveLength(2)
expect(source.indexOf("key: 'actions'")).toBeLessThan(source.indexOf("key: 'preloadNo'"))
expect(source.indexOf("key: 'actions'", source.indexOf("key: 'actions'") + 1)).toBeLessThan(source.indexOf("key: 'loadingListNo'"))
})
it('queries all warehouses without exposing a warehouse selector', () => {
expect(source).not.toContain('listAllPlatformWarehouses')
expect(source).not.toContain("key: 'warehouseId'")
expect(source).not.toContain('loadingWarehouses')
expect(source).not.toContain('warehouseId: warehouseId || undefined')
expect(source).toContain('query: { warehouseId: String(row.warehouseId || \'\') }')
2026-08-10 17:42:17 +08:00
expect(source).not.toContain("ElMessage.warning('请先选择仓库')")
expect(source).not.toContain("'请先选择仓库后查询'")
expect(preloadDetailSource).toContain('MISSING_WAREHOUSE_CONTEXT')
expect(confirmedDetailSource).toContain('MISSING_WAREHOUSE_CONTEXT')
2026-08-10 15:36:53 +08:00
})
it('uses the shared query and table components while keeping details on route pages', () => {
2026-08-10 15:36:53 +08:00
expect(source).toContain('QueryToolbar')
expect(source).toContain('DataTable')
expect(source).toContain('LoadErrorState')
expect(source).toContain('ApiErrorMeta')
expect(preloadDetailSource).toContain('AppDialog')
expect(confirmedDetailSource).toContain('AppDialog')
2026-08-12 16:31:46 +08:00
expect(detailSource).not.toContain('AppDrawer')
expect(detailSource).toContain('ContainerFeesPanel')
})
it('distinguishes the generated cabinet reference from the physical container number', () => {
expect(source).toContain("label: '柜次号'")
expect(source).toContain("label: '集装箱号'")
expect(source).toContain('装柜清单号/柜次号/集装箱号')
expect(detailSource).toContain('<span>柜次号</span>')
expect(detailSource).toContain('<span>集装箱号</span>')
expect(source).not.toContain("label: '柜号'")
expect(detailSource).not.toContain('<span>柜号</span>')
expect(source).toContain("key: 'cabinetNo', prop: 'cabinetNo'")
expect(source).not.toContain('internalContainerNo')
})
2026-08-15 12:33:29 +08:00
it('opens both preload and confirmed details as independent route pages', () => {
2026-08-12 16:31:46 +08:00
expect(source).toContain("name: 'preload-plan-detail'")
2026-08-15 12:33:29 +08:00
expect(source).toContain("name: 'loading-list-detail'")
expect(source).not.toContain('confirmed-inline-detail')
2026-08-12 16:31:46 +08:00
expect(preloadDetailSource).toContain('返回列表')
expect(preloadDetailSource).toContain('router.back()')
2026-08-15 12:33:29 +08:00
expect(confirmedDetailSource).toContain('返回列表')
expect(confirmedDetailSource).toContain('router.back()')
2026-08-17 19:13:25 +08:00
expect(confirmedDetailSource).toContain('@media (min-width: 1920px) { .confirmed-loading-detail-page { width: 100%; max-width: none; gap: 12px; } }')
2026-08-15 12:33:29 +08:00
expect(routesSource).toContain("path: 'loading-lists/:planId'")
expect(routesSource).toContain("name: 'loading-list-detail'")
2026-08-12 16:31:46 +08:00
})
it('keeps the real transport edit contract in a 620px centered modal on the detail page', () => {
expect(source).not.toContain('class="loading-transport-dialog"')
2026-08-12 16:31:46 +08:00
expect(preloadDetailSource).toContain('width="min(620px, calc(100vw - 28px))"')
expect(preloadDetailSource).not.toContain('备注信息(仅自己可见)')
expect(preloadDetailSource).not.toContain('备注信息(客户可见)')
expect(preloadDetailSource).not.toContain('备注信息(仓库可见)')
2026-08-10 15:36:53 +08:00
})
it('only exposes transport editing for LOADING preload details', () => {
2026-08-11 14:23:46 +08:00
expect(detailSource).toContain("mode === 'preload' && canEdit && ['EDITING', 'LOADING'].includes(summary.status)")
2026-08-13 11:57:44 +08:00
expect(detailSource).toContain('报关资料')
expect(detailSource).toContain('完成报关')
expect(preloadDetailSource).toContain('expectedVersion: detail.value.summary.version')
2026-08-10 15:36:53 +08:00
})
2026-08-11 10:35:39 +08:00
2026-08-11 11:52:30 +08:00
it('renders business labels instead of raw loading-plan status codes', () => {
2026-08-11 19:35:28 +08:00
expect(source).toContain(':status="loadingListStatusLabel(row.status)"')
expect(detailSource).toContain(':status="loadingListStatusLabel(summary.status)"')
2026-08-11 11:52:30 +08:00
expect(detailSource).not.toContain(':status="summary.status"')
expect(source).not.toContain('仅装柜中允许修改')
})
it('keeps transport editing as a detail-page action', () => {
expect(source).not.toContain('openEditFromRow(row)')
expect(source).not.toContain('编辑运输信息')
expect(detailSource).toContain("{{ preloadSummary?.containerNo ? '修改集装箱号 / 航次' : '录入集装箱号' }}")
expect(preloadDetailSource).toContain("const editDialogTitle = computed(() => detail.value?.summary.containerNo ? '修改集装箱号 / 航次' : '录入集装箱号')")
2026-08-11 10:35:39 +08:00
})
it('refreshes the detail version on A0409 while preserving transport input', () => {
expect(preloadDetailSource).toContain("details.code === 'A0409'")
expect(preloadDetailSource).toContain('await loadDetail()')
expect(preloadDetailSource).toContain('当前输入已保留,请核对后重新保存')
})
it('opens a validated plan and warehouse deep link without mixing list modes', () => {
expect(source).toContain('useRoute()')
expect(source).toContain('route.query.planId')
expect(source).toContain('route.query.warehouseId')
2026-08-15 12:33:29 +08:00
expect(source).toContain("router.replace({ name: 'loading-list-detail'")
expect(confirmedDetailSource).toContain("result.summary.status !== 'COMPLETED'")
expect(confirmedDetailSource).toContain('MODE_STATUS_MISMATCH')
})
it('uses backend readiness for whole-plan confirmation and translates blocking reasons', () => {
expect(detailSource).toContain(':disabled="!preloadSummary?.readiness.canConfirm"')
expect(detailSource).toContain("PRELOAD_NOT_PUSHED: '尚未推送预装清单'")
expect(detailSource).toContain("OCEAN_BOOKING_NOT_RELEASED: '关联订舱尚未放舱'")
expect(detailSource).toContain("PRELOAD_ALREADY_CONFIRMED: '整份预装计划已经确认'")
expect(detailSource).toContain("confirmationStatus === 'CONFIRMED'")
expect(detailSource).toContain("pdaTaskStatusLabels")
expect(preloadDetailSource).toContain('@confirm-preload="openConfirmPreload"')
})
it('passes translated status text directly to the badge', () => {
2026-08-11 19:35:28 +08:00
expect(source).toContain('<StatusBadge :status="loadingListStatusLabel(row.status)" />')
expect(source).not.toContain('<StatusBadge :status="row.status" />')
2026-08-11 19:35:28 +08:00
expect(detailSource).toContain('<StatusBadge :status="loadingListStatusLabel(summary.status)" />')
})
2026-08-12 09:25:55 +08:00
2026-08-12 18:00:26 +08:00
it('uses bordered list actions with a stable 320px layout', () => {
expect(source).toContain('size="small" type="primary" plain')
expect(source).not.toContain('<el-button v-if="canView" link')
expect(source).toContain("key: 'actions', label: '操作', fixed: 'left', width: 110")
2026-08-12 18:00:26 +08:00
expect(source).toContain('flex-wrap: wrap')
expect(source).toContain('@media (max-width: 720px)')
expect(source).toContain('.row-actions { gap: 4px; }')
2026-08-12 18:16:44 +08:00
expect(source).toContain(':loading="loading"\n stripe')
expect(detailSource).toContain(':columns="itemColumns"\n stripe')
2026-08-12 18:00:26 +08:00
})
2026-08-17 19:52:04 +08:00
it('shows every prototype detail field that is backed by the loading item contract', () => {
const fields = [
'chineseName',
'englishName',
'netWeightKg',
'packageCount',
'palletCount',
'volumeCbm',
'grossWeightKg',
'dimensionalWeightKg',
'productQuantity',
'unitsPerPackage',
'fbaTrackingNo',
'shipmentNo',
'shippingMark',
'internalRemark',
'customerRemark',
'warehouseRemark',
'customsDocument',
]
let previous = detailSource.indexOf("key: 'customerName'")
for (const field of fields) {
const current = detailSource.indexOf(`key: '${field}'`, previous + 1)
expect(current, field).toBeGreaterThan(previous)
previous = current
}
expect(detailSource).not.toContain("key: 'goodsImageUrl'")
expect(detailSource).not.toContain("label: '退税资料'")
})
2026-08-12 09:25:55 +08:00
it('does not expose unknown history action codes', () => {
expect(detailSource).toContain("CONFIRM_PRELOAD: '确认预装'")
2026-08-12 09:25:55 +08:00
expect(detailSource).toContain("[action] || '状态更新'")
expect(detailSource).not.toContain('[action] || action')
})
2026-08-12 10:59:49 +08:00
it('uses safe labels when customer or operator names are missing', () => {
2026-08-12 12:35:32 +08:00
expect(source).toContain("item.customerName || '客户信息缺失'")
expect(source).not.toContain('item.customerName || item.accountId')
2026-08-12 10:59:49 +08:00
expect(detailSource).toContain("item.customerName || '客户信息缺失'")
expect(detailSource).toContain("history.operatorName || '操作人信息缺失'")
expect(detailSource).not.toContain('item.customerName || item.accountId')
expect(detailSource).not.toContain('history.operatorName || history.operatorId')
})
2026-08-13 11:57:44 +08:00
it('uploads declaration documents from a file picker and freezes them after completion', () => {
2026-08-15 12:33:29 +08:00
expect(confirmedDetailSource).toContain('<el-upload :auto-upload="false" :limit="1"')
expect(confirmedDetailSource).toContain('@confirm="uploadCustomsDocument"')
expect(confirmedDetailSource).toContain('uploadLoadingDeclaration(')
expect(confirmedDetailSource).toContain('getLoadingDeclaration(planId.value, warehouseId.value)')
expect(confirmedDetailSource).toContain("details.code === 'A0404'")
2026-08-13 11:57:44 +08:00
expect(detailSource).toContain("canManageCustoms && !detail.customsDocument?.completedAt")
2026-08-15 12:33:29 +08:00
expect(confirmedDetailSource).not.toContain('文件 ID')
expect(confirmedDetailSource).not.toContain('fileId')
expect(confirmedDetailSource).not.toContain('上传入口待')
2026-08-13 11:57:44 +08:00
})
2026-08-10 15:36:53 +08:00
})