summaryrefslogtreecommitdiffstats
path: root/src/components/organisms/layout/comment.test.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-23 14:07:02 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-23 16:00:13 +0200
commit34e216546151eaf8a0a3cbb0bc8b65dae4c63bf2 (patch)
treebff34f8a1dc65f0559ddf851433f242edb092824 /src/components/organisms/layout/comment.test.tsx
parent0f8f963ba3eccd7fd94785bf7fb216b6287cec57 (diff)
refactor: reduce the number of data transformation
Diffstat (limited to 'src/components/organisms/layout/comment.test.tsx')
-rw-r--r--src/components/organisms/layout/comment.test.tsx39
1 files changed, 11 insertions, 28 deletions
diff --git a/src/components/organisms/layout/comment.test.tsx b/src/components/organisms/layout/comment.test.tsx
index 02a51dc..490a52b 100644
--- a/src/components/organisms/layout/comment.test.tsx
+++ b/src/components/organisms/layout/comment.test.tsx
@@ -1,48 +1,31 @@
import { render, screen } from '@test-utils';
-import { getFormattedDate, getFormattedTime } from '@utils/helpers/dates';
import Comment from './comment';
-
-const author = {
- avatar: 'http://placeimg.com/640/480',
- name: 'Your name',
- url: 'https://www.example.test/',
-};
-const content =
- 'Harum aut cumque iure fugit neque sequi cupiditate repudiandae laudantium. Ratione aut assumenda qui illum voluptas accusamus quis officiis exercitationem. Consectetur est harum eius perspiciatis officiis nihil. Aut corporis minima debitis adipisci possimus debitis et.';
-const publication = '2021-04-03 23:04:24';
-const id = 5;
-const saveComment = async () => {
- /** Do nothing. */
-};
-const data = {
+import {
author,
- content,
+ data,
+ formattedDate,
+ formattedTime,
id,
- publication,
- saveComment,
-};
-
-const formattedDate = getFormattedDate(publication);
-const formattedTime = getFormattedTime(publication);
+} from './comment.fixture';
describe('Comment', () => {
it('renders an avatar', () => {
- render(<Comment {...data} />);
+ render(<Comment canReply={true} {...data} />);
expect(
screen.getByRole('img', { name: 'Your name avatar' })
).toBeInTheDocument();
});
it('renders the author website url', () => {
- render(<Comment {...data} />);
+ render(<Comment canReply={true} {...data} />);
expect(screen.getByRole('link', { name: author.name })).toHaveAttribute(
'href',
- author.url
+ author.website
);
});
it('renders a permalink to the comment', () => {
- render(<Comment {...data} />);
+ render(<Comment canReply={true} {...data} />);
expect(
screen.getByRole('link', {
name: `${formattedDate} at ${formattedTime}`,
@@ -51,12 +34,12 @@ describe('Comment', () => {
});
it('renders a reply button', () => {
- render(<Comment {...data} canReply={true} />);
+ render(<Comment canReply={true} {...data} />);
expect(screen.getByRole('button', { name: 'Reply' })).toBeInTheDocument();
});
it('does not render a reply button', () => {
- render(<Comment {...data} canReply={false} />);
+ render(<Comment canReply={false} {...data} />);
expect(
screen.queryByRole('button', { name: 'Reply' })
).not.toBeInTheDocument();