From c9c1c90b30e243563bb4f731da15b3fe657556d2 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Mon, 6 Nov 2023 18:08:04 +0100
Subject: 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
---
 .../organisms/post-preview/post-preview.test.tsx   | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 src/components/organisms/post-preview/post-preview.test.tsx

(limited to 'src/components/organisms/post-preview/post-preview.test.tsx')

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
+    );
+  });
+});
-- 
cgit v1.2.3

