| 1 | import { JSDOM } from "jsdom"; |
| 2 | import React from "react"; |
| 3 | import { act } from "react"; |
| 4 | import { createRoot } from "react-dom/client"; |
| 5 | import { DesktopCloseBehaviorHint } from "../components/DesktopCloseBehaviorHint"; |
| 6 | import type { AppBindings } from "../lib/bridge"; |
| 7 | import { installDesktopHostStub } from "./desktopHostStub"; |
| 8 | |
| 9 | const dom = new JSDOM("<!doctype html><html><body><div id=\"root\"></div></body></html>", { |
| 10 | pretendToBeVisual: true, |
| 11 | url: "http://localhost/", |
| 12 | }); |
| 13 | globalThis.window = dom.window as unknown as Window & typeof globalThis; |
| 14 | globalThis.document = dom.window.document; |
| 15 | globalThis.IS_REACT_ACT_ENVIRONMENT = true; |
| 16 | installDesktopHostStub(({ |
| 17 | main: { |
| 18 | App: { |
| 19 | GetDesktopShellStatus: async () => ({ |
| 20 | trayState: "unavailable", |
| 21 | backgroundCloseAvailable: false, |
| 22 | reason: "no_host", |
| 23 | }), |
| 24 | } as Partial<AppBindings> as AppBindings, |
| 25 | }, |
| 26 | }).main.App); |
| 27 | |
| 28 | const rootElement = document.getElementById("root"); |
| 29 | if (!rootElement) throw new Error("missing root"); |
| 30 | const root = createRoot(rootElement); |
| 31 | await act(async () => { |
| 32 | root.render(<DesktopCloseBehaviorHint backgroundSelected hint="Keep running after close." unavailableHint="Closing this time will quit." />); |
| 33 | await Promise.resolve(); |
| 34 | }); |
| 35 | if (rootElement.textContent !== "Keep running after close.Closing this time will quit.") { |
| 36 | throw new Error(`unexpected close fallback hint: ${JSON.stringify(rootElement.textContent)}`); |
| 37 | } |
| 38 | await act(async () => root.unmount()); |
| 39 | console.log("desktop close behavior hint: ok"); |
| 40 |