import { ACTIVE_RUN_STATUSES, OO_DEFAULT_COLOR } from "@rakazo/core"; import { renderToString } from "react-dom/server"; import { describe, expect, it } from "vitest"; import { BotAvatar, OoShapePreview, ooMomentForPose, parseBotAvatar } from "./bot-avatar.js"; describe("BotAvatar", () => { it("renders distinct shape gradient IDs for concurrent working avatars", () => { const html = renderToString(
, ); const bodyGradIds = [...html.matchAll(/id="(oo[^"]+-body)"/g)].map((m) => m[1]); expect(bodyGradIds).toHaveLength(2); expect(new Set(bodyGradIds).size).toBe(2); for (const id of bodyGradIds) { expect(html).toContain(`url(#${id})`); } }); it.each([...ACTIVE_RUN_STATUSES])("marks active run status %s as working", (status) => { const html = renderToString(); expect(html).toContain(" { const html = renderToString(); expect(html).toContain('data-working="false"'); }); it("draws the Oo eyes for plain color values", () => { const html = renderToString( , ); expect(html).toContain(" { const html = renderToString( , ); expect(html).toContain('data-oo-species="cat"'); expect(html).toContain('data-part="ear-left"'); expect(html).toContain("#FFFFFF"); }); it("keeps small avatars free of arms and props", () => { const small = renderToString(); const large = renderToString(); expect(small).not.toContain('data-part="arm-left"'); expect(large).toContain('data-part="arm-left"'); }); it("maps mascot poses to moments", () => { expect(ooMomentForPose("delighted")).toBe("success"); expect(ooMomentForPose("typing")).toBe("working"); expect(ooMomentForPose("error")).toBe("concerned"); expect(ooMomentForPose("listening")).toBe("listening"); const html = renderToString(); expect(html).toContain('data-oo-moment="thinking"'); }); it("renders distinct shapes for distinct bot identities", () => { const maya = renderToString(); const github = renderToString(); expect(maya).not.toEqual(github); }); it("parses shape indexes from encoded color values", () => { const parsed = parseBotAvatar(`${OO_DEFAULT_COLOR}::shape_3`); expect(parsed.color).toBe(OO_DEFAULT_COLOR); expect(parsed.shapeIndex).toBe(3); expect(parsed.isImage).toBe(false); }); it("normalizes malformed shape suffixes to shape 0", () => { expect(parseBotAvatar(`${OO_DEFAULT_COLOR}::shape_-1`).shapeIndex).toBe(0); expect(parseBotAvatar(`${OO_DEFAULT_COLOR}::shape_3junk`).shapeIndex).toBe(0); expect(parseBotAvatar(`${OO_DEFAULT_COLOR}::shape_`).shapeIndex).toBe(0); }); it("renders uploaded images without the geometric svg", () => { const html = renderToString( , ); expect(html).toContain(" { const parsed = parseBotAvatar("https://evil.example/track.png"); expect(parsed.isImage).toBe(false); expect(parsed.imageUrl).toBeUndefined(); const html = renderToString( , ); expect(html).not.toContain(" { const html = renderToString( undefined} />, ); expect(html).toContain('aria-label="EvOo"'); expect(html).toContain('aria-pressed="true"'); expect(html).toContain("focus-visible:ring-2"); }); });