1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import { describe, expect, it } from '@jest/globals';
import { render, screen } from '../../../../tests/utils';
import { Comment } from './comment';
import {
author,
data,
formattedDate,
formattedTime,
id,
} from './comment.fixture';
describe('Comment', () => {
it('renders an avatar', () => {
render(<Comment canReply={true} {...data} />);
expect(
screen.getByRole('img', { name: author.avatar.alt })
).toBeInTheDocument();
});
it('renders the author website url', () => {
render(<Comment canReply={true} {...data} />);
expect(screen.getByRole('link', { name: author.name })).toHaveAttribute(
'href',
author.website
);
});
it('renders a permalink to the comment', () => {
render(<Comment canReply={true} {...data} />);
expect(
screen.getByRole('link', {
name: `${formattedDate} at ${formattedTime}`,
})
).toHaveAttribute('href', `#comment-${id}`);
});
it('renders a reply button', () => {
render(<Comment canReply={true} {...data} />);
expect(screen.getByRole('button', { name: 'Reply' })).toBeInTheDocument();
});
it('does not render a reply button', () => {
render(<Comment canReply={false} {...data} />);
expect(
screen.queryByRole('button', { name: 'Reply' })
).not.toBeInTheDocument();
});
});
|