Fork Horse repository, listed by its owner. Publisher snapshot.

packages/forkhorse-gatekeeper/test/expand-fixture-main.ts

Snapshot at 34e3175

Containing directory

2,176 bytes · typescriptView raw
1import { mountSidebar } from "../src/mount.ts";
2import { mountDashboard } from "../../forkhorse-dashboard/src/dashboard.ts";
3import { stateView } from "../../forkhorse-dashboard/src/model.ts";
4import { fixtureState } from "../../forkhorse-dashboard/test/fixtures.ts";
5import "../../forkhorse-dashboard/src/styles.css";
6
7// Labeled DOM/geometry fixture. The separate opaque-frame fixture uses the built app's RPC.
8const params = new URL(location.href).searchParams;
9const root = document.getElementById("sidebar")!;
10const evidence = document.getElementById("evidence")!;
11const calls: boolean[] = [];
12let clipboard = "";
13function report() {
14  evidence.textContent = JSON.stringify({ fixture: "offline synthetic host and clipboard", calls, clipboard });
15}
16Object.defineProperty(navigator, "clipboard", { configurable: true, value: {
17  async writeText(text: string) {
18    if (params.get("clipboard") === "denied") throw new Error("Fixture clipboard denial");
19    clipboard = text;
20    report();
21  },
22} });
23const options = {
24  brand: { name: "Fixture product", tagline: "Fixture collaboration" },
25  project: "demo", coreOrigin: "https://core.fixture.idiot.tax", fixture: true,
26  openPrompt: async () => {},
27  setPresenting: params.get("presentation") === "off" ? undefined : async (active: boolean) => {
28    calls.push(active);
29    report();
30    if (active && params.get("presentation") === "reject") throw new Error("Fixture host rejection");
31    const rect = root.getBoundingClientRect().toJSON();
32    root.style.cssText = active ? "position:fixed;inset:0;overflow:auto;z-index:10" : "";
33    return { rect: active ? rect : null, willResize: true };
34  },
35  transport: {
36    getState: async () => stateView(fixtureState()),
37    getActivity: async () => ({ activity: [], nextAfter: 0 }),
38    approve: async () => { throw new Error("Fixture forbids writes"); },
39    promote: async () => { throw new Error("Fixture forbids writes"); },
40  },
41};
42const view = params.get("role") === "owner"
43  ? mountDashboard(root, { ...options, owner: true, initialProject: "demo" })
44  : mountSidebar(root, options);
45report();
46window.addEventListener("pagehide", () => view.dispose(), { once: true });
47