Open History to see the last commit
1import {
2 BearerConnectionTarget,
3 RelayConnectionTarget,
4 SshConnectionTarget,
5} from "@t3tools/client-runtime/connection";
6import { EnvironmentId } from "@t3tools/contracts";
7import { describe, expect, it } from "vite-plus/test";
8
9import { folderDropTarget } from "./folderDrop";
10
11const environmentId = EnvironmentId.make("saved-local");
12const base = { environmentId, label: "server" };
13const savedServer = (httpBaseUrl: string, connectionId = "saved-1") => ({
14 target: new BearerConnectionTarget({ ...base, connectionId }),
15 httpBaseUrl,
16});
17const thinClient = {
18 localEnvironmentDisabled: true,
19 environmentId,
20 primaryEnvironmentId: null,
21 isDesktopRenderer: true,
22};
23
24describe("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});