import { expect, within } from "storybook/test"; import type { Meta, StoryObj } from "@storybook/react-vite"; import type { ReactNode } from "react"; import type { Accent } from "../../core/AlouetteConfig"; import { Box } from "../containers/Box"; import { Paragraph } from "../primitives/Text"; import { Story, accentsWithoutNeutral } from "../story-components/Story"; import { Blockquote, BlockquoteFrame } from "./Blockquote"; import { Citation } from "./Citation"; import { CodeBlock } from "./CodeBlock"; type ThisStory = StoryObj; export default { title: "alouette/Data/Blockquote", component: Blockquote, subcomponents: { BlockquoteFrame }, parameters: { componentSubtitle: "A quoted excerpt set off by an accent rule, with an optional Citation underneath: Blockquote for text, BlockquoteFrame for block content", }, argTypes: { accent: { description: "The accent of the leading rule", control: "select", options: accentsWithoutNeutral, }, size: { description: "The size of the quoted text", control: "inline-radio", options: ["sm", "md"], table: { defaultValue: { summary: "md" } }, }, children: { description: "The quoted text", control: "text" }, }, } satisfies Meta; export const BlockquotePreviewStory: ThisStory = { name: "Blockquote Preview", parameters: { layout: "padded", chromatic: { disableSnapshot: true }, }, args: { children: "The only thing that makes life possible is permanent, intolerable uncertainty: not knowing what comes next.", }, render: (args) =>
, }; interface QuoteProps { accent?: Accent; size?: "md" | "sm"; citation?: ReactNode; } function Quote({ accent, size, citation }: QuoteProps): ReactNode { return (
The only thing that makes life possible is permanent, intolerable uncertainty: not knowing what comes next.
); } export const BlockquoteVariantsStory: ThisStory = { name: "Blockquote Variants", render: () => ( Ursula K. Le Guin}> The only thing that makes life possible is permanent, intolerable uncertainty: not knowing what comes next. Light is the left hand of darkness. Run it with: pnpm install Ursula K. Le Guin} /> The Left Hand of Darkness } /> {accentsWithoutNeutral.map((accent) => ( {accent}} size="sm" /> ))} Ursula K. Le Guin} /> ), }; export const BlockquoteTestsStory: ThisStory = { name: "Blockquote Tests", render: () => (
A Source } > Quoted text.
First paragraph. Second paragraph.
), play: async ({ canvasElement }) => { const canvas = within(canvasElement); const quote = canvas.getByText("Quoted text."); // react-native-web maps role="blockquote" onto a real
, and the // quote itself is a Paragraph, so a

. await expect(quote.tagName).toBe("P"); const blockquote = quote.closest("blockquote"); await expect(blockquote).not.toBeNull(); const link = canvas.getByRole("link", { name: "A Source" }); await expect(blockquote?.contains(link)).toBe(true); await expect(link).toHaveAttribute("href", "https://example.com/source"); // BlockquoteFrame renders its children as they are: each paragraph is a direct // child of the

, not nested in a

of its own. const first = canvas.getByText("First paragraph."); const second = canvas.getByText("Second paragraph."); await expect(first.tagName).toBe("P"); await expect(first.parentElement?.tagName).toBe("BLOCKQUOTE"); await expect(second.parentElement).toBe(first.parentElement); }, };