Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

previewViewportReadiness.test.ts

72 lines2.2 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { browserViewportSettingKey } from "~/browser/browserViewportLayout";
4​
5import { isPreviewViewportReady } from "./previewViewportReadiness";
6​
7describe("isPreviewViewportReady", () => {
8 const landscape = {
9 _tag: "preset",
10 width: 844,
11 height: 390,
12 presetId: "iphone-12-pro",
13 } as const;
14​
15 it("rejects a stale same-mode preset while React applies the requested orientation", () => {
16 expect(
17 isPreviewViewportReady({
18 setting: landscape,
19 appliedSettingKey: "preset:390:844:iphone-12-pro",
20 declaredViewport: { width: 390, height: 844 },
21 renderedViewport: { width: 390, height: 844 },
22 }),
23 ).toBe(false);
24 });
25​
26 it("requires both the declaration and guest viewport to match a fixed request", () => {
27 const appliedSettingKey = browserViewportSettingKey(landscape);
28 expect(
29 isPreviewViewportReady({
30 setting: landscape,
31 appliedSettingKey,
32 declaredViewport: { width: 390, height: 844 },
33 renderedViewport: { width: 844, height: 390 },
34 }),
35 ).toBe(false);
36 expect(
37 isPreviewViewportReady({
38 setting: landscape,
39 appliedSettingKey,
40 declaredViewport: { width: 844, height: 390 },
41 renderedViewport: { width: 844, height: 390 },
42 }),
43 ).toBe(true);
44 });
45​
46 it("allows one pixel of Electron rounding tolerance in every mode", () => {
47 expect(
48 isPreviewViewportReady({
49 setting: { _tag: "fill" },
50 appliedSettingKey: "fill",
51 declaredViewport: { width: 500, height: 700 },
52 renderedViewport: { width: 501, height: 699 },
53 }),
54 ).toBe(true);
55 expect(
56 isPreviewViewportReady({
57 setting: landscape,
58 appliedSettingKey: browserViewportSettingKey(landscape),
59 declaredViewport: { width: 844, height: 390 },
60 renderedViewport: { width: 845, height: 389 },
61 }),
62 ).toBe(true);
63 expect(
64 isPreviewViewportReady({
65 setting: landscape,
66 appliedSettingKey: browserViewportSettingKey(landscape),
67 declaredViewport: { width: 844, height: 390 },
68 renderedViewport: { width: 846, height: 390 },
69 }),
70 ).toBe(false);
71 });
72});