import { composeStories, composeStory, } from "@storybook/react" import { expect, fn, userEvent } from "storybook/test" import { test } from "vitest" import { expectNoAxeViolations } from "../expectNoAxeViolations.testHelpers.ts" import { mountStory } from "../mountStory.testHelpers.ts" import { expectAgentDrivable } from "../testing/index.ts" import meta, * as stories from "./BadgeButton.stories.tsx" const { BesideABadge, Playground, InATileFooter } = composeStories(stories) /** * The properties a `` cannot have, and the reason this * is a component rather than a `className` on `Badge`. */ test("is a button, not a span", async () => { const { canvas } = await mountStory(Playground) const chip = expectAgentDrivable(canvas, { name: "1 episode", role: "button", }) await expect(chip.tagName).toBe("BUTTON") // Never `submit`: these chips sit inside forms, and the platform's // default would make "change the start point" save the dialog. await expect(chip).toHaveAttribute("type", "button") }) test("Tab reaches it and Enter fires it", async () => { const onClick = fn() const { canvas } = await mountStory( composeStory( { args: { children: "1 episode", onClick } }, meta, ), ) const chip = canvas.getByRole("button", { name: "1 episode", }) await userEvent.tab() await expect(chip).toHaveFocus() await userEvent.keyboard("{Enter}") await expect(onClick).toHaveBeenCalledTimes(1) // Space too — the second half of what the platform gives a // `