| 1 | import React, { useState } from "react"; |
| 2 | import { createRoot } from "react-dom/client"; |
| 3 | import { ModelApplicationRecovery } from "../src/components/ModelApplicationRecovery"; |
| 4 | import { LocaleProvider } from "../src/lib/i18n"; |
| 5 | import type { ModelApplicationDetails } from "../src/lib/modelApplication"; |
| 6 | import type { ReasonixDesktopHost } from "../src/lib/desktopHost"; |
| 7 | import "../src/styles.css"; |
| 8 | |
| 9 | const initial: ModelApplicationDetails = { code: "model_settings_pending", runtimeIdentity: "runtime", appliedRevision: "old", desiredRevision: "new", model: "fixture/model", connectionTarget: "http://localhost:9999", blockingJobs: [{ id: "task-1", kind: "task", label: "Dependent task", status: "running" }, { id: "task-2", kind: "task", label: "Another task", status: "running" }], canUseApplied: true }; |
| 10 | const fixture = { calls: [] as unknown[][], applied: false, sends: 0 }; |
| 11 | const status = () => ({ application: fixture.applied ? "applied" : "pending", targets: [{ tabId: "tab", application: fixture.applied ? "applied" : "pending", details: initial }], issues: [], appliedCatalogs: [] }); |
| 12 | const commands: Record<string, (...args: unknown[]) => unknown> = { |
| 13 | GetModelSettingsApplication: status, |
| 14 | RetryModelSettingsApplication: () => { fixture.applied = true; return status(); }, |
| 15 | CancelModelApplicationBlockers: (...args) => { fixture.calls.push(args); }, |
| 16 | StartTurnWithModelApplication: () => {}, |
| 17 | }; |
| 18 | window.reasonixDesktop = { kind: "electron", contract: { commands: Object.keys(commands) }, native: { window: {} }, on: () => () => {}, invoke: async (method, args) => commands[method](...args) } as unknown as ReasonixDesktopHost; |
| 19 | Object.assign(window, { modelApplicationFixture: fixture }); |
| 20 | |
| 21 | function Fixture() { |
| 22 | const [details, setDetails] = useState<ModelApplicationDetails | undefined>(initial); |
| 23 | const [text, setText] = useState("Keep my unsent message and attachment"); |
| 24 | return <main style={{ maxWidth: 800, margin: 32 }}> |
| 25 | <p>Existing conversation remains here.</p> |
| 26 | <textarea aria-label="Draft" value={text} onChange={event => setText(event.target.value)} /> |
| 27 | <span data-testid="attachment">fixture.txt</span> |
| 28 | {details && <ModelApplicationRecovery tabId="tab" details={details} onChange={setDetails} blocked={false} onUseApplied={choice => { fixture.calls.push([choice]); fixture.sends++; }} />} |
| 29 | </main>; |
| 30 | } |
| 31 | createRoot(document.getElementById("root")!).render(<LocaleProvider><Fixture /></LocaleProvider>); |
| 32 |