Open History to see the last commit
1import { expect, it, vi } from "vite-plus/test";
2
3import { watchShownPage } from "./threadForkNavigation";
4
5type Route = { key: string; name: string; params?: object };
6
7const navigation = vi.hoisted(() => ({ route: undefined as Route | undefined }));
8
9vi.mock("../../lib/rootNavigation", () => ({
10 rootNavigationRef: {
11 isReady: () => navigation.route !== undefined,
12 getCurrentRoute: () => navigation.route,
13 },
14}));
15vi.mock("../../state/atom-registry", () => ({ appAtomRegistry: {} }));
16vi.mock("../../state/threads", () => ({ environmentThreadShells: {} }));
17
18const thread = (key: string, threadId: string): Route => ({
19 key,
20 name: "Thread",
21 params: { environmentId: "env", threadId },
22});
23
24it.each([
25 ["stays on the source chat", thread("detail", "source"), true],
26 ["goes back to the thread list", { key: "home", name: "Home" }, false],
27 ["opens another chat in a new card", thread("pushed", "other"), false],
28 ["picks another chat in the split-view sidebar", thread("detail", "next"), false],
29])("a response fork opens only while the user %s", (_, after, stillShown) => {
30 navigation.route = thread("detail", "source");
31 const stillOnSourcePage = watchShownPage();
32 navigation.route = after;
33 expect(stillOnSourcePage()).toBe(stillShown);
34});