Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions resources/js/react/components/ItemCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import preview from '@/.storybook/preview';
import { expect, fn } from 'storybook/test';
import ItemCard from './ItemCard';

/**
* An item on the roadmap's board: its vote, title, description, type, and comment count.
* The title opens the item in a slideover. `vote` asks whoever shows it to count a vote.
*/
const meta = preview.meta({
title: 'Roadmap/ItemCard',
component: ItemCard,
args: {
item: {
id: 7,
title: 'Dark mode for the dashboard',
slug: 'dark-mode-for-the-dashboard',
url: '/roadmap/dark-mode-for-the-dashboard',
description:
'Follow the system setting, with a switch in the user menu to override it.',
status: 'planned',
status_label: 'Planned',
type: 'feature',
type_label: 'Feature',
votes_count: 42,
comments_count: 5,
has_voted: false,
votable: true,
created_at: '2026-11-02T09:00:00Z',
},
typeVariant: 'default',
commentsEnabled: true,
showStatus: false,
votePending: false,
},
decorators: [
(Story) => (
<div className="max-w-sm">
<Story />
</div>
),
],
});
export default meta;

/** On the board, in its status's column. Its vote button asks for a vote. */
export const Default = meta.story({
// The spy here only: in the meta's args it would leave every snippet incomplete.
args: { onVote: fn() },
play: async ({ args, canvas, userEvent }) => {
await expect(
canvas.getByRole('link', { name: 'Dark mode for the dashboard' }),
).toBeVisible();
await expect(
canvas.getByRole('link', { name: 'Comments' }),
).toHaveTextContent('5');

await userEvent.click(canvas.getByRole('button', { name: 'Upvote' }));

await expect(args.onVote).toHaveBeenCalled();
},
});

/** In the visitor's own submissions, off the board: it says its status. */
export const WithStatus = meta.story({
args: { showStatus: true },
play: async ({ canvas }) => {
await expect(canvas.getByText('Planned')).toBeVisible();
},
});

/** Comments turned off: no count. */
export const WithoutComments = meta.story({
args: { commentsEnabled: false },
play: async ({ canvas }) => {
await expect(
canvas.queryByRole('link', { name: 'Comments' }),
).toBeNull();
},
});

/** A bug the visitor voted for, with no description. */
export const VotedBug = meta.story({
args: {
item: {
id: 8,
title: 'Invoices show the wrong currency',
slug: 'invoices-wrong-currency',
url: '/roadmap/invoices-wrong-currency',
description: null,
status: 'in_progress',
status_label: 'In progress',
type: 'bug',
type_label: 'Bug',
votes_count: 12,
comments_count: 0,
has_voted: true,
votable: true,
created_at: '2026-11-18T09:00:00Z',
},
typeVariant: 'destructive',
},
play: async ({ canvas }) => {
await expect(
canvas.getByRole('button', { name: 'Upvote' }),
).toHaveAttribute('aria-pressed', 'true');
},
});
5 changes: 3 additions & 2 deletions resources/js/react/components/ItemCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default function ItemCard({
/** Own submissions are listed off the board, where the column no longer says the status. */
showStatus?: boolean;
votePending?: boolean;
onVote: (item: RoadmapItem) => void;
/** Asks for a vote on the item; whoever shows the card counts it. */
onVote?: (item: RoadmapItem) => void;
}) {
const t = useT();

Expand All @@ -35,7 +36,7 @@ export default function ItemCard({
votes={item.votes_count}
voted={item.has_voted}
pending={votePending || !item.votable}
onVote={() => onVote(item)}
onVote={() => onVote?.(item)}
/>

<div className="flex min-w-0 flex-1 flex-col gap-1">
Expand Down
49 changes: 49 additions & 0 deletions resources/js/react/components/VoteButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import preview from '@/.storybook/preview';
import { expect, fn } from 'storybook/test';
import VoteButton from './VoteButton';

/**
* An item's upvote and its count. Filled once the visitor has voted. Whoever shows it
* counts the vote, on `vote`; `pending` disables it meanwhile, or for an item that takes
* no votes.
*/
const meta = preview.meta({
title: 'Roadmap/VoteButton',
component: VoteButton,
args: { itemId: 1, votes: 42, voted: false, pending: false },
});
export default meta;

/** Not voted yet. A click asks for the vote. */
export const Default = meta.story({
// The spy here only: in the meta's args it would leave every snippet incomplete.
args: { onVote: fn() },
play: async ({ args, canvas, userEvent }) => {
const button = canvas.getByRole('button', { name: 'Upvote' });
await expect(button).toHaveAttribute('aria-pressed', 'false');

await userEvent.click(button);

await expect(args.onVote).toHaveBeenCalled();
},
});

/** The visitor's vote counts: filled. */
export const Voted = meta.story({
args: { voted: true, votes: 43 },
play: async ({ canvas }) => {
await expect(
canvas.getByRole('button', { name: 'Upvote' }),
).toHaveAttribute('aria-pressed', 'true');
},
});

/** A vote on its way, or an item that takes none: disabled. */
export const Pending = meta.story({
args: { pending: true },
play: async ({ canvas }) => {
await expect(
canvas.getByRole('button', { name: 'Upvote' }),
).toBeDisabled();
},
});
5 changes: 3 additions & 2 deletions resources/js/react/components/VoteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default function VoteButton({
votes: number;
voted: boolean;
pending?: boolean;
onVote: () => void;
/** Asks for the vote; whoever shows the button counts it. */
onVote?: () => void;
}) {
const t = useT();

Expand All @@ -34,7 +35,7 @@ export default function VoteButton({
)}
onClick={(event) => {
event.preventDefault();
onVote();
onVote?.();
}}
>
<IconAltArrowUpBold className="size-5" />
Expand Down
101 changes: 101 additions & 0 deletions resources/js/vue/components/ItemCard.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import preview from '@/.storybook/preview';
import { expect, fn } from 'storybook/test';
import ItemCard from './ItemCard.vue';

/**
* An item on the roadmap's board: its vote, title, description, type, and comment count.
* The title opens the item in a slideover. `vote` asks whoever shows it to count a vote.
*/
const meta = preview.meta({
title: 'Roadmap/ItemCard',
component: ItemCard,
args: {
item: {
id: 7,
title: 'Dark mode for the dashboard',
slug: 'dark-mode-for-the-dashboard',
url: '/roadmap/dark-mode-for-the-dashboard',
description:
'Follow the system setting, with a switch in the user menu to override it.',
status: 'planned',
status_label: 'Planned',
type: 'feature',
type_label: 'Feature',
votes_count: 42,
comments_count: 5,
has_voted: false,
votable: true,
created_at: '2026-11-02T09:00:00Z',
},
typeVariant: 'default',
commentsEnabled: true,
showStatus: false,
votePending: false,
},
decorators: [() => ({ template: '<div class="max-w-sm"><story /></div>' })],
});
export default meta;

/** On the board, in its status's column. Its vote button asks for a vote. */
export const Default = meta.story({
// The spy here only: in the meta's args it would leave every snippet incomplete.
args: { onVote: fn() },
play: async ({ args, canvas, userEvent }) => {
await expect(
canvas.getByRole('link', { name: 'Dark mode for the dashboard' }),
).toBeVisible();
await expect(
canvas.getByRole('link', { name: 'Comments' }),
).toHaveTextContent('5');

await userEvent.click(canvas.getByRole('button', { name: 'Upvote' }));

await expect(args.onVote).toHaveBeenCalled();
},
});

/** In the visitor's own submissions, off the board: it says its status. */
export const WithStatus = meta.story({
args: { showStatus: true },
play: async ({ canvas }) => {
await expect(canvas.getByText('Planned')).toBeVisible();
},
});

/** Comments turned off: no count. */
export const WithoutComments = meta.story({
args: { commentsEnabled: false },
play: async ({ canvas }) => {
await expect(
canvas.queryByRole('link', { name: 'Comments' }),
).toBeNull();
},
});

/** A bug the visitor voted for, with no description. */
export const VotedBug = meta.story({
args: {
item: {
id: 8,
title: 'Invoices show the wrong currency',
slug: 'invoices-wrong-currency',
url: '/roadmap/invoices-wrong-currency',
description: null,
status: 'in_progress',
status_label: 'In progress',
type: 'bug',
type_label: 'Bug',
votes_count: 12,
comments_count: 0,
has_voted: true,
votable: true,
created_at: '2026-11-18T09:00:00Z',
},
typeVariant: 'destructive',
},
play: async ({ canvas }) => {
await expect(
canvas.getByRole('button', { name: 'Upvote' }),
).toHaveAttribute('aria-pressed', 'true');
},
});
49 changes: 49 additions & 0 deletions resources/js/vue/components/VoteButton.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import preview from '@/.storybook/preview';
import { expect, fn } from 'storybook/test';
import VoteButton from './VoteButton.vue';

/**
* An item's upvote and its count. Filled once the visitor has voted. Whoever shows it
* counts the vote, on `vote`; `pending` disables it meanwhile, or for an item that takes
* no votes.
*/
const meta = preview.meta({
title: 'Roadmap/VoteButton',
component: VoteButton,
args: { itemId: 1, votes: 42, voted: false, pending: false },
});
export default meta;

/** Not voted yet. A click asks for the vote. */
export const Default = meta.story({
// The spy here only: in the meta's args it would leave every snippet incomplete.
args: { onVote: fn() },
play: async ({ args, canvas, userEvent }) => {
const button = canvas.getByRole('button', { name: 'Upvote' });
await expect(button).toHaveAttribute('aria-pressed', 'false');

await userEvent.click(button);

await expect(args.onVote).toHaveBeenCalled();
},
});

/** The visitor's vote counts: filled. */
export const Voted = meta.story({
args: { voted: true, votes: 43 },
play: async ({ canvas }) => {
await expect(
canvas.getByRole('button', { name: 'Upvote' }),
).toHaveAttribute('aria-pressed', 'true');
},
});

/** A vote on its way, or an item that takes none: disabled. */
export const Pending = meta.story({
args: { pending: true },
play: async ({ canvas }) => {
await expect(
canvas.getByRole('button', { name: 'Upvote' }),
).toBeDisabled();
},
});