blob: 78012ed087dfc2055f005b5fe0e3aff1484488fa (
plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
);
});
});
|