feat: 完善导出设置与打印预览
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
cssPixelsToMillimeters,
|
||||
defaultExportConfig,
|
||||
exportConfigSchema,
|
||||
getPaperDimensionsMm,
|
||||
millimetersToCssPixels,
|
||||
millimetersToPdfPoints,
|
||||
paperDimensionsMm,
|
||||
supportedPaperFormats
|
||||
} from "../src/export-config.js";
|
||||
|
||||
describe("导出配置", () => {
|
||||
it("只保留五种固定纸张尺寸", () => {
|
||||
expect(supportedPaperFormats).toEqual([
|
||||
"A3",
|
||||
"A4",
|
||||
"A5",
|
||||
"Letter",
|
||||
"Legal"
|
||||
]);
|
||||
expect(paperDimensionsMm).toEqual({
|
||||
A3: { width: 297, height: 420 },
|
||||
A4: { width: 210, height: 297 },
|
||||
A5: { width: 148, height: 210 },
|
||||
Letter: { width: 216, height: 279 },
|
||||
Legal: { width: 216, height: 356 }
|
||||
});
|
||||
});
|
||||
|
||||
it("使用 A4 和 16mm 作为默认纸张配置", () => {
|
||||
expect(defaultExportConfig.paper).toEqual({
|
||||
format: "A4",
|
||||
orientation: "portrait",
|
||||
margins: {
|
||||
top: "16mm",
|
||||
right: "16mm",
|
||||
bottom: "16mm",
|
||||
left: "16mm"
|
||||
}
|
||||
});
|
||||
expect(exportConfigSchema.safeParse(defaultExportConfig).success).toBe(true);
|
||||
});
|
||||
|
||||
it("使用统一的 96 CSS px/in 和 72 PDF pt/in 换算物理尺寸", () => {
|
||||
expect(millimetersToCssPixels(25.4)).toBeCloseTo(96);
|
||||
expect(cssPixelsToMillimeters(96)).toBeCloseTo(25.4);
|
||||
expect(millimetersToCssPixels(210)).toBeCloseTo(793.700787);
|
||||
expect(millimetersToPdfPoints(210)).toBeCloseTo(595.275591);
|
||||
});
|
||||
|
||||
it("根据方向交换纸张宽高", () => {
|
||||
expect(getPaperDimensionsMm("A5", "portrait")).toEqual({
|
||||
width: 148,
|
||||
height: 210
|
||||
});
|
||||
expect(getPaperDimensionsMm("A5", "landscape")).toEqual({
|
||||
width: 210,
|
||||
height: 148
|
||||
});
|
||||
});
|
||||
|
||||
it("拒绝旧配置版本和已移除的纸张类型", () => {
|
||||
expect(
|
||||
exportConfigSchema.safeParse({
|
||||
...defaultExportConfig,
|
||||
version: 1
|
||||
}).success
|
||||
).toBe(false);
|
||||
expect(
|
||||
exportConfigSchema.safeParse({
|
||||
...defaultExportConfig,
|
||||
paper: {
|
||||
...defaultExportConfig.paper,
|
||||
format: "Tabloid"
|
||||
}
|
||||
}).success
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("拒绝没有正文可用区域的页边距", () => {
|
||||
expect(
|
||||
exportConfigSchema.safeParse({
|
||||
...defaultExportConfig,
|
||||
paper: {
|
||||
...defaultExportConfig.paper,
|
||||
margins: {
|
||||
top: "149mm",
|
||||
right: "105mm",
|
||||
bottom: "149mm",
|
||||
left: "105mm"
|
||||
}
|
||||
}
|
||||
}).success
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user