Skip to content
Source
Sign inSign up

providerInstanceDisplay.test.ts

85 lines3.6 KB

1import { ProviderDriverKind } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 normalizeProviderAccentColor,
6 providerAccentForegroundColor,
7 providerInstanceInitials,
8 shouldShowInstanceBadge,
9} from "./providerInstanceDisplay.ts";
10​
11const codex = ProviderDriverKind.make("codex");
12const acpRegistry = ProviderDriverKind.make("acpRegistry");
13​
14describe("providerInstanceInitials", () => {
15 it("treats punctuation as a word break but keeps apostrophes between letters", () => {
16 expect(providerInstanceInitials("Codex (hub)")).toBe("CH");
17 expect(providerInstanceInitials("work_codex")).toBe("WC");
18 expect(providerInstanceInitials("Theo's Codex")).toBe("TC");
19 expect(providerInstanceInitials("Codex 'hub'")).toBe("CH");
20 expect(providerInstanceInitials("‘hub’")).toBe("HU");
21 expect(providerInstanceInitials("(hub)")).toBe("HU");
22 });
23​
24 it("keeps an emoji whole instead of splitting its surrogate pair", () => {
25 expect(providerInstanceInitials("😀 Work")).toBe("😀W");
26 expect(providerInstanceInitials("😀")).toBe("😀");
27 });
28});
29​
30describe("normalizeProviderAccentColor", () => {
31 // regression: #9899 a non-hex accent must not render as the account badge color
32 it("rejects a non-hex value", () => {
33 expect(normalizeProviderAccentColor("blue")).toBeUndefined();
34 });
35});
36​
37describe("providerAccentForegroundColor", () => {
38 it.each([
39 ["#b5f23d", "#000000"],
40 ["#2563eb", "#ffffff"],
41 ["#777777", "#000000"],
42 ])("chooses the higher WCAG contrast foreground for %s", (accent, foreground) => {
43 expect(providerAccentForegroundColor(accent)).toBe(foreground);
44 });
45});
46​
47describe("shouldShowInstanceBadge", () => {
48 it("hides badges for distinct ACP agents sharing the registry driver", () => {
49 const mistral = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe", enabled: true };
50 const devin = { driverKind: acpRegistry, acpRegistryAgentId: "devin", enabled: true };
51 expect(shouldShowInstanceBadge(mistral, [mistral, devin])).toBe(false);
52 expect(shouldShowInstanceBadge(devin, [mistral, devin])).toBe(false);
53 });
54​
55 it("distinguishes registry instances whose agent identity is unavailable", () => {
56 const entry = { driverKind: acpRegistry, enabled: true };
57 expect(shouldShowInstanceBadge(entry, [entry, { ...entry }])).toBe(true);
58 });
59​
60 it("shows the badge when the entry has an accent color", () => {
61 const entry = { driverKind: codex, accentColor: "#ff8800", enabled: true };
62 expect(shouldShowInstanceBadge(entry, [entry])).toBe(true);
63 });
64​
65 it("ignores a non-hex accent color", () => {
66 const entry = { driverKind: codex, accentColor: "blue", enabled: true };
67 expect(shouldShowInstanceBadge(entry, [entry])).toBe(false);
68 });
69​
70 it("shows the badge when two entries share a driver, even without an accent", () => {
71 const first = { driverKind: codex, accentColor: undefined, enabled: true };
72 const second = { driverKind: codex, accentColor: undefined, enabled: true };
73 expect(shouldShowInstanceBadge(first, [first, second])).toBe(true);
74 });
75​
76 it("ignores disabled siblings for enabled instances while distinguishing historical owners", () => {
77 const enabled = { driverKind: codex, enabled: true };
78 const disabled = { driverKind: codex, enabled: false };
79​
80 expect(shouldShowInstanceBadge(enabled, [enabled, disabled])).toBe(false);
81 expect(shouldShowInstanceBadge(disabled, [enabled, disabled])).toBe(true);
82 expect(shouldShowInstanceBadge(disabled, [disabled, { ...disabled }])).toBe(true);
83 expect(shouldShowInstanceBadge(disabled, [disabled])).toBe(false);
84 });
85});