ForgeFlow-ERP/frontend/scripts/test-document-form-components.mjs
2026-06-13 00:18:37 +08:00

104 lines
3.5 KiB
JavaScript

import { existsSync, readFileSync } from "node:fs";
import { resolve } from "node:path";
const files = [
"src/components/documentForms/DocumentPaper.vue",
"src/components/documentForms/DocumentGrid.vue",
"src/components/documentForms/DocumentLineTable.vue",
"src/components/documentForms/WarehouseDocumentFormShell.vue",
"src/components/documentForms/DocumentArchiveActions.vue",
"src/styles/main.css"
];
const sources = new Map();
for (const file of files) {
const path = resolve(process.cwd(), file);
if (!existsSync(path)) {
throw new Error(`Missing required file: ${file}`);
}
const source = readFileSync(path, "utf8");
if (source.trim().length < 200) {
throw new Error(`Required file has unexpectedly short content: ${file}`);
}
sources.set(file, source);
}
const documentPaper = sources.get("src/components/documentForms/DocumentPaper.vue");
for (const snippet of ["ERP留存联", "document-paper-clip", "document-paper-binder-hole"]) {
if (!documentPaper.includes(snippet)) {
throw new Error(`DocumentPaper missing required snippet: ${snippet}`);
}
}
const archiveActions = sources.get("src/components/documentForms/DocumentArchiveActions.vue");
for (const snippet of ["预览PDF", "下载PDF", "重新生成"]) {
if (!archiveActions.includes(snippet)) {
throw new Error(`DocumentArchiveActions missing required label: ${snippet}`);
}
}
const warehouseDocumentFormShell = sources.get("src/components/documentForms/WarehouseDocumentFormShell.vue");
for (const snippet of ["formatChineseDate", "displayBusinessDate"]) {
if (!warehouseDocumentFormShell.includes(snippet)) {
throw new Error(`WarehouseDocumentFormShell missing business date formatting snippet: ${snippet}`);
}
}
if (warehouseDocumentFormShell.includes("{{ businessDate || \"-\" }}")) {
throw new Error("WarehouseDocumentFormShell must not render raw businessDate values");
}
for (const forbiddenSnippet of ["ghost-button", "action-button"]) {
if (archiveActions.includes(forbiddenSnippet)) {
throw new Error(`DocumentArchiveActions must not use global button class: ${forbiddenSnippet}`);
}
}
for (const snippet of ["document-archive-button", "normalizedStatusType", ".trim()"]) {
if (!archiveActions.includes(snippet)) {
throw new Error(`DocumentArchiveActions missing archive action hardening snippet: ${snippet}`);
}
}
const css = sources.get("src/styles/main.css");
for (const selector of [".document-paper-shell", ".document-paper-sheet", ".document-line-table"]) {
if (!css.includes(selector)) {
throw new Error(`main.css missing required selector: ${selector}`);
}
}
for (const selector of [
".document-grid-value input",
".document-grid-value select",
".document-grid-value textarea",
".document-line-table input",
".document-line-table select",
".document-line-table textarea"
]) {
if (!css.includes(selector)) {
throw new Error(`main.css missing document form overflow guard selector: ${selector}`);
}
}
for (const snippet of ["box-sizing: border-box", "min-width: 0", "max-width: 100%", "text-overflow: ellipsis"]) {
if (!css.includes(snippet)) {
throw new Error(`document form controls missing overflow guard declaration: ${snippet}`);
}
}
for (const selector of [
".document-archive-button",
".document-archive-button-preview",
".document-archive-button-download",
".document-archive-button-regenerate"
]) {
if (!css.includes(selector)) {
throw new Error(`main.css missing document archive button selector: ${selector}`);
}
}
console.log("document form components static tests passed");