The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { assert, it } from "@effect/vitest"; |
| 2 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as FileSystem from "effect/FileSystem"; |
| 5 | import * as Path from "effect/Path"; |
| 6 | import { vi } from "vite-plus/test"; |
| 7 | |
| 8 | const { startDrag, getFileIcon } = vi.hoisted(() => ({ |
| 9 | startDrag: vi.fn(), |
| 10 | getFileIcon: vi.fn(async () => "file-icon"), |
| 11 | })); |
| 12 | vi.mock("electron", () => ({ app: { getFileIcon } })); |
| 13 | |
| 14 | import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts"; |
| 15 | import * as ElectronWindow from "../../electron/ElectronWindow.ts"; |
| 16 | import { startFileDrag } from "./fileDrag.ts"; |
| 17 | |
| 18 | it.effect("only drags existing absolute paths from the host environment and app window", () => |
| 19 | Effect.gen(function* () { |
| 20 | startDrag.mockClear(); |
| 21 | getFileIcon.mockClear(); |
| 22 | const fs = yield* FileSystem.FileSystem; |
| 23 | const path = yield* Path.Path; |
| 24 | const stateDir = yield* fs.makeTempDirectoryScoped(); |
| 25 | const filePath = path.join(stateDir, "file with spaces.txt"); |
| 26 | yield* fs.writeFileString(filePath, "file"); |
| 27 | yield* fs.writeFileString(path.join(stateDir, "environment-id"), "host\n"); |
| 28 | const run = (environmentId: string, target: string, platform = "darwin", sender = 1) => |
| 29 | startFileDrag.handler({ environmentId, path: target }, { sender: { id: sender } }).pipe( |
| 30 | Effect.provideService(DesktopEnvironment.DesktopEnvironment, { |
| 31 | path, |
| 32 | stateDir, |
| 33 | platform, |
| 34 | } as DesktopEnvironment.DesktopEnvironment["Service"]), |
| 35 | Effect.provideService(ElectronWindow.ElectronWindow, { |
| 36 | main: Effect.succeedSome({ webContents: { id: 1, startDrag } }), |
| 37 | } as unknown as ElectronWindow.ElectronWindow["Service"]), |
| 38 | ); |
| 39 | assert.isFalse(yield* run("remote", filePath)); |
| 40 | assert.isFalse(yield* run("host", "relative.txt")); |
| 41 | assert.isFalse(yield* run("host", `${filePath}:12`)); |
| 42 | assert.isFalse(yield* run("host", filePath, "linux")); |
| 43 | assert.isFalse(yield* run("host", filePath, "darwin", 2)); |
| 44 | assert.strictEqual(startDrag.mock.calls.length, 0); |
| 45 | assert.isTrue(yield* run("host", filePath)); |
| 46 | assert.isTrue(yield* run("host", filePath, "win32")); |
| 47 | assert.deepEqual(startDrag.mock.calls, [ |
| 48 | [{ file: filePath, icon: "file-icon" }], |
| 49 | [{ file: filePath, icon: "file-icon" }], |
| 50 | ]); |
| 51 | yield* fs.remove(path.join(stateDir, "environment-id")); |
| 52 | assert.isFalse(yield* run("host", filePath)); |
| 53 | assert.strictEqual(startDrag.mock.calls.length, 2); |
| 54 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 55 | ); |