Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/chat-ui/test/avatar-composition.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("avatar composition and identity resolution", () => {
expect(corbitHtml).toContain('data-corbit="true"');
expect(corbitHtml).toContain('aria-label="Echo Agent"');
expect(corbitHtml).toContain("<svg");
expect(corbitHtml).toContain(CORBIT_DEFAULT_COLOR);
expect(corbitHtml).toContain(`fill:var(${CORBIT_DEFAULT_COLOR})`);
expect(corbitHtml).not.toContain(">EA<");
});

Expand All @@ -29,7 +29,9 @@ describe("avatar composition and identity resolution", () => {
expect(AVATAR_COLORS).toContain(aliceColor);
expect(AVATAR_COLORS).toContain(bobColor);

expect(avatarClassForPrincipal("usr_alice")).toContain(aliceColor);
expect(avatarClassForPrincipal("usr_alice")).toBe(
`bg-(${aliceColor}) text-black`,
);

expect(avatarColorForPrincipal("usr_alice")).toBe(aliceColor);
});
Expand Down
36 changes: 36 additions & 0 deletions packages/chat-ui/test/avatar-tokens.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// happy-dom does not apply stylesheets, so the avatar identity palette is
// locked against CSS source: :root must define exactly the four --avatar-N
// tokens with their pinned hex values (the proposed upstream contract).
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const css = readFileSync(
join(dirname(fileURLToPath(import.meta.url)), "../src/styles.css"),
"utf8",
);

function rootBodies(): string[] {
return [
...css.matchAll(/(?:^|\n)\s*:root\s*\{([^}]+)\}/g),
].map((match) => match[1] ?? "");
}

describe("avatar token contract", () => {
test(":root defines exactly the four avatar pastels with pinned hex", () => {
const bodies = rootBodies();
expect(bodies.length).toBeGreaterThan(0);
const body = bodies[0] ?? "";

expect(body).toMatch(/--avatar-1:\s*#c5d2de\s*;/);
expect(body).toMatch(/--avatar-2:\s*#c1d1be\s*;/);
expect(body).toMatch(/--avatar-3:\s*#f7ead5\s*;/);
expect(body).toMatch(/--avatar-4:\s*#f2b277\s*;/);

const tokens = [...body.matchAll(/--avatar-(\d+)\s*:/g)].map(
(match) => match[1],
);
expect(tokens.sort()).toEqual(["1", "2", "3", "4"]);
});
});
Loading