From 2155550fa36a3bc3c8f66e0926530123b4018cd4 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 16 May 2022 12:46:38 +0200 Subject: refactor: use custom hook for breadcrumb items and schema --- .../sectioned/sectioned-layout.stories.tsx | 24 +++++++++++++--------- .../templates/sectioned/sectioned-layout.test.tsx | 9 +++++++- .../templates/sectioned/sectioned-layout.tsx | 8 ++++---- 3 files changed, 26 insertions(+), 15 deletions(-) (limited to 'src/components/templates/sectioned') diff --git a/src/components/templates/sectioned/sectioned-layout.stories.tsx b/src/components/templates/sectioned/sectioned-layout.stories.tsx index 9ff3b75..ce31a83 100644 --- a/src/components/templates/sectioned/sectioned-layout.stories.tsx +++ b/src/components/templates/sectioned/sectioned-layout.stories.tsx @@ -1,5 +1,4 @@ import { ComponentMeta, ComponentStory } from '@storybook/react'; -import { IntlProvider } from 'react-intl'; import SectionedLayoutComponent from './sectioned-layout'; /** @@ -8,7 +7,21 @@ import SectionedLayoutComponent from './sectioned-layout'; export default { title: 'Templates/Sectioned', component: SectionedLayoutComponent, + args: { + breadcrumbSchema: [], + }, argTypes: { + breadcrumbSchema: { + control: { + type: null, + }, + description: 'The JSON schema for breadcrumb items.', + type: { + name: 'object', + required: true, + value: {}, + }, + }, sections: { description: 'The different sections.', type: { @@ -18,15 +31,6 @@ export default { }, }, }, - decorators: [ - (Story) => ( - -
- -
-
- ), - ], parameters: { layout: 'fullscreen', }, diff --git a/src/components/templates/sectioned/sectioned-layout.test.tsx b/src/components/templates/sectioned/sectioned-layout.test.tsx index 334d1cc..9b8bab5 100644 --- a/src/components/templates/sectioned/sectioned-layout.test.tsx +++ b/src/components/templates/sectioned/sectioned-layout.test.tsx @@ -1,6 +1,8 @@ import { render, screen } from '@test-utils'; +import { BreadcrumbList } from 'schema-dts'; import SectionedLayout from './sectioned-layout'; +const breadcrumbSchema: BreadcrumbList['itemListElement'][] = []; const sections = [ { title: 'Section 1', @@ -26,7 +28,12 @@ const sections = [ describe('SectionedLayout', () => { it('renders the correct number of section', () => { - render(); + render( + + ); expect(screen.getAllByRole('heading', { name: /^Section/ })).toHaveLength( sections.length ); diff --git a/src/components/templates/sectioned/sectioned-layout.tsx b/src/components/templates/sectioned/sectioned-layout.tsx index 36ca039..58d5ad0 100644 --- a/src/components/templates/sectioned/sectioned-layout.tsx +++ b/src/components/templates/sectioned/sectioned-layout.tsx @@ -3,11 +3,11 @@ import Section, { type SectionVariant, } from '@components/atoms/layout/section'; import { FC } from 'react'; -import Layout from '../layout/layout'; +import Layout, { type LayoutProps } from '../layout/layout'; export type Section = Pick; -export type SectionedLayoutProps = { +export type SectionedLayoutProps = Pick & { /** * An array of objects describing each section. */ @@ -19,7 +19,7 @@ export type SectionedLayoutProps = { * * Render a sectioned layout. */ -const SectionedLayout: FC = ({ sections }) => { +const SectionedLayout: FC = ({ sections, ...props }) => { const getSections = (items: SectionProps[]) => { return items.map((section, index) => { const variant: SectionVariant = index % 2 ? 'light' : 'dark'; @@ -37,7 +37,7 @@ const SectionedLayout: FC = ({ sections }) => { }); }; - return {getSections(sections)}; + return {getSections(sections)}; }; export default SectionedLayout; -- cgit v1.2.3