Open History to see the last commit
1import { afterEach, describe, expect, it } from "vite-plus/test";
2import type { ThreadId } from "@t3tools/contracts";
3
4import { resolveFocusedSideChat, useSideChatFocusStore } from "./sideChatStore";
5
6const parentKey = "env:parent";
7const first = "first" as ThreadId;
8const second = "second" as ThreadId;
9
10const focused = () => useSideChatFocusStore.getState().byParent[parentKey];
11const aside = (threadId: string) => ({
12 id: `aside:${threadId}` as const,
13 kind: "aside" as const,
14 threadId,
15});
16
17afterEach(() => {
18 useSideChatFocusStore.setState({ byParent: {} });
19});
20
21describe("side chat focus", () => {
22 it("releases only the side chat that still has the composer", () => {
23 const { focus, release } = useSideChatFocusStore.getState();
24 focus(parentKey, first);
25 focus(parentKey, second);
26
27 release(parentKey, first);
28 expect(focused()).toBe(second);
29
30 release(parentKey);
31 expect(focused()).toBeUndefined();
32 });
33
34 it("counts only while the side chat's tab is the open panel's active one", () => {
35 const resolve = (input: Partial<Parameters<typeof resolveFocusedSideChat>[0]>) =>
36 resolveFocusedSideChat({
37 picked: first,
38 panelOpen: true,
39 activeSurface: aside(first),
40 ...input,
41 });
42
43 expect(resolve({})).toBe(first);
44 expect(resolve({ panelOpen: false })).toBeNull();
45 expect(resolve({ activeSurface: aside(second) })).toBeNull();
46 expect(resolve({ activeSurface: { id: "diff", kind: "diff" } })).toBeNull();
47 expect(resolve({ activeSurface: null })).toBeNull();
48 expect(resolve({ picked: null })).toBeNull();
49 });
50});