1import { FolderClosedIcon } from "lucide-react";
2import { FileExplorerIcon, FinderIcon } from "../Icons";
3import { resolveOpenInOptions } from "./OpenInPicker";
4import { EnvironmentId } from "@t3tools/contracts";
5import { describe, expect, it } from "vite-plus/test";
6
7import { shouldShowOpenInPicker } from "./OpenInPicker.logic";
8
9describe("shouldShowOpenInPicker", () => {
10 const primaryEnvironmentId = EnvironmentId.make("environment-primary");
11
12 it("shows the picker for projects in the primary environment", () => {
13 expect(
14 shouldShowOpenInPicker({
15 activeProjectName: "codething-mvp",
16 activeThreadEnvironmentId: primaryEnvironmentId,
17 primaryEnvironmentId,
18 remoteOpenMode: "local-exec",
19 }),
20 ).toBe(true);
21 });
22
23 it("shows the picker for remote environments in deep-link mode", () => {
24 expect(
25 shouldShowOpenInPicker({
26 activeProjectName: "codething-mvp",
27 activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
28 primaryEnvironmentId,
29 remoteOpenMode: "remote-links",
30 }),
31 ).toBe(true);
32 });
33
34 it("shows the picker's unavailable state for remote environments without an SSH route", () => {
35 expect(
36 shouldShowOpenInPicker({
37 activeProjectName: "codething-mvp",
38 activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
39 primaryEnvironmentId: null,
40 remoteOpenMode: "remote-unavailable",
41 }),
42 ).toBe(true);
43 });
44
45 it("hides the picker for non-primary local backends", () => {
46 expect(
47 shouldShowOpenInPicker({
48 activeProjectName: "codething-mvp",
49 activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
50 primaryEnvironmentId,
51 remoteOpenMode: "local-exec",
52 }),
53 ).toBe(false);
54 });
55
56 it("hides the picker when there is no active project", () => {
57 expect(
58 shouldShowOpenInPicker({
59 activeProjectName: undefined,
60 activeThreadEnvironmentId: primaryEnvironmentId,
61 primaryEnvironmentId,
62 remoteOpenMode: "remote-links",
63 }),
64 ).toBe(false);
65 });
66});
67
68describe("resolveOpenInOptions", () => {
69 it.each([
70 ["MacIntel", "Finder", FinderIcon],
71 ["Win32", "File Explorer", FileExplorerIcon],
72 ["Linux x86_64", "Files", FolderClosedIcon],
73 ] as const)("includes the file manager with its icon on %s", (platform, label, Icon) => {
74 expect(resolveOpenInOptions(platform, ["cursor", "vscode", "file-manager"])).toEqual([
75 expect.objectContaining({ value: "cursor", label: "Cursor" }),
76 expect.objectContaining({ value: "vscode", label: "VS Code" }),
77 expect.objectContaining({ value: "file-manager", label, Icon }),
78 ]);
79 });
80
81 it("omits the file manager when unavailable or using remote editors", () => {
82 expect(resolveOpenInOptions("MacIntel", ["vscode"])).toEqual([
83 expect.objectContaining({ value: "vscode" }),
84 ]);
85 expect(resolveOpenInOptions("MacIntel", [])).toEqual([]);
86 });
87});