diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-23 14:07:02 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-23 16:00:13 +0200 |
| commit | 34e216546151eaf8a0a3cbb0bc8b65dae4c63bf2 (patch) | |
| tree | bff34f8a1dc65f0559ddf851433f242edb092824 /src/components/organisms/layout/summary.test.tsx | |
| parent | 0f8f963ba3eccd7fd94785bf7fb216b6287cec57 (diff) | |
refactor: reduce the number of data transformation
Diffstat (limited to 'src/components/organisms/layout/summary.test.tsx')
| -rw-r--r-- | src/components/organisms/layout/summary.test.tsx | 44 |
1 files changed, 10 insertions, 34 deletions
diff --git a/src/components/organisms/layout/summary.test.tsx b/src/components/organisms/layout/summary.test.tsx index 9e34254..7617c26 100644 --- a/src/components/organisms/layout/summary.test.tsx +++ b/src/components/organisms/layout/summary.test.tsx @@ -1,35 +1,12 @@ import { render, screen } from '@test-utils'; import Summary from './summary'; - -const cover = { - alt: 'A cover', - height: 480, - src: 'http://placeimg.com/640/480', - width: 640, -}; - -const excerpt = - 'Perspiciatis quasi libero nemo non eligendi nam minima. Deleniti expedita tempore. Praesentium explicabo molestiae eaque consectetur vero. Quae nostrum quisquam similique. Ut hic est quas ut esse quisquam nobis.'; - -const meta = { - dates: { publication: '2022-04-11' }, - readingTime: { wordsCount: excerpt.split(' ').length }, - thematics: [ - { id: 'cat-1', name: 'Cat 1', url: '#' }, - { id: 'cat-2', name: 'Cat 2', url: '#' }, - ], - commentsCount: 1, -}; - -const title = 'Odio odit necessitatibus'; - -const url = '#'; +import { cover, intro, meta, title, url } from './summary.fixture'; describe('Summary', () => { it('renders a title wrapped in a h2 element', () => { render( <Summary - excerpt={excerpt} + intro={intro} meta={meta} title={title} titleLevel={2} @@ -42,16 +19,15 @@ describe('Summary', () => { }); it('renders an excerpt', () => { - render(<Summary excerpt={excerpt} meta={meta} title={title} url={url} />); - expect(screen.getByText(excerpt)).toBeInTheDocument(); + render(<Summary intro={intro} meta={meta} title={title} url={url} />); + expect(screen.getByText(intro)).toBeInTheDocument(); }); it('renders a cover', () => { render( <Summary - cover={cover} - excerpt={excerpt} - meta={meta} + intro={intro} + meta={{ ...meta, cover }} title={title} url={url} /> @@ -60,19 +36,19 @@ describe('Summary', () => { }); it('renders a link to the full post', () => { - render(<Summary excerpt={excerpt} meta={meta} title={title} url={url} />); + render(<Summary intro={intro} meta={meta} title={title} url={url} />); expect(screen.getByRole('link', { name: title })).toBeInTheDocument(); }); it('renders a read more link', () => { - render(<Summary excerpt={excerpt} meta={meta} title={title} url={url} />); + render(<Summary intro={intro} meta={meta} title={title} url={url} />); expect( screen.getByRole('link', { name: `Read more about ${title}` }) ).toBeInTheDocument(); }); it('renders some meta', () => { - render(<Summary excerpt={excerpt} meta={meta} title={title} url={url} />); - expect(screen.getByText(meta.thematics[0].name)).toBeInTheDocument(); + render(<Summary intro={intro} meta={meta} title={title} url={url} />); + expect(screen.getByText(meta.thematics![0].name)).toBeInTheDocument(); }); }); |
