1import { expect, it, vi } from "vite-plus/test";
2import { createCanvasFrameSink } from "./frame.ts";
3
4it("retains a borrowed frame at its native size before notifying the viewer", () => {
5 const drawImage = vi.fn();
6 const canvas = {
7 width: 300,
8 height: 150,
9 getContext: () => ({ drawImage }),
10 } as unknown as HTMLCanvasElement;
11 const source = {} as CanvasImageSource;
12 const notify = vi.fn(() => {
13 expect(canvas.width).toBe(1170);
14 expect(canvas.height).toBe(2532);
15 expect(drawImage).toHaveBeenLastCalledWith(source, 0, 0, 1170, 2532);
16 });
17 createCanvasFrameSink(canvas, notify).present(source, 1170, 2532);
18 expect(notify).toHaveBeenCalledOnce();
19});
20
21it("reports when a canvas cannot present a frame", () => {
22 const canvas = {
23 width: 300,
24 height: 150,
25 getContext: () => null,
26 } as unknown as HTMLCanvasElement;
27 const notify = vi.fn();
28 expect(createCanvasFrameSink(canvas, notify).present({} as CanvasImageSource, 1170, 2532)).toBe(
29 false,
30 );
31 expect(notify).not.toHaveBeenCalled();
32});