Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

terminalLabels.test.ts

53 lines2.1 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import type { TerminalSummary } from "@t3tools/contracts";
4import { DEFAULT_TERMINAL_ID } from "@t3tools/contracts";
5​
6import { getTerminalLabel, nextTerminalId, resolveTerminalSessionLabel } from "./terminalLabels.ts";
7​
8describe("getTerminalLabel", () => {
9 it("uses the numeric suffix for term-* ids", () => {
10 expect(getTerminalLabel(DEFAULT_TERMINAL_ID)).toBe("Terminal 1");
11 expect(getTerminalLabel("term-2")).toBe("Terminal 2");
12 expect(getTerminalLabel("term-12")).toBe("Terminal 12");
13 expect(getTerminalLabel("terminal-3")).toBe("Terminal 3");
14 });
15​
16 it("falls back to the raw id for unknown shapes", () => {
17 expect(getTerminalLabel("custom-session")).toBe("custom-session");
18 });
19});
20​
21describe("resolveTerminalSessionLabel", () => {
22 it("prefers a non-empty summary label", () => {
23 const summary = { label: " bun " } as Pick<TerminalSummary, "label">;
24 expect(resolveTerminalSessionLabel("term-1", summary)).toBe("bun");
25 });
26​
27 it("falls back to getTerminalLabel when summary is missing or blank", () => {
28 expect(resolveTerminalSessionLabel(DEFAULT_TERMINAL_ID, { label: " " })).toBe("Terminal 1");
29 expect(resolveTerminalSessionLabel(DEFAULT_TERMINAL_ID, null)).toBe("Terminal 1");
30 expect(resolveTerminalSessionLabel("term-2", undefined)).toBe("Terminal 2");
31 });
32});
33​
34describe("nextTerminalId", () => {
35 it("allocates term-1 when no terminals are listed yet", () => {
36 expect(nextTerminalId([])).toBe(DEFAULT_TERMINAL_ID);
37 });
38​
39 it("allocates term-2 when only term-1 exists", () => {
40 expect(nextTerminalId([DEFAULT_TERMINAL_ID])).toBe("term-2");
41 });
42​
43 it("skips over taken term-N slots", () => {
44 expect(nextTerminalId([DEFAULT_TERMINAL_ID, "term-2", "term-3"])).toBe("term-4");
45 expect(nextTerminalId([DEFAULT_TERMINAL_ID, "term-3"])).toBe("term-2");
46 expect(nextTerminalId(["term-2", "term-3"])).toBe("term-1");
47 });
48​
49 it("ignores blank/whitespace-only ids", () => {
50 expect(nextTerminalId(["", " ", DEFAULT_TERMINAL_ID])).toBe("term-2");
51 expect(nextTerminalId(["", " "])).toBe("term-1");
52 });
53});