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

preview.test.ts

44 lines1.5 KB

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