From 5dacbbf060fffcf0046225ba768060558a552147 Mon Sep 17 00:00:00 2001 From: roble Date: Thu, 26 Nov 2026 21:00:52 +0000 Subject: [PATCH] feat: stories for PostCard, CategoryNav, PostMeta and LatestPostsSection Co-Authored-By: Claude Opus 5.5 --- .../react/components/CategoryNav.stories.tsx | 53 ++++++++++++ .../components/LatestPostsSection.stories.tsx | 75 +++++++++++++++++ .../js/react/components/PostCard.stories.tsx | 83 +++++++++++++++++++ .../js/react/components/PostMeta.stories.tsx | 45 ++++++++++ .../js/vue/components/CategoryNav.stories.ts | 53 ++++++++++++ .../components/LatestPostsSection.stories.ts | 75 +++++++++++++++++ .../js/vue/components/PostCard.stories.ts | 77 +++++++++++++++++ .../js/vue/components/PostMeta.stories.ts | 45 ++++++++++ 8 files changed, 506 insertions(+) create mode 100644 resources/js/react/components/CategoryNav.stories.tsx create mode 100644 resources/js/react/components/LatestPostsSection.stories.tsx create mode 100644 resources/js/react/components/PostCard.stories.tsx create mode 100644 resources/js/react/components/PostMeta.stories.tsx create mode 100644 resources/js/vue/components/CategoryNav.stories.ts create mode 100644 resources/js/vue/components/LatestPostsSection.stories.ts create mode 100644 resources/js/vue/components/PostCard.stories.ts create mode 100644 resources/js/vue/components/PostMeta.stories.ts diff --git a/resources/js/react/components/CategoryNav.stories.tsx b/resources/js/react/components/CategoryNav.stories.tsx new file mode 100644 index 0000000..b931b0d --- /dev/null +++ b/resources/js/react/components/CategoryNav.stories.tsx @@ -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(); + }, +}); diff --git a/resources/js/react/components/LatestPostsSection.stories.tsx b/resources/js/react/components/LatestPostsSection.stories.tsx new file mode 100644 index 0000000..183d7a6 --- /dev/null +++ b/resources/js/react/components/LatestPostsSection.stories.tsx @@ -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(); + }, +}); diff --git a/resources/js/react/components/PostCard.stories.tsx b/resources/js/react/components/PostCard.stories.tsx new file mode 100644 index 0000000..6899d69 --- /dev/null +++ b/resources/js/react/components/PostCard.stories.tsx @@ -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) => ( +
+ +
+ ), + ], +}); +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); + }, +}); diff --git a/resources/js/react/components/PostMeta.stories.tsx b/resources/js/react/components/PostMeta.stories.tsx new file mode 100644 index 0000000..a74f5f0 --- /dev/null +++ b/resources/js/react/components/PostMeta.stories.tsx @@ -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(); + }, +}); diff --git a/resources/js/vue/components/CategoryNav.stories.ts b/resources/js/vue/components/CategoryNav.stories.ts new file mode 100644 index 0000000..4a0116a --- /dev/null +++ b/resources/js/vue/components/CategoryNav.stories.ts @@ -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(); + }, +}); diff --git a/resources/js/vue/components/LatestPostsSection.stories.ts b/resources/js/vue/components/LatestPostsSection.stories.ts new file mode 100644 index 0000000..5172359 --- /dev/null +++ b/resources/js/vue/components/LatestPostsSection.stories.ts @@ -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(); + }, +}); diff --git a/resources/js/vue/components/PostCard.stories.ts b/resources/js/vue/components/PostCard.stories.ts new file mode 100644 index 0000000..7da0680 --- /dev/null +++ b/resources/js/vue/components/PostCard.stories.ts @@ -0,0 +1,77 @@ +import preview from '@/.storybook/preview'; +import { expect } from 'storybook/test'; +import PostCard from './PostCard.vue'; + +/** + * 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: [() => ({ template: '
' })], +}); +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); + }, +}); diff --git a/resources/js/vue/components/PostMeta.stories.ts b/resources/js/vue/components/PostMeta.stories.ts new file mode 100644 index 0000000..6e758d1 --- /dev/null +++ b/resources/js/vue/components/PostMeta.stories.ts @@ -0,0 +1,45 @@ +import preview from '@/.storybook/preview'; +import { expect } from 'storybook/test'; +import PostMeta from './PostMeta.vue'; + +/** + * 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(); + }, +});