import { expect, within } from "storybook/test"; import type { Meta, StoryObj } from "@storybook/react-vite"; import { Box } from "../containers/Box"; import { Paragraph } from "../primitives/Text"; import { Story, accentsWithoutNeutral } from "../story-components/Story"; import { Citation } from "./Citation"; type ThisStory = StoryObj; export default { title: "alouette/Data/Citation", component: Citation, parameters: { componentSubtitle: "Attribution for a quote or an excerpt — an em dash and the source, optionally linked", }, argTypes: { accent: { description: "The accent of the linked source", control: "select", options: accentsWithoutNeutral, }, size: { description: "The size of the attribution", control: "inline-radio", options: ["sm", "md"], table: { defaultValue: { summary: "md" } }, }, href: { description: "Links the source when set", control: "text" }, children: { description: "The source being credited", control: "text" }, }, } satisfies Meta; export const CitationPreviewStory: ThisStory = { name: "Citation Preview", parameters: { layout: "padded", chromatic: { disableSnapshot: true }, }, args: { children: "Ursula K. Le Guin" }, render: (args) => , }; export const CitationVariantsStory: ThisStory = { name: "Citation Variants", render: () => ( Ursula K. Le Guin, sm Ursula K. Le Guin, md The Dispossessed Opens in the same tab {accentsWithoutNeutral.map((accent) => ( {accent} ))} Light is the left hand of darkness, and darkness the right hand of light. The Left Hand of Darkness ), }; export const CitationTestsStory: ThisStory = { name: "Citation Tests", render: () => ( Ursula K. Le Guin A Source ), play: async ({ canvasElement }) => { const canvas = within(canvasElement); await expect(canvas.getByText("Ursula K. Le Guin")).toBeTruthy(); // The em dash is part of the component, not of the source text. await expect(canvas.getAllByText("—")).toHaveLength(2); const link = canvas.getByRole("link", { name: "A Source" }); await expect(link).toHaveAttribute("href", "https://example.com/source"); }, };