test: 扩展DOCX全主题视觉矩阵

This commit is contained in:
SkyJourney
2026-08-03 10:23:22 +08:00
parent 28c88faabb
commit f0fff7f726
6 changed files with 440 additions and 126 deletions
@@ -0,0 +1,98 @@
import assert from "node:assert/strict";
import path from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
import {
createDocxLayoutVisualMatrixCases,
DOCX_LAYOUT_MATRIX_MARGIN_SCENARIOS,
DOCX_LAYOUT_MATRIX_ORIENTATIONS,
readBundledThemeMatrixDefinitions,
summarizeDocxLayoutVisualMatrix
} from "./docx-layout-visual-matrix-cases.mjs";
const repositoryDirectory = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
".."
);
const themesDirectory = path.join(repositoryDirectory, "themes");
function matrix() {
const themes = readBundledThemeMatrixDefinitions(themesDirectory);
const cases = createDocxLayoutVisualMatrixCases(themes);
return { themes, cases, summary: summarizeDocxLayoutVisualMatrix(themes, cases) };
}
test("生成 14×2×5 的完整 DOCX 布局视觉矩阵", () => {
const { cases, summary } = matrix();
assert.equal(summary.themeCount, 14);
assert.equal(summary.orientationCount, 2);
assert.equal(summary.marginScenarioCount, 5);
assert.equal(summary.expectedCaseCount, 140);
assert.equal(cases.length, 140);
assert.equal(new Set(cases.map((entry) => entry.id)).size, 140);
assert.deepEqual(summary.orientations, ["portrait", "landscape"]);
});
test("每套主题都覆盖两个方向和五组边距", () => {
const { themes, cases } = matrix();
for (const theme of themes) {
const themeCases = cases.filter((entry) => entry.themeId === theme.id);
assert.equal(themeCases.length, 10, theme.id);
assert.deepEqual(
[...new Set(themeCases.map((entry) => entry.orientation))],
DOCX_LAYOUT_MATRIX_ORIENTATIONS
);
assert.deepEqual(
[...new Set(themeCases.map((entry) => entry.marginScenarioId))],
DOCX_LAYOUT_MATRIX_MARGIN_SCENARIOS.map((scenario) => scenario.id)
);
}
});
test("主题默认边距始终保留 theme 模式且不写 custom 数值", () => {
const { themes, cases } = matrix();
const themeDefaultCases = cases.filter(
(entry) => entry.marginScenarioId === "theme-default"
);
assert.equal(themeDefaultCases.length, 28);
for (const entry of themeDefaultCases) {
assert.equal(entry.config.paper.marginMode, "theme");
assert.equal("margins" in entry.config.paper, false);
const theme = themes.find((candidate) => candidate.id === entry.themeId);
assert.deepEqual(entry.themeDefaultMargins, theme?.themeDefaultMargins);
}
});
test("显式边距场景全部使用 custom 模式并保留稳定数值", () => {
const { cases } = matrix();
for (const scenario of DOCX_LAYOUT_MATRIX_MARGIN_SCENARIOS.slice(1)) {
const scenarioCases = cases.filter(
(entry) => entry.marginScenarioId === scenario.id
);
assert.equal(scenarioCases.length, 28, scenario.id);
for (const entry of scenarioCases) {
assert.equal(entry.config.paper.marginMode, "custom");
assert.deepEqual(entry.config.paper.margins, scenario.margins);
}
}
});
test("四套独立封面主题扩展为 40 个严格封面场景", () => {
const { cases, summary } = matrix();
assert.equal(summary.coverThemeCount, 4);
assert.equal(summary.coverCaseCount, 40);
assert.deepEqual(
[...new Set(
cases
.filter((entry) => entry.coverPageCount === 1)
.map((entry) => entry.themeId)
)],
[
"formal-feasibility",
"tender-blind",
"tender-business-blue",
"tender-classic"
]
);
});