import { imageFrameReactionButton } from "@seed-design/css/recipes/image-frame-reaction-button"; import { render } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it } from "bun:test"; import type { ReactElement } from "react"; import { ImageFrameReactionButton } from "./ImageFrame"; function setUp(jsx: ReactElement) { return { user: userEvent.setup(), ...render(jsx), }; } describe("ImageFrame", () => { describe("ImageFrameReactionButton", () => { it("renders the unselected icon by default", () => { const classNames = imageFrameReactionButton(); const { getByRole, container } = setUp(); const button = getByRole("button", { name: "Like image" }); const lineIcon = container.querySelector(`.${classNames.lineIcon}`); const fillIcon = container.querySelector(`.${classNames.fillIcon}`); const gradient = container.querySelector("linearGradient"); expect(button).toHaveAttribute("aria-pressed", "false"); expect(lineIcon).not.toBeNull(); expect(lineIcon).toHaveClass(classNames.lineIcon); expect(fillIcon).toBeNull(); expect(gradient).toBeNull(); expect(lineIcon).not.toHaveAttribute("data-pressed"); }); it("switches to the selected icon on press", async () => { const classNames = imageFrameReactionButton(); const { getByRole, container, user } = setUp( , ); const button = getByRole("button", { name: "Like image" }); await user.click(button); const fillIcon = container.querySelector(`.${classNames.fillIcon}`); const lineIcon = container.querySelector(`.${classNames.lineIcon}`); const gradient = container.querySelector("linearGradient"); expect(button).toHaveAttribute("aria-pressed", "true"); expect(fillIcon).not.toBeNull(); expect(lineIcon).toBeNull(); expect(gradient).not.toBeNull(); expect(fillIcon).toHaveAttribute("data-pressed", ""); }); }); });