Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

diffPanelStore.test.ts

44 lines1.5 KB

1import { beforeEach, describe, expect, it } from "vite-plus/test";
2​
3import { useDiffPanelSessionStore, useDiffPanelStore } from "./diffPanelStore";
4​
5describe("diffPanelStore", () => {
6 beforeEach(() => {
7 useDiffPanelStore.setState({
8 byThreadKey: {},
9 branchBaseRefByThreadKey: {},
10 });
11 useDiffPanelSessionStore.setState({ collapsedFileKeysByScopeKey: {} });
12 });
13​
14 it("retains fold choices when a panel consumer returns with fresh defaults", () => {
15 const scopeKey = "environment-1:thread-1:branch";
16 const defaults = new Set(["src/app.ts", "src/index.ts"]);
17 useDiffPanelSessionStore.getState().updateCollapsedFileKeys(scopeKey, defaults, (current) => {
18 const next = new Set(current);
19 next.delete("src/app.ts");
20 return next;
21 });
22​
23 expect(useDiffPanelSessionStore.getState().collapsedFileKeysByScopeKey[scopeKey]).toEqual(
24 new Set(["src/index.ts"]),
25 );
26​
27 useDiffPanelSessionStore.getState().updateCollapsedFileKeys(scopeKey, new Set(), (current) => {
28 const next = new Set(current);
29 next.delete("src/index.ts");
30 return next;
31 });
32 expect(useDiffPanelSessionStore.getState().collapsedFileKeysByScopeKey[scopeKey]).toEqual(
33 new Set(),
34 );
35​
36 useDiffPanelSessionStore
37 .getState()
38 .updateCollapsedFileKeys(scopeKey, defaults, (current) => current);
39 expect(useDiffPanelSessionStore.getState().collapsedFileKeysByScopeKey[scopeKey]).toEqual(
40 new Set(),
41 );
42 expect(defaults).toEqual(new Set(["src/app.ts", "src/index.ts"]));
43 });
44});