evOo-local/apps/web/src/lib/computer-screen.test.ts
cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

82 lines
2.5 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { loadComputerScreen } from "./computer-screen";
describe("computer screen requests", () => {
it("shows connection failures and lets a successful retry clear them", async () => {
const commit = vi.fn();
const options = {
isCurrent: () => true,
commit,
fallbackError: "Could not connect",
};
await loadComputerScreen({
...options,
load: async () => {
throw new Error("Control stream failed to start");
},
});
expect(commit).toHaveBeenLastCalledWith({
url: null,
error: "Control stream failed to start",
});
await expect(
loadComputerScreen({
...options,
load: async () => ({ url: "https://screen.example/vnc.html" }),
}),
).resolves.toBe("https://screen.example/vnc.html");
expect(commit).toHaveBeenLastCalledWith({
url: "https://screen.example/vnc.html",
error: null,
});
});
it.each(["success", "failure"])(
"ignores a stale %s after a newer screen failure",
async (outcome) => {
let finish!: (screen: { url: string | null }) => void;
let fail!: (error: Error) => void;
const deferred = new Promise<{ url: string | null }>((resolve, reject) => {
finish = resolve;
fail = reject;
});
let current = 1;
const commit = vi.fn();
const stale = loadComputerScreen({
load: () => deferred,
isCurrent: () => current === 1,
commit,
fallbackError: "Could not connect",
});
current = 2;
await loadComputerScreen({
load: async () => {
throw new Error("Latest connection failed");
},
isCurrent: () => current === 2,
commit,
fallbackError: "Could not connect",
});
if (outcome === "success") finish({ url: "https://stale.example/vnc.html" });
else fail(new Error("Stale connection failed"));
await expect(stale).resolves.toBeNull();
expect(commit).toHaveBeenCalledExactlyOnceWith({
url: null,
error: "Latest connection failed",
});
},
);
it("uses the visible fallback for errors without a message", async () => {
const commit = vi.fn();
await loadComputerScreen({
load: async () => Promise.reject(null),
isCurrent: () => true,
commit,
fallbackError: "Could not connect",
});
expect(commit).toHaveBeenCalledExactlyOnceWith({ url: null, error: "Could not connect" });
});
});