1import { describe, expect, it } from "@effect/vitest";
2import { EnvironmentId } from "@t3tools/contracts";
3import { folderDropTarget, resolveDroppedFolderPath } from "./folderDrop";
4
5const environmentId = EnvironmentId.make("environment-1");
6
7describe("folderDropTarget", () => {
8 it("targets local when the thread is on the primary environment", () => {
9 expect(
10 folderDropTarget({
11 localEnvironmentDisabled: false,
12 environmentId,
13 primaryEnvironmentId: environmentId,
14 }),
15 ).toBe("local");
16 });
17
18 it("targets remote when Electron has no local environment", () => {
19 expect(
20 folderDropTarget({
21 localEnvironmentDisabled: true,
22 environmentId,
23 primaryEnvironmentId: environmentId,
24 }),
25 ).toBe("remote");
26 });
27
28 it("targets remote when the thread lives on another environment", () => {
29 expect(
30 folderDropTarget({
31 localEnvironmentDisabled: false,
32 environmentId: EnvironmentId.make("environment-2"),
33 primaryEnvironmentId: environmentId,
34 }),
35 ).toBe("remote");
36 });
37
38 it("targets remote when no primary environment is known", () => {
39 expect(
40 folderDropTarget({
41 localEnvironmentDisabled: false,
42 environmentId,
43 primaryEnvironmentId: null,
44 }),
45 ).toBe("remote");
46 });
47});
48
49describe("resolveDroppedFolderPath", () => {
50 it("returns the native path when the bridge provides it", () => {
51 const folder = new File([], "contracts");
52 expect(resolveDroppedFolderPath(folder, () => "/tmp/project/contracts")).toBe(
53 "/tmp/project/contracts",
54 );
55 });
56
57 it("returns null for an outside-folder drop even when the folder name matches a project directory", () => {
58 const folder = new File([], "contracts");
59 expect(resolveDroppedFolderPath(folder, undefined)).toBeNull();
60 });
61
62 it("returns null when the bridge returns an empty path", () => {
63 const folder = new File([], "contracts");
64 expect(resolveDroppedFolderPath(folder, () => "")).toBeNull();
65 });
66});