67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { normalizePrintConfig, PRINT_DEFAULTS } from "./config";
|
|
|
|
describe("normalizePrintConfig", () => {
|
|
test("uses defaults", () => {
|
|
expect(normalizePrintConfig()).toEqual(PRINT_DEFAULTS);
|
|
});
|
|
|
|
test("parses directive strings and clamps values", () => {
|
|
const config = normalizePrintConfig({
|
|
columns: "3",
|
|
margin: "100",
|
|
gap: "-5",
|
|
font: "20",
|
|
pageNumbers: "false",
|
|
timestamp: "true",
|
|
cutMarks: "no",
|
|
});
|
|
|
|
expect(config.columns).toBe(3);
|
|
expect(config.margin).toBe(40);
|
|
expect(config.gap).toBe(0);
|
|
expect(config.font).toBe(6);
|
|
expect(config.pageNumbers).toBe(false);
|
|
expect(config.timestamp).toBe(true);
|
|
expect(config.cutMarks).toBe(false);
|
|
});
|
|
|
|
test("clamps font to 2..6mm", () => {
|
|
expect(normalizePrintConfig({ font: "1" }).font).toBe(2);
|
|
expect(normalizePrintConfig({ font: "20" }).font).toBe(6);
|
|
});
|
|
|
|
test("clamps columns to 1..4", () => {
|
|
expect(normalizePrintConfig({ columns: "0" }).columns).toBe(1);
|
|
expect(normalizePrintConfig({ columns: "9" }).columns).toBe(4);
|
|
});
|
|
|
|
test("accepts YAML data-config numbers and booleans", () => {
|
|
const config = normalizePrintConfig({
|
|
columns: 2,
|
|
margin: 12,
|
|
gap: 6,
|
|
font: 3,
|
|
title: "规则书",
|
|
pageNumbers: true,
|
|
timestamp: true,
|
|
cutMarks: false,
|
|
});
|
|
|
|
expect(config).toEqual({
|
|
columns: 2,
|
|
margin: 12,
|
|
gap: 6,
|
|
font: 3,
|
|
title: "规则书",
|
|
pageNumbers: true,
|
|
timestamp: true,
|
|
cutMarks: false,
|
|
});
|
|
});
|
|
|
|
test("timestamp defaults to false", () => {
|
|
expect(normalizePrintConfig().timestamp).toBe(false);
|
|
expect(normalizePrintConfig({ timestamp: "false" }).timestamp).toBe(false);
|
|
});
|
|
});
|