import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import test from "node:test"; const appRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); const readSource = (relativePath) => readFileSync(resolve(appRoot, relativePath), "utf8"); test("APP 首页展示 PC 端核心运营统计并保护移动端横向空间", () => { const source = readSource("src/pages/index.vue"); for (const className of [ "dashboard-overview", "dashboard-kpi-grid", "dashboard-trend-card", "dashboard-distribution-card", "dashboard-trend-range", "dashboard-status-list", ]) { assert.match(source, new RegExp(`class=\\"[^\\"]*${className}[^\\"]*\\"`)); } for (const label of [ "当前库存托盘", "剩余包数", "今日入库单", "今日出库单", "待确认单据", "入库 / 出库趋势", "托盘流转状态分布", ]) { assert.match(source, new RegExp(label)); } assert.match(source, /listPalletInventory/); assert.match(source, /listShipmentReport/); assert.match(source, /listInbound/); assert.match(source, /listShipment/); assert.match(source, /listReturn/); assert.match(source, /TREND_RANGE_OPTIONS/); assert.match(source, /overflow-x:\s*hidden/); assert.match(source, /min-width:\s*0/); }); test("APP 首页统计保留加载、空数据和部分失败状态", () => { const source = readSource("src/pages/index.vue"); assert.match(source, /statsLoading/); assert.match(source, /statsError/); assert.match(source, /dashboard-stat-empty/); assert.match(source, /dashboard-stat-error/); assert.match(source, /formatMetric/); assert.match(source, /--/); }); test("APP 首页扫码异常支持默认收起并通过标题展开", () => { const source = readSource("src/pages/index.vue"); assert.match(source, /const exceptionsExpanded = ref\(false\)/); assert.match(source, /function toggleExceptionList\(\)/); assert.match(source, /class="[^"]*exception-header[^"]*"/); assert.match(source, /@click="toggleExceptionList"/); assert.match(source, /exception-toggle-icon/); assert.match(source, /v-else-if="exceptionsExpanded" class="exception-list"/); }); test("APP 首页报表 API 复用现有只读报表路径", () => { const inventorySource = readSource("src/api/report/palletInventory.js"); const shipmentSource = readSource("src/api/report/shipment.js"); assert.match(inventorySource, /export function listPalletInventory\(/); assert.match(inventorySource, /url:\s*["']\/report\/pallet-inventory\/list["']/); assert.match(inventorySource, /method:\s*["']get["']/); assert.match(shipmentSource, /export function listShipmentReport\(/); assert.match(shipmentSource, /url:\s*["']\/report\/shipment\/list["']/); assert.match(shipmentSource, /method:\s*["']get["']/); });