Skip to content

Commit 5325fee

Browse files
committed
test(bots): a still face shows each colour picked
With Bot faces set to still, the Look section's preview is a still, and the conversation list's face is one at rest. The test picks a colour and checks the preview is painted again in it at once, and that every other face of the Bot draws it once it is saved. Nothing needed changing.
1 parent 12d1ef3 commit 5325fee

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

‎app/tests/bot-look.test.tsx‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { AbstractAvatar } from "@/components/agents/abstract-avatar";
2020
import { SAVE_AFTER_MS } from "@/components/bot-profile/look";
2121
import { SetupSections } from "@/components/bot-profile/setup";
2222
import { ChannelAvatar } from "@/components/channels/avatar";
23+
import { BOT_FACES_STORAGE_KEY, setBotFaces } from "@/lib/bot-faces";
2324
import { agentListQueryOptions, agentQueryOptions } from "@/lib/agents/queries";
2425
import { queryClient } from "@/query-client";
2526
import {
@@ -43,6 +44,7 @@ beforeAll(() => GlobalRegistrator.register());
4344
afterEach(() => {
4445
cleanup();
4546
queryClient.clear();
47+
window.localStorage.removeItem(BOT_FACES_STORAGE_KEY);
4648
});
4749
afterAll(async () => {
4850
await settleReactWork();
@@ -551,3 +553,52 @@ test("a conversation's face, which knows only the Bot's id, waits for the Bots l
551553
expect(drawn()).toEqual(["coral:k2p9x7aq", "coral:k2p9x7aq", "not-listed"]),
552554
);
553555
});
556+
557+
test("with Bot faces set to still, the preview is painted again in each colour picked, and the conversation's face follows", async () => {
558+
// Every canvas paints on one context, which counts the pictures begun on it.
559+
let paints = 0;
560+
const ctx = new Proxy(
561+
{
562+
clearRect: () => {
563+
paints++;
564+
},
565+
createLinearGradient: () => ({ addColorStop: () => {} }),
566+
createRadialGradient: () => ({ addColorStop: () => {} }),
567+
} as Record<string | symbol, unknown>,
568+
{
569+
get: (target, key) => (key in target ? target[key] : () => {}),
570+
set: (target, key, value) => {
571+
target[key] = value;
572+
return true;
573+
},
574+
},
575+
);
576+
const getContext = HTMLCanvasElement.prototype.getContext;
577+
HTMLCanvasElement.prototype.getContext = (() =>
578+
ctx) as unknown as typeof getContext;
579+
try {
580+
setBotFaces("still");
581+
serve();
582+
const { view, user } = draw();
583+
const look = await lookOf(view);
584+
const palettes = () =>
585+
[...view.container.querySelectorAll("[data-palette]")].map((orb) =>
586+
orb.getAttribute("data-palette"),
587+
);
588+
await waitFor(() =>
589+
expect(palettes()).toEqual(["ocean", "ocean", "ocean"]),
590+
);
591+
await settleReactWork();
592+
const before = paints;
593+
594+
await user.click(look.getByRole("radio", { name: "Green" }));
595+
596+
expect(palettes()).toEqual(["moss", "ocean", "ocean"]);
597+
expect(paints).toBeGreaterThan(before);
598+
await waitFor(() => expect(palettes()).toEqual(["moss", "moss", "moss"]), {
599+
timeout: SAVE_AFTER_MS * 4,
600+
});
601+
} finally {
602+
HTMLCanvasElement.prototype.getContext = getContext;
603+
}
604+
});

0 commit comments

Comments
 (0)