Repository navigation
Expand file tree
/
Copy pathcalibration.test.ts
More file actions
58 lines (53 loc) · 1.94 KB
/
Copy pathcalibration.test.ts
File metadata and controls
58 lines (53 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// @vitest-environment jsdom
import { describe, expect, it } from "vitest";
import { drawCalibrationPattern } from "./calibration";
type Rectangle = {
style: string;
args: [number, number, number, number];
};
describe("G2 maximum-boundary calibration", () => {
it("draws exact outer, inset, and center boundaries on a 576 by 288 canvas", () => {
const rectangles: Rectangle[] = [];
const labels: string[] = [];
let fillStyle = "";
const context = {
get fillStyle() {
return fillStyle;
},
set fillStyle(value: string | CanvasGradient | CanvasPattern) {
fillStyle = String(value);
},
font: "",
textAlign: "start",
textBaseline: "alphabetic",
fillRect: (x: number, y: number, width: number, height: number) => {
rectangles.push({ style: fillStyle, args: [x, y, width, height] });
},
fillText: (value: string) => labels.push(value),
};
const canvas = {
width: 0,
height: 0,
getContext: () => context,
} as unknown as HTMLCanvasElement;
drawCalibrationPattern(canvas);
expect(canvas.width).toBe(576);
expect(canvas.height).toBe(288);
expect(rectangles).toEqual(expect.arrayContaining([
{ style: "#000000", args: [0, 0, 576, 288] },
{ style: "#ffffff", args: [0, 0, 576, 4] },
{ style: "#ffffff", args: [0, 284, 576, 4] },
{ style: "#ffffff", args: [0, 0, 4, 288] },
{ style: "#ffffff", args: [572, 0, 4, 288] },
{ style: "#ffffff", args: [8, 8, 560, 2] },
{ style: "#ffffff", args: [8, 278, 560, 2] },
{ style: "#ffffff", args: [8, 8, 2, 272] },
{ style: "#ffffff", args: [566, 8, 2, 272] },
{ style: "#ffffff", args: [287, 0, 2, 288] },
{ style: "#ffffff", args: [0, 143, 576, 2] },
{ style: "#ffffff", args: [32, 4, 2, 12] },
{ style: "#ffffff", args: [4, 32, 12, 2] },
]));
expect(labels).toEqual(["TL", "TR", "BL", "BR", "576×288 MAX"]);
});
});