mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Add Storybook stories for the new brewery detail page components
This commit is contained in:
56
web/frontend/stories/CommentItem.stories.tsx
Normal file
56
web/frontend/stories/CommentItem.stories.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { expect, fn, userEvent, within } from 'storybook/test';
|
||||
import CommentItem from '../app/features/breweries/components/CommentItem';
|
||||
import type { FillerComment } from '../app/features/breweries/utils/filler-brewery-detail';
|
||||
|
||||
const commentItemDescription = `A single comment row on the brewery detail page: avatar initials, username/star/timestamp, body, and a per-comment like toggle.`;
|
||||
|
||||
const comment: FillerComment = {
|
||||
id: '1',
|
||||
user: 'malt_kettle',
|
||||
initials: 'MK',
|
||||
rating: 5,
|
||||
time: '2 days ago',
|
||||
text: 'The barrel-aged flanders red is worth the trip alone.',
|
||||
likes: 12,
|
||||
liked: false,
|
||||
};
|
||||
|
||||
const meta = {
|
||||
title: 'Breweries/CommentItem',
|
||||
component: CommentItem,
|
||||
tags: ['autodocs'],
|
||||
args: {
|
||||
onToggleLike: fn(),
|
||||
},
|
||||
parameters: {
|
||||
layout: 'padded',
|
||||
docs: {
|
||||
description: {
|
||||
component: commentItemDescription,
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies Meta<typeof CommentItem>;
|
||||
|
||||
export default meta;
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
export const Unliked: Story = {
|
||||
args: { comment },
|
||||
play: async ({ args, canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
await expect(canvas.getByText('malt_kettle')).toBeInTheDocument();
|
||||
const likeButton = canvas.getByRole('button', { name: /12 likes/i });
|
||||
await userEvent.click(likeButton);
|
||||
await expect(args.onToggleLike).toHaveBeenCalledWith('1');
|
||||
},
|
||||
};
|
||||
|
||||
export const Liked: Story = {
|
||||
args: { comment: { ...comment, liked: true } },
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
await expect(canvas.getByRole('button', { name: /13 likes/i })).toBeInTheDocument();
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user