Open History to see the last commit
1import type { EnvironmentId, T3ProjectFileScript, ThreadId } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
4
5const testState = vi.hoisted(() => ({
6 useT3ProjectFileScripts: vi.fn(),
7 projectScriptsControl: vi.fn(),
8}));
9
10vi.mock("../../hooks/useT3ProjectFileScripts", () => ({
11 useT3ProjectFileScripts: (...args: ReadonlyArray<unknown>) =>
12 testState.useT3ProjectFileScripts(...args),
13}));
14vi.mock("../BranchToolbar", () => ({
15 BranchToolbar: () => null,
16}));
17vi.mock("../ProjectScriptsControl", () => ({
18 default: (props: unknown) => {
19 testState.projectScriptsControl(props);
20 return null;
21 },
22}));
23vi.mock("./ThreadAutomationsPanel", () => ({
24 ThreadAutomationsPanel: () => null,
25}));
26vi.mock("./ThreadRelationshipsControl", () => ({
27 ThreadRelationshipsPanel: () => null,
28}));
29
30import { ThreadDetailsPanel, type ThreadDetailsPanelProps } from "./ThreadDetailsPanel";
31
32describe("ThreadDetailsPanel", () => {
33 beforeEach(() => {
34 testState.useT3ProjectFileScripts.mockReset();
35 testState.projectScriptsControl.mockReset();
36 });
37
38 it("passes checked-in t3.json scripts to the project scripts control", () => {
39 const environmentId = "environment:thread-details" as EnvironmentId;
40 const gitCwd = "/tmp/thread-details-project";
41 const fileScripts = [
42 {
43 name: "Check project",
44 command: "vp check",
45 icon: "test",
46 },
47 ] satisfies ReadonlyArray<T3ProjectFileScript>;
48 testState.useT3ProjectFileScripts.mockReturnValue(fileScripts);
49
50 const props: ThreadDetailsPanelProps = {
51 mode: "popover",
52 environmentId,
53 environmentConnection: null,
54 threadId: "thread:thread-details" as ThreadId,
55 activeProjectName: undefined,
56 activeProjectScripts: [],
57 preferredScriptId: null,
58 keybindings: [],
59 availableEditors: [],
60 showOpenInPicker: false,
61 gitCwd,
62 isGitRepo: false,
63 envLocked: false,
64 availableEnvironments: [],
65 onEnvironmentChange: vi.fn(),
66 onEnvModeChange: vi.fn(),
67 startFromOrigin: false,
68 onStartFromOriginChange: vi.fn(),
69 onComposerFocusRequest: vi.fn(),
70 onReconnectEnvironment: vi.fn(),
71 onOpenConnectionSettings: vi.fn(),
72 versionMismatch: null,
73 onDismissVersionMismatch: vi.fn(),
74 onRunProjectScript: vi.fn(),
75 onAddProjectScript: vi.fn() as ThreadDetailsPanelProps["onAddProjectScript"],
76 onUpdateProjectScript: vi.fn() as ThreadDetailsPanelProps["onUpdateProjectScript"],
77 onDeleteProjectScript: vi.fn() as ThreadDetailsPanelProps["onDeleteProjectScript"],
78 };
79
80 renderToStaticMarkup(<ThreadDetailsPanel {...props} />);
81
82 expect(testState.useT3ProjectFileScripts).toHaveBeenCalledWith(environmentId, gitCwd);
83 expect(testState.projectScriptsControl).toHaveBeenCalledWith(
84 expect.objectContaining({
85 displayMode: "panel",
86 scripts: [],
87 fileScripts,
88 }),
89 );
90 });
91});