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

providerInstanceDisplay.test.ts

158 lines5.7 KB

1import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 normalizeProviderAccentColor,
6 providerAccentForegroundColor,
7 providerInstanceInitials,
8 resolveProviderInstanceDisplayName,
9 shouldShowInstanceBadge,
10} from "./providerInstanceDisplay.ts";
11​
12const codex = ProviderDriverKind.make("codex");
13const claude = ProviderDriverKind.make("claudeAgent");
14const acpRegistry = ProviderDriverKind.make("acpRegistry");
15​
16describe("resolveProviderInstanceDisplayName", () => {
17 it("keeps a snapshot name that differs from the brand label", () => {
18 expect(
19 resolveProviderInstanceDisplayName({
20 instanceId: ProviderInstanceId.make("codex"),
21 driver: codex,
22 displayName: "Work",
23 }),
24 ).toBe("Work");
25 });
26​
27 it("humanizes a custom instance id when the snapshot only carries the brand label", () => {
28 expect(
29 resolveProviderInstanceDisplayName({
30 instanceId: ProviderInstanceId.make("codex_personal"),
31 driver: codex,
32 displayName: "Codex",
33 }),
34 ).toBe("Codex Personal");
35 });
36​
37 it("uses the brand label for the default instance", () => {
38 expect(
39 resolveProviderInstanceDisplayName({
40 instanceId: ProviderInstanceId.make("codex"),
41 driver: codex,
42 }),
43 ).toBe("Codex");
44 });
45});
46​
47describe("providerInstanceInitials", () => {
48 it("takes the first two characters of a single word", () => {
49 expect(providerInstanceInitials("Codex")).toBe("CO");
50 });
51​
52 it("takes the first character of each of the first two words", () => {
53 expect(providerInstanceInitials("Codex Personal")).toBe("CP");
54 });
55​
56 it("ignores words past the first two", () => {
57 expect(providerInstanceInitials("Codex Personal Backup Account")).toBe("CP");
58 });
59​
60 it("returns an empty string for an empty label", () => {
61 expect(providerInstanceInitials("")).toBe("");
62 });
63​
64 it("keeps an emoji whole instead of splitting its surrogate pair", () => {
65 expect(providerInstanceInitials("😀 Work")).toBe("😀W");
66 expect(providerInstanceInitials("😀")).toBe("😀");
67 });
68});
69​
70describe("normalizeProviderAccentColor", () => {
71 it("accepts a lowercase hex color", () => {
72 expect(normalizeProviderAccentColor("#ff8800")).toBe("#ff8800");
73 });
74​
75 it("accepts an uppercase hex color", () => {
76 expect(normalizeProviderAccentColor("#FF8800")).toBe("#FF8800");
77 });
78​
79 it("rejects a non-hex value", () => {
80 expect(normalizeProviderAccentColor("blue")).toBeUndefined();
81 });
82​
83 it("rejects a short hex value", () => {
84 expect(normalizeProviderAccentColor("#fff")).toBeUndefined();
85 });
86​
87 it("treats undefined and blank as unset", () => {
88 expect(normalizeProviderAccentColor(undefined)).toBeUndefined();
89 expect(normalizeProviderAccentColor(" ")).toBeUndefined();
90 });
91});
92​
93describe("providerAccentForegroundColor", () => {
94 it.each([
95 ["#b5f23d", "#000000"],
96 ["#2563eb", "#ffffff"],
97 ["#777777", "#000000"],
98 ])("chooses the higher WCAG contrast foreground for %s", (accent, foreground) => {
99 expect(providerAccentForegroundColor(accent)).toBe(foreground);
100 });
101});
102​
103describe("shouldShowInstanceBadge", () => {
104 it("hides badges for distinct ACP agents sharing the registry driver", () => {
105 const mistral = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe", enabled: true };
106 const devin = { driverKind: acpRegistry, acpRegistryAgentId: "devin", enabled: true };
107 expect(shouldShowInstanceBadge(mistral, [mistral, devin])).toBe(false);
108 expect(shouldShowInstanceBadge(devin, [mistral, devin])).toBe(false);
109 });
110​
111 it("shows badges for multiple instances of the same ACP agent", () => {
112 const first = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe", enabled: true };
113 const second = { ...first };
114 expect(shouldShowInstanceBadge(first, [first, second])).toBe(true);
115 });
116​
117 it("keeps an explicit accent on a single ACP agent", () => {
118 const entry = {
119 driverKind: acpRegistry,
120 acpRegistryAgentId: "mistral-vibe",
121 accentColor: "#ff8800",
122 enabled: true,
123 };
124 expect(shouldShowInstanceBadge(entry, [entry])).toBe(true);
125 });
126​
127 it("distinguishes registry instances whose agent identity is unavailable", () => {
128 const entry = { driverKind: acpRegistry, enabled: true };
129 expect(shouldShowInstanceBadge(entry, [entry, { ...entry }])).toBe(true);
130 });
131​
132 it("shows the badge when the entry has an accent color", () => {
133 const entry = { driverKind: codex, accentColor: "#ff8800", enabled: true };
134 expect(shouldShowInstanceBadge(entry, [entry])).toBe(true);
135 });
136​
137 it("shows the badge when two entries share a driver, even without an accent", () => {
138 const first = { driverKind: codex, accentColor: undefined, enabled: true };
139 const second = { driverKind: codex, accentColor: undefined, enabled: true };
140 expect(shouldShowInstanceBadge(first, [first, second])).toBe(true);
141 });
142​
143 it("ignores disabled siblings for enabled instances while distinguishing historical owners", () => {
144 const enabled = { driverKind: codex, enabled: true };
145 const disabled = { driverKind: codex, enabled: false };
146​
147 expect(shouldShowInstanceBadge(enabled, [enabled, disabled])).toBe(false);
148 expect(shouldShowInstanceBadge(disabled, [enabled, disabled])).toBe(true);
149 expect(shouldShowInstanceBadge(disabled, [disabled, { ...disabled }])).toBe(true);
150 expect(shouldShowInstanceBadge(disabled, [disabled])).toBe(false);
151 });
152​
153 it("hides the badge for a single instance of a driver with no accent", () => {
154 const entry = { driverKind: codex, accentColor: undefined, enabled: true };
155 const other = { driverKind: claude, accentColor: undefined, enabled: true };
156 expect(shouldShowInstanceBadge(entry, [entry, other])).toBe(false);
157 });
158});