|
| 1 | +import { |
| 2 | + BearerConnectionTarget, |
| 3 | + RelayConnectionTarget, |
| 4 | + SshConnectionTarget, |
| 5 | +} from "@t3tools/client-runtime/connection"; |
| 6 | +import { EnvironmentId } from "@t3tools/contracts"; |
| 7 | +import { describe, expect, it } from "vite-plus/test"; |
| 8 | + |
| 9 | +import { folderDropTarget } from "./folderDrop"; |
| 10 | + |
| 11 | +const environmentId = EnvironmentId.make("saved-local"); |
| 12 | +const base = { environmentId, label: "server" }; |
| 13 | +const savedServer = (httpBaseUrl: string, connectionId = "saved-1") => ({ |
| 14 | + target: new BearerConnectionTarget({ ...base, connectionId }), |
| 15 | + httpBaseUrl, |
| 16 | +}); |
| 17 | +const thinClient = { |
| 18 | + localEnvironmentDisabled: true, |
| 19 | + environmentId, |
| 20 | + primaryEnvironmentId: null, |
| 21 | + isDesktopRenderer: true, |
| 22 | +}; |
| 23 | + |
| 24 | +describe("folderDropTarget", () => { |
| 25 | + it.each([ |
| 26 | + [ |
| 27 | + "the bundled primary", |
| 28 | + { |
| 29 | + ...thinClient, |
| 30 | + localEnvironmentDisabled: false, |
| 31 | + primaryEnvironmentId: environmentId, |
| 32 | + connection: null, |
| 33 | + }, |
| 34 | + "local", |
| 35 | + ], |
| 36 | + [ |
| 37 | + "a saved loopback server on desktop", |
| 38 | + { ...thinClient, connection: savedServer("http://127.0.0.1:3773") }, |
| 39 | + "local", |
| 40 | + ], |
| 41 | + [ |
| 42 | + "a saved LAN server", |
| 43 | + { ...thinClient, connection: savedServer("http://192.168.1.20:3773") }, |
| 44 | + "remote", |
| 45 | + ], |
| 46 | + [ |
| 47 | + "a saved loopback server in a browser", |
| 48 | + { ...thinClient, isDesktopRenderer: false, connection: savedServer("http://localhost:3773") }, |
| 49 | + "remote", |
| 50 | + ], |
| 51 | + [ |
| 52 | + "a desktop WSL backend", |
| 53 | + { ...thinClient, connection: savedServer("http://127.0.0.1:3774", "local:wsl-ubuntu") }, |
| 54 | + "remote", |
| 55 | + ], |
| 56 | + [ |
| 57 | + "an SSH forward on loopback", |
| 58 | + { |
| 59 | + ...thinClient, |
| 60 | + connection: { |
| 61 | + target: new SshConnectionTarget({ ...base, connectionId: "ssh-1" }), |
| 62 | + httpBaseUrl: "http://127.0.0.1:41000", |
| 63 | + }, |
| 64 | + }, |
| 65 | + "remote", |
| 66 | + ], |
| 67 | + [ |
| 68 | + "a relay connection", |
| 69 | + { |
| 70 | + ...thinClient, |
| 71 | + connection: { |
| 72 | + target: new RelayConnectionTarget(base), |
| 73 | + httpBaseUrl: "https://relay.t3.codes", |
| 74 | + }, |
| 75 | + }, |
| 76 | + "remote", |
| 77 | + ], |
| 78 | + ["an unprepared connection", { ...thinClient, connection: null }, "remote"], |
| 79 | + ] as const)("targets %s", (_name, input, expected) => { |
| 80 | + expect(folderDropTarget(input)).toBe(expected); |
| 81 | + }); |
| 82 | +}); |
0 commit comments