mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-11-15 01:12:36 -06:00
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { describe, expect, test, vi } from "vitest";
|
|
import { render } from "vitest-browser-react";
|
|
import * as Stickers from "../core/Stickers";
|
|
import { StickerImage } from "./StickerImage";
|
|
|
|
const state = vi.hoisted(() => ({ attending: true, reducedMotion: false }));
|
|
|
|
vi.mock("../chat-hooks", () => ({
|
|
useIsAttending: () => state.attending,
|
|
}));
|
|
|
|
vi.mock("~/hooks/usePrefersReducedMotion", () => ({
|
|
usePrefersReducedMotion: () => state.reducedMotion,
|
|
}));
|
|
|
|
describe("StickerImage", () => {
|
|
test.each([
|
|
{
|
|
why: "plays while paying attention",
|
|
attending: true,
|
|
reducedMotion: false,
|
|
paused: false,
|
|
},
|
|
{
|
|
why: "holds still while not paying attention",
|
|
attending: false,
|
|
reducedMotion: false,
|
|
paused: true,
|
|
},
|
|
{
|
|
why: "holds still for reduced motion",
|
|
attending: true,
|
|
reducedMotion: true,
|
|
paused: true,
|
|
},
|
|
])("$why", async ({ attending, reducedMotion, paused }) => {
|
|
state.attending = attending;
|
|
state.reducedMotion = reducedMotion;
|
|
|
|
const screen = await render(
|
|
<StickerImage
|
|
sticker={Stickers.CHAT_STICKERS[0]}
|
|
size={96}
|
|
data-testid="sticker"
|
|
/>,
|
|
);
|
|
|
|
const sticker = screen.getByTestId("sticker");
|
|
if (paused) {
|
|
await expect.element(sticker).toHaveAttribute("data-paused", "true");
|
|
} else {
|
|
await expect.element(sticker).not.toHaveAttribute("data-paused");
|
|
}
|
|
});
|
|
});
|