| 1 | import assert from "node:assert/strict"; |
| 2 | import { managementDom } from "../test-support/managementDom"; |
| 3 | import { installDesktopHostStub } from "./desktopHostStub"; |
| 4 | const dom = managementDom(); |
| 5 | const { default: React, act } = await import("react"); |
| 6 | const { createRoot } = await import("react-dom/client"); |
| 7 | const { LocaleProvider } = await import("../lib/i18n"); |
| 8 | const { HistoricalImportList } = await import("../components/HistoricalImportList"); |
| 9 | let imports = 0; |
| 10 | let fail = true; |
| 11 | let status = { items: [{ id: "old", title: "Retained conversation", format: "canonical", status: "available" }], running: false, paused: false, remaining: 0 }; |
| 12 | const controls: string[] = []; |
| 13 | const opened: string[] = []; |
| 14 | const host = installDesktopHostStub({ |
| 15 | ListHistoricalSessions: async () => status, |
| 16 | GetHistoricalImportStatus: async () => status, |
| 17 | ImportHistoricalSession: async () => { |
| 18 | imports++; |
| 19 | if (fail) throw new Error("source in use"); |
| 20 | return { session: { hostId: "local", sessionId: "imported" }, workspaceId: "global", generation: 2 }; |
| 21 | }, |
| 22 | StartHistoricalImport: async (ids: string[]) => { assert.deepEqual(ids, []); controls.push("start"); return status = { ...status, running: true, remaining: 1 }; }, |
| 23 | ControlHistoricalImport: async (action: string) => { controls.push(action); return status = { ...status, paused: action === "pause", running: action !== "cancel" }; }, |
| 24 | }); |
| 25 | const root = createRoot(document.getElementById("root")!); |
| 26 | await act(async () => root.render(<LocaleProvider><HistoricalImportList active onOpenSession={async ref => { opened.push(ref.sessionId); }} /></LocaleProvider>)); |
| 27 | const button = (text: string) => [...document.querySelectorAll<HTMLButtonElement>("button")].find(node => node.textContent?.trim() === text)!; |
| 28 | assert.equal(imports, 0, "listing must not import"); |
| 29 | await act(async () => button("Import and open").click()); |
| 30 | assert.deepEqual(opened, [], "failed import cannot navigate"); |
| 31 | assert.equal(document.querySelectorAll(".archived-sessions__row").length, 1, "blocked original stays visible"); |
| 32 | fail = false; |
| 33 | await act(async () => button("Import and open").click()); |
| 34 | assert.deepEqual(opened, ["imported"]); |
| 35 | await act(async () => button("Import all").click()); |
| 36 | await act(async () => button("Pause after current item").click()); |
| 37 | await act(async () => button("Continue").click()); |
| 38 | await act(async () => button("Cancel import").click()); |
| 39 | assert.deepEqual(controls, ["start", "pause", "resume", "cancel"]); |
| 40 | assert.ok(document.body.textContent?.includes("Original files are kept")); |
| 41 | await act(async () => root.unmount()); |
| 42 | host.uninstall(); dom.window.close(); |
| 43 | console.log("PASS explicit import, failure retention, open after commit and batch controls"); |
| 44 |