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

providerInstanceDisplay.test.ts

108 lines3.5 KB

1import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 normalizeProviderAccentColor,
6 providerInstanceInitials,
7 resolveProviderInstanceDisplayName,
8 shouldShowInstanceBadge,
9} from "./providerInstanceDisplay.ts";
10​
11const codex = ProviderDriverKind.make("codex");
12const claude = ProviderDriverKind.make("claudeAgent");
13​
14describe("resolveProviderInstanceDisplayName", () => {
15 it("keeps a snapshot name that differs from the brand label", () => {
16 expect(
17 resolveProviderInstanceDisplayName({
18 instanceId: ProviderInstanceId.make("codex"),
19 driver: codex,
20 displayName: "Work",
21 }),
22 ).toBe("Work");
23 });
24​
25 it("humanizes a custom instance id when the snapshot only carries the brand label", () => {
26 expect(
27 resolveProviderInstanceDisplayName({
28 instanceId: ProviderInstanceId.make("codex_personal"),
29 driver: codex,
30 displayName: "Codex",
31 }),
32 ).toBe("Codex Personal");
33 });
34​
35 it("uses the brand label for the default instance", () => {
36 expect(
37 resolveProviderInstanceDisplayName({
38 instanceId: ProviderInstanceId.make("codex"),
39 driver: codex,
40 }),
41 ).toBe("Codex");
42 });
43});
44​
45describe("providerInstanceInitials", () => {
46 it("takes the first two characters of a single word", () => {
47 expect(providerInstanceInitials("Codex")).toBe("CO");
48 });
49​
50 it("takes the first character of each of the first two words", () => {
51 expect(providerInstanceInitials("Codex Personal")).toBe("CP");
52 });
53​
54 it("ignores words past the first two", () => {
55 expect(providerInstanceInitials("Codex Personal Backup Account")).toBe("CP");
56 });
57​
58 it("returns an empty string for an empty label", () => {
59 expect(providerInstanceInitials("")).toBe("");
60 });
61​
62 it("keeps an emoji whole instead of splitting its surrogate pair", () => {
63 expect(providerInstanceInitials("😀 Work")).toBe("😀W");
64 expect(providerInstanceInitials("😀")).toBe("😀");
65 });
66});
67​
68describe("normalizeProviderAccentColor", () => {
69 it("accepts a lowercase hex color", () => {
70 expect(normalizeProviderAccentColor("#ff8800")).toBe("#ff8800");
71 });
72​
73 it("accepts an uppercase hex color", () => {
74 expect(normalizeProviderAccentColor("#FF8800")).toBe("#FF8800");
75 });
76​
77 it("rejects a non-hex value", () => {
78 expect(normalizeProviderAccentColor("blue")).toBeUndefined();
79 });
80​
81 it("rejects a short hex value", () => {
82 expect(normalizeProviderAccentColor("#fff")).toBeUndefined();
83 });
84​
85 it("treats undefined and blank as unset", () => {
86 expect(normalizeProviderAccentColor(undefined)).toBeUndefined();
87 expect(normalizeProviderAccentColor(" ")).toBeUndefined();
88 });
89});
90​
91describe("shouldShowInstanceBadge", () => {
92 it("shows the badge when the entry has an accent color", () => {
93 const entry = { driverKind: codex, accentColor: "#ff8800" };
94 expect(shouldShowInstanceBadge(entry, [entry])).toBe(true);
95 });
96​
97 it("shows the badge when two entries share a driver, even without an accent", () => {
98 const first = { driverKind: codex, accentColor: undefined };
99 const second = { driverKind: codex, accentColor: undefined };
100 expect(shouldShowInstanceBadge(first, [first, second])).toBe(true);
101 });
102​
103 it("hides the badge for a single instance of a driver with no accent", () => {
104 const entry = { driverKind: codex, accentColor: undefined };
105 const other = { driverKind: claude, accentColor: undefined };
106 expect(shouldShowInstanceBadge(entry, [entry, other])).toBe(false);
107 });
108});