|
1 | 1 | import { describe, expect, it, vi } from "vite-plus/test"; |
2 | | -import type { RuntimeMode } from "@t3tools/contracts"; |
| 2 | +import { EnvironmentId, ProjectId, type RuntimeMode } from "@t3tools/contracts"; |
3 | 3 | import { act, createElement } from "react"; |
4 | 4 | import { create } from "react-test-renderer"; |
5 | 5 |
|
@@ -135,6 +135,12 @@ vi.mock("@tanstack/react-router", async (importOriginal) => ({ |
135 | 135 | ...(await importOriginal<typeof import("@tanstack/react-router")>()), |
136 | 136 | useParams: () => null, |
137 | 137 | useRouter: () => testState.router, |
| 138 | + useNavigate: () => testState.router.navigate, |
| 139 | + useLocation: ({ |
| 140 | + select, |
| 141 | + }: { |
| 142 | + select: (location: { hash: string; pathname: string }) => unknown; |
| 143 | + }) => select({ hash: "", pathname: testState.router.state.location.href }), |
138 | 144 | createFileRoute: () => (options: unknown) => ({ |
139 | 145 | options, |
140 | 146 | useRouteContext: () => ({ authGateState: { status: "server" } }), |
@@ -203,6 +209,7 @@ vi.mock("../state/environments", () => ({ |
203 | 209 | useEnvironments: () => ({ environments: [], isReady: true }), |
204 | 210 | })); |
205 | 211 | vi.mock("../components/NoProjectsHero", () => ({ NoProjectsHero: () => null })); |
| 212 | +vi.mock("../components/onboarding/WelcomeWizard", () => ({ WelcomeWizard: "dialog" })); |
206 | 213 | vi.mock("../components/WorkspacePageHeader", () => ({ WorkspacePageHeader: () => null })); |
207 | 214 | vi.mock("../components/ui/button", () => ({ Button: "button" })); |
208 | 215 | vi.mock("../components/ui/sidebar", () => ({ SidebarInset: "main" })); |
@@ -248,6 +255,7 @@ vi.mock("../components/ui/toast", () => ({ |
248 | 255 | import { useNewThreadHandler } from "./useHandleNewThread"; |
249 | 256 | import * as newThread from "./useHandleNewThread"; |
250 | 257 | import { Route } from "../routes/_chat.index"; |
| 258 | +import { Route as WelcomeRoute } from "../routes/welcome"; |
251 | 259 |
|
252 | 260 | describe.each([ |
253 | 261 | ["new", null], |
@@ -469,3 +477,46 @@ it("shows the index retry action after an unavailable result and opens the same |
469 | 477 | vi.unstubAllGlobals(); |
470 | 478 | } |
471 | 479 | }); |
| 480 | + |
| 481 | +it("keeps welcome open when an imported checkout is unavailable and retries that checkout after reconnect", async () => { |
| 482 | + testState.reset(null); |
| 483 | + testState.toast.mockClear(); |
| 484 | + testState.projectFileReads.mockClear(); |
| 485 | + testState.connectionPhase = "disconnected"; |
| 486 | + testState.router.state.location.href = "/welcome"; |
| 487 | + const projectRef = { |
| 488 | + environmentId: EnvironmentId.make("environment-ssh"), |
| 489 | + projectId: ProjectId.make("project-remote"), |
| 490 | + }; |
| 491 | + const openThread = useNewThreadHandler(); |
| 492 | + const handler = vi.spyOn(newThread, "useNewThreadHandler").mockReturnValue(openThread); |
| 493 | + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); |
| 494 | + await WelcomeRoute.options.component!.preload?.(); |
| 495 | + const renderer = await act(async () => create(createElement(WelcomeRoute.options.component!))); |
| 496 | + try { |
| 497 | + const wizard = renderer.root.findByType("dialog"); |
| 498 | + await act(async () => wizard.props.onDone(projectRef)); |
| 499 | + expect(renderer.root.findByType("dialog")).toBe(wizard); |
| 500 | + expect(testState.router.state.location.href).toBe("/welcome"); |
| 501 | + expect(testState.router.navigate).not.toHaveBeenCalled(); |
| 502 | + expect(testState.projectFileReads).not.toHaveBeenCalled(); |
| 503 | + expect(testState.toast).toHaveBeenCalledWith( |
| 504 | + expect.objectContaining({ title: "Environment unavailable" }), |
| 505 | + ); |
| 506 | + testState.connectionPhase = "connected"; |
| 507 | + await act(async () => wizard.props.onDone(projectRef)); |
| 508 | + expect(testState.router.state.location.href).toBe("/draft/draft-delayed"); |
| 509 | + expect(renderer.root.findAllByType("dialog")).toHaveLength(0); |
| 510 | + expect(testState.draftStore.setLogicalProjectDraftThreadId).toHaveBeenCalledWith( |
| 511 | + "remote-project", |
| 512 | + projectRef, |
| 513 | + "draft-delayed", |
| 514 | + expect.anything(), |
| 515 | + ); |
| 516 | + } finally { |
| 517 | + await act(async () => renderer.unmount()); |
| 518 | + handler.mockRestore(); |
| 519 | + testState.connectionPhase = "connected"; |
| 520 | + vi.unstubAllGlobals(); |
| 521 | + } |
| 522 | +}); |
0 commit comments