Open History to see the last commit
1import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3import { beforeEach, describe, expect, it } from "vite-plus/test";
4
5import {
6 selectThreadDiffPanelSelection,
7 useDiffPanelSessionStore,
8 useDiffPanelStore,
9} from "./diffPanelStore";
10
11const THREAD_REF = scopeThreadRef(EnvironmentId.make("environment-1"), ThreadId.make("thread-1"));
12
13describe("diffPanelStore", () => {
14 beforeEach(() => {
15 useDiffPanelStore.setState({
16 byThreadKey: {},
17 branchBaseRefByThreadKey: {},
18 repositoryByThreadKey: {},
19 });
20 useDiffPanelSessionStore.setState({ collapsedFileKeysByScopeKey: {} });
21 });
22
23 it("retains fold choices when a panel consumer returns with fresh defaults", () => {
24 const scopeKey = "environment-1:thread-1:branch";
25 const defaults = new Set(["src/app.ts", "src/index.ts"]);
26 useDiffPanelSessionStore.getState().updateCollapsedFileKeys(scopeKey, defaults, (current) => {
27 const next = new Set(current);
28 next.delete("src/app.ts");
29 return next;
30 });
31
32 expect(useDiffPanelSessionStore.getState().collapsedFileKeysByScopeKey[scopeKey]).toEqual(
33 new Set(["src/index.ts"]),
34 );
35
36 useDiffPanelSessionStore.getState().updateCollapsedFileKeys(scopeKey, new Set(), (current) => {
37 const next = new Set(current);
38 next.delete("src/index.ts");
39 return next;
40 });
41 expect(useDiffPanelSessionStore.getState().collapsedFileKeysByScopeKey[scopeKey]).toEqual(
42 new Set(),
43 );
44
45 useDiffPanelSessionStore
46 .getState()
47 .updateCollapsedFileKeys(scopeKey, defaults, (current) => current);
48 expect(useDiffPanelSessionStore.getState().collapsedFileKeysByScopeKey[scopeKey]).toEqual(
49 new Set(),
50 );
51 expect(defaults).toEqual(new Set(["src/app.ts", "src/index.ts"]));
52 });
53
54 it("goes back to the automatic base when switching repositories", () => {
55 useDiffPanelStore.getState().selectRepository(THREAD_REF, "api");
56 useDiffPanelStore.getState().selectBranchBaseRef(THREAD_REF, "origin/develop");
57 useDiffPanelStore.getState().selectRepository(THREAD_REF, "api");
58 expect(
59 selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF),
60 ).toEqual({ kind: "branch", baseRef: "origin/develop" });
61
62 useDiffPanelStore.getState().selectRepository(THREAD_REF, "web");
63 expect(
64 selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF),
65 ).toEqual({ kind: "branch", baseRef: null });
66 });
67});