aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/organisms/post-preview/post-preview.test.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-06 18:08:04 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-11 18:15:27 +0100
commitc9c1c90b30e243563bb4f731da15b3fe657556d2 (patch)
tree8263c176b4096e2893b9d9319bfa7edb01fce188 /src/components/organisms/post-preview/post-preview.test.tsx
parent2771de88f40a5f4ed7480bd8614532dda72deeda (diff)
refactor(components): replace Summary component with PostPreview
* rename component to PostPreview because Summary is an HTML element and it could lead to confusion * replace `title` and `titleLevel` with `heading` and `headingLvl` because `title` is a native attribute * rename `intro` prop to `excerpt` * extract `cover` from `meta` prop * rewrite meta type * extract meta logic into a new component
Diffstat (limited to 'src/components/organisms/post-preview/post-preview.test.tsx')
-rw-r--r--src/components/organisms/post-preview/post-preview.test.tsx66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/components/organisms/post-preview/post-preview.test.tsx b/src/components/organisms/post-preview/post-preview.test.tsx
new file mode 100644
index 0000000..78012ed
--- /dev/null
+++ b/src/components/organisms/post-preview/post-preview.test.tsx
@@ -0,0 +1,66 @@
+import { describe, expect, it } from '@jest/globals';
+import NextImage from 'next/image';
+import { render, screen as rtlScreen } from '../../../../tests/utils';
+import { PostPreview } from './post-preview';
+import type { PostPreviewMetaData } from './post-preview-meta';
+
+describe('PostPreview', () => {
+ it('renders an excerpt with a heading and a link', () => {
+ const excerpt = 'At necessitatibus id soluta adipisci quibusdam.';
+ const heading = 'impedit et ea';
+ const url = '#quia';
+
+ render(<PostPreview excerpt={excerpt} heading={heading} url={url} />);
+
+ expect(rtlScreen.getByRole('heading')).toHaveTextContent(heading);
+ expect(rtlScreen.getByRole('link', { name: heading })).toHaveAttribute(
+ 'href',
+ url
+ );
+ expect(rtlScreen.getByText(excerpt)).toBeInTheDocument();
+ });
+
+ it('can render a cover', () => {
+ const excerpt = 'At necessitatibus id soluta adipisci quibusdam.';
+ const heading = 'impedit et ea';
+ const url = '#quia';
+ const altTxt = 'alias consequatur quod';
+
+ render(
+ <PostPreview
+ cover={
+ <NextImage
+ alt={altTxt}
+ height={480}
+ src="https://picsum.photos/640/480"
+ width={640}
+ />
+ }
+ excerpt={excerpt}
+ heading={heading}
+ url={url}
+ />
+ );
+
+ expect(rtlScreen.getByRole('img')).toHaveAccessibleName(altTxt);
+ });
+
+ it('can render some meta', () => {
+ const excerpt = 'At necessitatibus id soluta adipisci quibusdam.';
+ const heading = 'impedit et ea';
+ const url = '#quia';
+ const meta = {
+ author: 'Noah_Gleason48',
+ publicationDate: '2023',
+ wordsCount: 250,
+ } satisfies PostPreviewMetaData;
+
+ render(
+ <PostPreview excerpt={excerpt} heading={heading} meta={meta} url={url} />
+ );
+
+ expect(rtlScreen.getAllByRole('term')).toHaveLength(
+ Object.keys(meta).length
+ );
+ });
+});