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

terminalLabels.test.ts

44 lines1.7 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { DEFAULT_TERMINAL_ID } from "@t3tools/contracts";
4​
5import { getTerminalLabel, nextTerminalId, resolveTerminalSessionLabel } from "./terminalLabels.ts";
6​
7describe("getTerminalLabel", () => {
8 it("uses the numeric suffix for term-* ids", () => {
9 expect(getTerminalLabel(DEFAULT_TERMINAL_ID)).toBe("Terminal 1");
10 expect(getTerminalLabel("term-2")).toBe("Terminal 2");
11 expect(getTerminalLabel("term-12")).toBe("Terminal 12");
12 expect(getTerminalLabel("terminal-3")).toBe("Terminal 3");
13 });
14​
15 it("falls back to the raw id for unknown shapes", () => {
16 expect(getTerminalLabel("custom-session")).toBe("custom-session");
17 });
18});
19​
20describe("resolveTerminalSessionLabel", () => {
21 it("prefers a non-empty summary label", () => {
22 expect(resolveTerminalSessionLabel("term-1", { label: " bun " })).toBe("bun");
23 });
24​
25 it("falls back to getTerminalLabel when summary is missing or blank", () => {
26 expect(resolveTerminalSessionLabel(DEFAULT_TERMINAL_ID, { label: " " })).toBe("Terminal 1");
27 expect(resolveTerminalSessionLabel(DEFAULT_TERMINAL_ID, null)).toBe("Terminal 1");
28 expect(resolveTerminalSessionLabel("term-2", undefined)).toBe("Terminal 2");
29 });
30});
31​
32describe("nextTerminalId", () => {
33 it.each([
34 [[], DEFAULT_TERMINAL_ID],
35 [[DEFAULT_TERMINAL_ID], "term-2"],
36 [[DEFAULT_TERMINAL_ID, "term-2", "term-3"], "term-4"],
37 [[DEFAULT_TERMINAL_ID, "term-3"], "term-2"],
38 [["term-2", "term-3"], "term-1"],
39 [["", " ", DEFAULT_TERMINAL_ID], "term-2"],
40 [["", " "], "term-1"],
41 ])("allocates the lowest unused id for %j: %s", (existingIds, expected) => {
42 expect(nextTerminalId(existingIds)).toBe(expected);
43 });
44});