| 1 | import assert from "node:assert/strict"; |
| 2 | import React, { act } from "react"; |
| 3 | import { createRoot } from "react-dom/client"; |
| 4 | import { JSDOM } from "jsdom"; |
| 5 | import { useOnboardingCommands } from "../app-runtime/useOnboardingCommands"; |
| 6 | import { useOverlayStore } from "../store/overlays"; |
| 7 | import { useAppNavigationStore } from "../store/appNavigation"; |
| 8 | import { onboardingWasDismissed } from "../lib/onboarding"; |
| 9 | |
| 10 | const dom = new JSDOM("<div id='root'></div>", { url: "http://localhost" }); |
| 11 | Object.assign(globalThis, { window: dom.window, document: dom.window.document, |
| 12 | localStorage: dom.window.localStorage, IS_REACT_ACT_ENVIRONMENT: true }); |
| 13 | const root = createRoot(document.getElementById("root")!); |
| 14 | let commands!: ReturnType<typeof useOnboardingCommands>; |
| 15 | let completed = 0; |
| 16 | function Probe() { commands = useOnboardingCommands(() => { completed++; }); return null; } |
| 17 | await act(async () => root.render(<Probe />)); |
| 18 | commands.chooseOnboardingProvider(); |
| 19 | assert.deepEqual(useAppNavigationStore.getState().page, { kind: "settings", tab: "providers" }); |
| 20 | assert.deepEqual(useAppNavigationStore.getState().settingsFocus, { target: "model-access", onboarding: true }); |
| 21 | assert.equal(useOverlayStore.getState().needsOnboarding, false); |
| 22 | commands.completeOnboarding(); |
| 23 | assert.equal(completed, 1); |
| 24 | commands.skipOnboarding(); |
| 25 | assert.equal(onboardingWasDismissed(), true); |
| 26 | await act(async () => root.unmount()); |
| 27 | commands.completeOnboarding(); |
| 28 | assert.equal(completed, 1, "unmounted owner cannot publish onboarding state"); |
| 29 | dom.window.close(); |
| 30 | console.log("onboarding commands: model access, completion, dismissal and disposal passed"); |
| 31 |