1import { describe, expect, it } from "vite-plus/test";
2
3import { nextEnvironmentId, parseActiveThreadPath } from "./hardwareKeyboardCommands";
4
5describe("parseActiveThreadPath", () => {
6 it("extracts the active thread from thread subroutes", () => {
7 expect(parseActiveThreadPath("/threads/environment-1/thread-1/files/src/index.ts")).toEqual({
8 environmentId: "environment-1",
9 threadId: "thread-1",
10 });
11 });
12
13 it("decodes route components", () => {
14 expect(parseActiveThreadPath("/threads/local%20machine/thread%2Fone/review")).toEqual({
15 environmentId: "local machine",
16 threadId: "thread/one",
17 });
18 });
19
20 it("ignores non-thread routes", () => {
21 expect(parseActiveThreadPath("/settings")).toBeNull();
22 expect(parseActiveThreadPath("/threads/environment-only")).toBeNull();
23 });
24
25 it("ignores malformed encoded route components", () => {
26 expect(parseActiveThreadPath("/threads/%E0%A4%A/thread-1")).toBeNull();
27 });
28});
29
30describe("nextEnvironmentId", () => {
31 const environments = [{ environmentId: "a" }, { environmentId: "b" }, { environmentId: "c" }];
32
33 it.each([
34 ["the next machine", "a", "b"],
35 ["the first machine after the last", "c", "a"],
36 ["the first machine when the current one is not listed", "gone", "a"],
37 ["the first machine when there is no current one", null, "a"],
38 ])("returns %s", (_label, current, expected) => {
39 expect(nextEnvironmentId(environments, current)).toBe(expected);
40 });
41
42 it("returns null when there is nowhere else to go", () => {
43 expect(nextEnvironmentId([{ environmentId: "a" }], "a")).toBeNull();
44 });
45});