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
53 changes: 53 additions & 0 deletions resources/js/react/components/CategoryNav.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import preview from '@/.storybook/preview';
import { expect } from 'storybook/test';
import CategoryNav from './CategoryNav';

/**
* The blog's categories above its posts, with "All" first. The current one is filled.
* Renders nothing when the blog has no categories.
*/
const meta = preview.meta({
title: 'Blog/CategoryNav',
component: CategoryNav,
args: {
categories: [
{ name: 'Guides', slug: 'guides' },
{ name: 'Product', slug: 'product' },
{ name: 'Engineering', slug: 'engineering' },
],
active: null,
allActive: true,
},
});
export default meta;

/** On the blog's index: "All" is current. */
export const Default = meta.story({
play: async ({ canvas }) => {
await expect(canvas.getByRole('link', { name: 'All' })).toHaveAttribute(
'aria-current',
'page',
);
},
});

/** On a category's page: that category is current. */
export const CategorySelected = meta.story({
args: { active: 'product', allActive: false },
play: async ({ canvas }) => {
await expect(
canvas.getByRole('link', { name: 'Product' }),
).toHaveAttribute('aria-current', 'page');
await expect(
canvas.getByRole('link', { name: 'All' }),
).not.toHaveAttribute('aria-current');
},
});

/** No categories: nothing renders. */
export const Empty = meta.story({
args: { categories: [] },
play: async ({ canvas }) => {
await expect(canvas.queryByRole('navigation')).toBeNull();
},
});
75 changes: 75 additions & 0 deletions resources/js/react/components/LatestPostsSection.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import preview from '@/.storybook/preview';
import { expect } from 'storybook/test';
import LatestPostsSection from './LatestPostsSection';

/** The newest posts on another page, such as the home page, with a link to the blog. */
const meta = preview.meta({
title: 'Blog/LatestPostsSection',
component: LatestPostsSection,
parameters: { layout: 'fullscreen' },
args: {
posts: [
{
id: 1,
title: 'Shipping a SaaS in a weekend',
slug: 'shipping-a-saas-in-a-weekend',
excerpt:
'What we cut, what we kept, and the three modules that did most of the work.',
cover_url: '',
card_url: '',
published_at: '2026-11-20T09:00:00Z',
updated_at: null,
category: { name: 'Guides', slug: 'guides' },
tags: [],
author: { name: 'Ada Lovelace', avatar_url: null },
url: '/blog/shipping-a-saas-in-a-weekend',
content: null,
},
{
id: 2,
title: 'Why we moved billing to Stripe Checkout',
slug: 'stripe-checkout',
excerpt:
'Fewer forms to keep up to date, and tax handled for us.',
cover_url: '',
card_url: '',
published_at: '2026-11-12T09:00:00Z',
updated_at: null,
category: { name: 'Engineering', slug: 'engineering' },
tags: [{ name: 'billing', slug: 'billing' }],
author: { name: 'Grace Hopper', avatar_url: null },
url: '/blog/stripe-checkout',
content: null,
},
{
id: 3,
title: 'Release notes: November',
slug: 'release-notes-november',
excerpt: null,
cover_url: '',
card_url: '',
published_at: '2026-11-01T09:00:00Z',
updated_at: null,
category: { name: 'Product', slug: 'product' },
tags: [],
author: null,
url: '/blog/release-notes-november',
content: null,
},
],
},
});
export default meta;

/** Three posts and the link to the blog. */
export const Default = meta.story({
play: async ({ canvas }) => {
await expect(
canvas.getByRole('heading', { name: 'From the blog' }),
).toBeVisible();
await expect(canvas.getAllByRole('article')).toHaveLength(3);
await expect(
canvas.getByRole('link', { name: /View all/ }),
).toBeVisible();
},
});
83 changes: 83 additions & 0 deletions resources/js/react/components/PostCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import preview from '@/.storybook/preview';
import { expect } from 'storybook/test';
import PostCard from './PostCard';

/**
* A post in a list: cover, category, title, excerpt, tags, author and date. The title's
* link covers the whole card; the category and tags stay links of their own.
*
* Without a cover image, the title shows on a gradient in the theme's colours.
*/
const meta = preview.meta({
title: 'Blog/PostCard',
component: PostCard,
args: {
post: {
id: 1,
title: 'Shipping a SaaS in a weekend',
slug: 'shipping-a-saas-in-a-weekend',
excerpt:
'What we cut, what we kept, and the three modules that did most of the work.',
cover_url: '',
card_url: '',
published_at: '2026-11-20T09:00:00Z',
updated_at: null,
category: { name: 'Guides', slug: 'guides' },
tags: [
{ name: 'billing', slug: 'billing' },
{ name: 'auth', slug: 'auth' },
],
author: { name: 'Ada Lovelace', avatar_url: null },
url: '/blog/shipping-a-saas-in-a-weekend',
content: null,
},
},
decorators: [
(Story) => (
<div className="max-w-sm">
<Story />
</div>
),
],
});
export default meta;

/** Every part filled in. */
export const Default = meta.story({
play: async ({ canvas }) => {
await expect(
canvas.getByRole('link', { name: 'Shipping a SaaS in a weekend' }),
).toBeVisible();
await expect(
canvas.getByRole('link', { name: 'Guides' }),
).toBeVisible();
await expect(
canvas.getByRole('link', { name: '#billing' }),
).toBeVisible();
await expect(canvas.getByText('Ada Lovelace')).toBeVisible();
},
});

/** Only a title: no category, excerpt, tags or author. */
export const Minimal = meta.story({
args: {
post: {
id: 2,
title: 'Release notes: November',
slug: 'release-notes-november',
excerpt: null,
cover_url: '',
card_url: '',
published_at: null,
updated_at: null,
category: null,
tags: [],
author: null,
url: '/blog/release-notes-november',
content: null,
},
},
play: async ({ canvas }) => {
await expect(canvas.getAllByRole('link')).toHaveLength(1);
},
});
45 changes: 45 additions & 0 deletions resources/js/react/components/PostMeta.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import preview from '@/.storybook/preview';
import { expect } from 'storybook/test';
import PostMeta from './PostMeta';

/**
* Who wrote a post and when: the author's photo (or initial), name and date, in the
* visitor's language.
*/
const meta = preview.meta({
title: 'Blog/PostMeta',
component: PostMeta,
args: {
author: {
name: 'Ada Lovelace',
avatar_url: '/images/default-avatar.jpg',
},
publishedAt: '2026-11-20T09:00:00Z',
},
});
export default meta;

/** Photo, name and date. */
export const Default = meta.story({
play: async ({ canvas }) => {
await expect(canvas.getByText('Ada Lovelace')).toBeVisible();
await expect(canvas.getByText(/2026/)).toBeVisible();
},
});

/** An author without a photo: their initial. */
export const WithoutPhoto = meta.story({
args: { author: { name: 'Grace Hopper', avatar_url: null } },
play: async ({ canvas }) => {
await expect(canvas.getByText('G')).toBeVisible();
},
});

/** No author, a date only. */
export const WithoutAuthor = meta.story({
args: { author: null },
play: async ({ canvas }) => {
await expect(canvas.queryByText('Ada Lovelace')).toBeNull();
await expect(canvas.getByText(/2026/)).toBeVisible();
},
});
53 changes: 53 additions & 0 deletions resources/js/vue/components/CategoryNav.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import preview from '@/.storybook/preview';
import { expect } from 'storybook/test';
import CategoryNav from './CategoryNav.vue';

/**
* The blog's categories above its posts, with "All" first. The current one is filled.
* Renders nothing when the blog has no categories.
*/
const meta = preview.meta({
title: 'Blog/CategoryNav',
component: CategoryNav,
args: {
categories: [
{ name: 'Guides', slug: 'guides' },
{ name: 'Product', slug: 'product' },
{ name: 'Engineering', slug: 'engineering' },
],
active: null,
allActive: true,
},
});
export default meta;

/** On the blog's index: "All" is current. */
export const Default = meta.story({
play: async ({ canvas }) => {
await expect(canvas.getByRole('link', { name: 'All' })).toHaveAttribute(
'aria-current',
'page',
);
},
});

/** On a category's page: that category is current. */
export const CategorySelected = meta.story({
args: { active: 'product', allActive: false },
play: async ({ canvas }) => {
await expect(
canvas.getByRole('link', { name: 'Product' }),
).toHaveAttribute('aria-current', 'page');
await expect(
canvas.getByRole('link', { name: 'All' }),
).not.toHaveAttribute('aria-current');
},
});

/** No categories: nothing renders. */
export const Empty = meta.story({
args: { categories: [] },
play: async ({ canvas }) => {
await expect(canvas.queryByRole('navigation')).toBeNull();
},
});
75 changes: 75 additions & 0 deletions resources/js/vue/components/LatestPostsSection.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import preview from '@/.storybook/preview';
import { expect } from 'storybook/test';
import LatestPostsSection from './LatestPostsSection.vue';

/** The newest posts on another page, such as the home page, with a link to the blog. */
const meta = preview.meta({
title: 'Blog/LatestPostsSection',
component: LatestPostsSection,
parameters: { layout: 'fullscreen' },
args: {
posts: [
{
id: 1,
title: 'Shipping a SaaS in a weekend',
slug: 'shipping-a-saas-in-a-weekend',
excerpt:
'What we cut, what we kept, and the three modules that did most of the work.',
cover_url: '',
card_url: '',
published_at: '2026-11-20T09:00:00Z',
updated_at: null,
category: { name: 'Guides', slug: 'guides' },
tags: [],
author: { name: 'Ada Lovelace', avatar_url: null },
url: '/blog/shipping-a-saas-in-a-weekend',
content: null,
},
{
id: 2,
title: 'Why we moved billing to Stripe Checkout',
slug: 'stripe-checkout',
excerpt:
'Fewer forms to keep up to date, and tax handled for us.',
cover_url: '',
card_url: '',
published_at: '2026-11-12T09:00:00Z',
updated_at: null,
category: { name: 'Engineering', slug: 'engineering' },
tags: [{ name: 'billing', slug: 'billing' }],
author: { name: 'Grace Hopper', avatar_url: null },
url: '/blog/stripe-checkout',
content: null,
},
{
id: 3,
title: 'Release notes: November',
slug: 'release-notes-november',
excerpt: null,
cover_url: '',
card_url: '',
published_at: '2026-11-01T09:00:00Z',
updated_at: null,
category: { name: 'Product', slug: 'product' },
tags: [],
author: null,
url: '/blog/release-notes-november',
content: null,
},
],
},
});
export default meta;

/** Three posts and the link to the blog. */
export const Default = meta.story({
play: async ({ canvas }) => {
await expect(
canvas.getByRole('heading', { name: 'From the blog' }),
).toBeVisible();
await expect(canvas.getAllByRole('article')).toHaveLength(3);
await expect(
canvas.getByRole('link', { name: /View all/ }),
).toBeVisible();
},
});
Loading