A bot's identity was one of seven hues, and the hue picked both its colour and its stone shape. Now its colour is free and its stone is its own: - `bots.color` holds any `#rrggbb`, `bots.stone` the flat-cut shape it's drawn on. `bots.hue` stays as the palette column they replaced, read only as a fallback; `src/scripts/move-bot-colour-to-owners.ts` backfills an install from it (safe to rerun). - `src/utils/bot-color.ts` is the only place a colour is validated or resolved (`resolveBotColor`/`resolveBotStone` carry the old hue forward, `botColorNeedsPaperFace` flips the eyes to paper on a very dark body), and `src/utils/bot-stone-props.ts` gives every row its props, so a row saved before this still renders as it did. - `BotStone` takes the colour as the body's SVG `fill`, the one documented exception to the token rule: an arbitrary hex has no token to point at. `UnreadDot` follows it. - The picker keeps the palette tiles (still shape and colour together) and adds a native swatch and a hex field, so a custom colour keeps its stone. Same place as before: the header avatar's modal and Settings > Bots, for crew managers. The coordinator stays hue-less. - A recolour reaches other open tabs through `pushBotUpdated`.
29 lines
958 B
TypeScript
29 lines
958 B
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import pickFreeColor from "./pick-free-color";
|
|
|
|
describe("pick-free-color", () => {
|
|
test("takes the first palette colour nobody has", () => {
|
|
expect(pickFreeColor({ taken: [] })).toEqual({ color: "#e4572e", stone: "ember" });
|
|
});
|
|
|
|
test("skips the colours already taken", () => {
|
|
expect(pickFreeColor({ taken: ["#e4572e", "#e9a23b", null] })).toEqual({
|
|
color: "#7fae3c",
|
|
stone: "moss",
|
|
});
|
|
});
|
|
|
|
test("falls back to the least used colour", () => {
|
|
const everyone = ["#e4572e", "#e9a23b", "#7fae3c", "#16a394", "#3b7dd8", "#7c5cd6"];
|
|
|
|
expect(pickFreeColor({ taken: [...everyone, "#e4572e"] })).toEqual({
|
|
color: "#d6538c",
|
|
stone: "rose",
|
|
});
|
|
});
|
|
|
|
test("counts a colour however it's cased", () => {
|
|
expect(pickFreeColor({ taken: ["#E4572E"] }).color).toBe("#e9a23b");
|
|
});
|
|
});
|