Files
admin-web/src/modules/loading-lists/pages/PreloadPlanDetailView.test.ts
T

98 lines
5.8 KiB
TypeScript

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/pages/PreloadPlanDetailView.vue'), 'utf8')
const detailSource = readFileSync(resolve(process.cwd(), 'src/modules/loading-lists/components/LoadingListDetailDrawer.vue'), 'utf8')
describe('PreloadPlanDetailView prototype contract', () => {
it('is a formal desktop detail page wired to the shared header return action', () => {
expect(source).toContain('<AdminPage>')
expect(source).toContain('@back="goBack"')
expect(source).toContain("router.push({ name: 'loading-plans' })")
expect(source).toContain('@media (min-width: 1920px) { .preload-detail-page { width: 100%; max-width: none; gap: 12px; } }')
expect(source).not.toContain('AppDrawer')
})
it('requires the real warehouse context and preserves status boundaries', () => {
expect(source).toContain('MISSING_WAREHOUSE_CONTEXT')
expect(source).toContain("['EDITING', 'LOADING'].includes(result.summary.status)")
expect(source).toContain('MODE_STATUS_MISMATCH')
})
it('uses the real optimistic-lock transport endpoint without inventing note writes', () => {
expect(source).toContain('updatePreloadTransport')
expect(source).toContain('expectedVersion: detail.value.summary.version')
expect(source).toContain('width="min(620px, calc(100vw - 28px))"')
expect(source).not.toContain('saveMfNote')
})
it('edits only the selected item warehouse remark with optimistic locking', () => {
expect(source).toContain('@edit-warehouse-remark="openWarehouseRemark"')
expect(source).toContain('updateLoadingItemWarehouseRemark(current.summary.planId, target.itemId')
expect(source).toContain('expectedPlanVersion: current.summary.version')
expect(source).toContain('expectedItemVersion: target.itemVersion')
expect(source).toContain('operationId: remarkOperationId.value')
expect(source).toContain('maxlength="1000"')
expect(source).toContain("warehouseRemark.value.trim() || null")
expect(source).toContain('summary: { ...current.summary, version: result.version }')
expect(source).toContain('updatedItem?.version')
expect(source).not.toContain('plan.remark')
})
it('preserves warehouse remark input and refreshes current data on conflicts', () => {
expect(source).toContain("details.code === 'A0409'")
expect(source).toContain('await loadDetail()')
expect(source).toContain("detail.value?.items.find((item) => item.itemId === target.itemId) || target")
expect(source).toContain('当前输入已保留')
expect(source).toContain('计划状态或明细版本已变化')
expect(source).toContain(':confirm-loading="remarkSaving"')
})
it('keeps preload as a correction-only entry before PDA claim and does not imply that preload directly opens PDA', () => {
expect(source).toContain("{ required: true, message: '请输入集装箱号'")
expect(source).toContain("summary.status === 'EDITING'")
expect(source).toContain("(!pdaStatus || pdaStatus === 'PENDING')")
expect(source).toContain('PDA 已领取或作业已开始,真实集装箱号只读。')
expect(source).toContain("const editDialogTitle = computed(() => '纠正集装箱号 / 航次')")
expect(source).toContain("{ required: true, message: '请输入操作原因'")
expect(source).toContain("String(value || '').trim().toUpperCase()")
expect(source).toContain('operationReason: editForm.operationReason.trim()')
expect(detailSource).toContain('v-if="canEditTransport"')
expect(detailSource).not.toContain("preloadSummary?.containerNo ? '修改集装箱号 / 航次' : '录入集装箱号'")
expect(source).toContain('由服务端按真实条件创建唯一 PDA 任务')
expect(source).toContain('真实集装箱号未录入时不能确认')
expect(source).toContain('PDA 领取或作业开始后集装箱号只读')
})
it('uses a flat blocking note instead of repeated colored page alerts', () => {
expect(source).not.toContain('<el-alert\n v-if="detail"')
expect(detailSource).toContain('class="readiness-note"')
expect(detailSource).toContain('role="status"')
expect(detailSource).toContain("confirmationStatus !== 'CONFIRMED' && !preloadSummary.readiness.canConfirm")
expect(detailSource).not.toContain('type="success" :closable="false" show-icon title="整份预装计划已确认"')
expect(detailSource).toContain('<el-button type="primary" :loading="confirmSaving"')
expect(detailSource).not.toContain('<el-button type="success" :loading="confirmSaving"')
})
it('confirms the whole plan through readiness with stable idempotency and refreshes the detail', () => {
expect(source).toContain('confirmPreloadPlan(summary.planId, summary.version, confirmOperationId.value)')
expect(source).toContain('summary?.readiness.canConfirm')
expect(source).toContain('confirmSaving.value')
expect(source).toContain('await loadDetail()')
expect(source).toContain('本操作将确认整份预装计划')
expect(source).toContain('全部入库预装票据')
expect(source).toContain('当前页面不会伪造 PDA 成功')
expect(source).not.toContain('/inbounds/')
})
it('keeps backend confirmation errors visible and supports narrow dialogs', () => {
expect(source).toContain("confirmError.value = getApiErrorDetails(cause, '确认预装失败,请稍后重试')")
expect(source).toContain('<OperationErrorToast :details="remarkError || editError || confirmError" />')
expect(source).not.toContain(':message="confirmError.message"')
expect(source).toContain('width="min(520px, calc(100vw - 28px))"')
expect(source).toContain("label=\"柜次号\"")
expect(source).toContain("label=\"集装箱号\"")
})
})