import { expect, within } from "storybook/test"; import type { Meta, StoryObj } from "@storybook/react-vite"; import { RobotRegularIcon } from "alouette-icons/phosphor-icons/Robot"; import { UserRegularIcon } from "alouette-icons/phosphor-icons/User"; import type { ReactNode } from "react"; import type { SVGIconElement } from "../primitives/Icon"; import { View } from "../primitives/View"; import { Story, accentsWithoutNeutral } from "../story-components/Story"; import { Avatar, type AvatarProps } from "./Avatar"; type ThisStory = StoryObj; export default { title: "alouette/Data/Avatar", component: Avatar, parameters: { componentSubtitle: "Accent disc standing for a person or an account: their initials, or an icon.", }, argTypes: { name: { control: "text" }, size: { control: "inline-radio", options: ["sm", "md", "lg"] }, variant: { control: "inline-radio", options: ["solid", "enabled"], table: { defaultValue: { summary: "solid" } }, }, accent: { control: "select", options: accentsWithoutNeutral }, }, } satisfies Meta; export const PreviewAvatarStory: ThisStory = { name: "Avatar Preview", parameters: { layout: "padded", chromatic: { disableSnapshot: true }, }, args: { name: "Camille Hurel" }, render: (args) => , }; interface SizeRowProps { name?: string; icon?: SVGIconElement; variant?: AvatarProps["variant"]; } function SizeRow({ name, icon, variant }: SizeRowProps): ReactNode { return ( ); } interface AccentRowProps { variant: AvatarProps["variant"]; } function AccentRow({ variant }: AccentRowProps): ReactNode { return ( {accentsWithoutNeutral.map((accent) => ( ))} } /> ); } export const VariantsAvatarStory: ThisStory = { name: "Avatar Variants", render: () => ( } /> } variant="enabled" /> } /> ), }; export const TestsAvatarStory: ThisStory = { name: "Avatar Tests", render: () => ( ), play: async ({ canvasElement }) => { const canvas = within(canvasElement); // Two initials at most, whatever the name holds. await expect(canvas.getByText("CH")).toBeTruthy(); await expect(canvas.getByText("CA")).toBeTruthy(); await expect(canvas.getByText("C")).toBeTruthy(); // Trimmed to the caps, the initials center on their ink rather than on // ascender + descender. tailwind-merge reads `text-trim-cap` as a text // color unless alouette's config registers it. await expect(getComputedStyle(canvas.getByText("CH")).textBoxTrim).toBe( "trim-both", ); }, };