Files
t3code/apps/web/src/diffFileActions.test.ts

52 lines
1.5 KiB
TypeScript

import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
import { openDiffFilePrimaryAction } from "./diffFileActions";
import { selectThreadRightPanelState, useRightPanelStore } from "./rightPanelStore";
const THREAD_REF = scopeThreadRef(
EnvironmentId.make("environment-local"),
ThreadId.make("thread-1"),
);
describe("openDiffFilePrimaryAction", () => {
beforeEach(() => {
useRightPanelStore.setState({ byThreadKey: {} });
});
it("opens diff files in the thread file viewer", () => {
const openInEditor = vi.fn();
openDiffFilePrimaryAction({
threadRef: THREAD_REF,
filePath: "apps/web/src/components/DiffPanel.tsx",
activeCwd: "/repo/project",
openInEditor,
});
expect(
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, THREAD_REF),
).toMatchObject({
isOpen: true,
activeSurfaceId: "file:apps/web/src/components/DiffPanel.tsx",
});
expect(openInEditor).not.toHaveBeenCalled();
});
it("falls back to the editor without thread context", () => {
const openInEditor = vi.fn();
openDiffFilePrimaryAction({
threadRef: null,
filePath: "apps/web/src/components/DiffPanel.tsx",
activeCwd: "/repo/project",
openInEditor,
});
expect(openInEditor).toHaveBeenCalledWith(
"/repo/project/apps/web/src/components/DiffPanel.tsx",
);
});
});