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

preview.test.ts

55 lines1.8 KB

1import { Schema } from "effect";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 PreviewAutomationHost,
6 PreviewAutomationOpenInput,
7 PreviewAutomationStatus,
8} from "./previewAutomation.ts";
9​
10const decodeOpenInput = Schema.decodeUnknownSync(PreviewAutomationOpenInput);
11const decodeAutomationHost = Schema.decodeUnknownSync(PreviewAutomationHost);
12const decodeAutomationStatus = Schema.decodeUnknownSync(PreviewAutomationStatus);
13​
14describe("PreviewAutomationOpenInput", () => {
15 it("retains the legacy show visibility alias", () => {
16 expect(decodeOpenInput({ show: false })).toEqual({ show: false });
17 });
18});
19​
20describe("PreviewAutomationHost", () => {
21 it("accepts legacy hosts and current operation advertisements", () => {
22 expect(decodeAutomationHost({ clientId: "legacy", environmentId: "environment-1" })).toEqual({
23 clientId: "legacy",
24 environmentId: "environment-1",
25 });
26 expect(
27 decodeAutomationHost({
28 clientId: "current",
29 environmentId: "environment-1",
30 supportedOperations: ["status", "resize"],
31 }).supportedOperations,
32 ).toEqual(["status", "resize"]);
33 });
34});
35​
36describe("PreviewAutomationStatus", () => {
37 it("accepts old hosts without viewport data and exposes it from current hosts", () => {
38 const base = {
39 available: true,
40 visible: false,
41 tabId: "preview-t",
42 url: "https://example.com",
43 title: "Example",
44 loading: false,
45 };
46 expect(decodeAutomationStatus(base)).toEqual(base);
47 expect(
48 decodeAutomationStatus({
49 ...base,
50 viewportSetting: { _tag: "preset", presetId: "pixel-8", width: 412, height: 915 },
51 viewport: { width: 412, height: 915 },
52 }).viewport,
53 ).toEqual({ width: 412, height: 915 });
54 });
55});