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, vi } from "vite-plus/test";
4
5import { openDiffFilePrimaryAction } from "./diffFileActions";
6import { selectThreadRightPanelState, useRightPanelStore } from "./rightPanelStore";
7
8const THREAD_REF = scopeThreadRef(
9 EnvironmentId.make("environment-local"),
10 ThreadId.make("thread-1"),
11);
12
13describe("openDiffFilePrimaryAction", () => {
14 beforeEach(() => {
15 useRightPanelStore.setState({ byThreadKey: {}, threadPanelVisibilityByThreadKey: {} });
16 });
17
18 it("opens diff files in the thread file viewer", () => {
19 const openInEditor = vi.fn();
20
21 openDiffFilePrimaryAction({
22 threadRef: THREAD_REF,
23 filePath: "apps/web/src/components/DiffPanel.tsx",
24 activeCwd: "/repo/project",
25 openInEditor,
26 });
27
28 expect(
29 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, THREAD_REF),
30 ).toMatchObject({
31 isOpen: true,
32 activeSurfaceId: "file:apps/web/src/components/DiffPanel.tsx",
33 });
34 expect(openInEditor).not.toHaveBeenCalled();
35 });
36
37 it("falls back to the editor without thread context", () => {
38 const openInEditor = vi.fn();
39
40 openDiffFilePrimaryAction({
41 threadRef: null,
42 filePath: "apps/web/src/components/DiffPanel.tsx",
43 activeCwd: "/repo/project",
44 openInEditor,
45 });
46
47 expect(openInEditor).toHaveBeenCalledWith(
48 "/repo/project/apps/web/src/components/DiffPanel.tsx",
49 );
50 });
51});