-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjects.spec.tsx
More file actions
100 lines (81 loc) · 3.46 KB
/
Copy pathProjects.spec.tsx
File metadata and controls
100 lines (81 loc) · 3.46 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import ProjectPage from './Projects';
import styles from './projects.module.scss';
import { PROJECTS_PATH } from 'app/routePaths';
import { meta as projectsMeta } from 'routes/projects';
import { renderApp } from 'utils/testing/renderApp';
describe('Projects page', () => {
it('should render projects heading and divider', () => {
renderApp(<ProjectPage />);
expect(
screen.getByRole('heading', { name: /projects/i }),
).toBeInTheDocument();
expect(document.querySelector('.divider')).toBeInTheDocument();
});
it('should render the main projects container with correct class', () => {
const { container } = renderApp(<ProjectPage />);
const mainElement = container.querySelector('main');
expect(mainElement).toBeInTheDocument();
expect(mainElement).toHaveClass(styles.projects);
const projectsItemsContainer = container.querySelector(
`.${styles.projectsItemsContainer}`,
);
expect(projectsItemsContainer).toBeInTheDocument();
});
it('should render all project items', () => {
renderApp(<ProjectPage />);
const getHeading = (name: RegExp): HTMLElement =>
screen.getByRole('heading', { level: 3, name });
expect(getHeading(/reactplate/i)).toBeInTheDocument();
expect(getHeading(/threshold-elgamal/i)).toBeInTheDocument();
expect(getHeading(/sealed\.vote/i)).toBeInTheDocument();
expect(getHeading(/expressplate/i)).toBeInTheDocument();
expect(getHeading(/aliases\.sh/i)).toBeInTheDocument();
expect(
getHeading(/Battle Brothers Legends build planner/i),
).toBeInTheDocument();
});
it('prioritizes only the first project grid image', () => {
renderApp(<ProjectPage />);
const lcpImage = screen.getByAltText('threshold-elgamal preview');
const laterImage = screen.getByAltText('reactplate preview');
expect(lcpImage).toHaveAttribute('fetchpriority', 'high');
expect(lcpImage).not.toHaveAttribute('loading');
expect(laterImage).toHaveAttribute('loading', 'lazy');
expect(laterImage).toHaveAttribute('decoding', 'async');
});
it('should include a divider between project items', () => {
const { container } = renderApp(<ProjectPage />);
const dividers = container.querySelectorAll('.divider');
expect(dividers.length).toBeGreaterThan(1);
});
it('exposes correct meta for Projects route', () => {
const metaArgs = {
params: {},
data: null,
location: {
pathname: PROJECTS_PATH,
search: '',
hash: '',
state: null,
key: 'test',
unstable_mask: undefined,
},
loaderData: {} as Record<string, never>,
matches: [],
} satisfies Parameters<typeof projectsMeta>[0];
const tags = projectsMeta(metaArgs);
expect(tags).toEqual(
expect.arrayContaining([
{ title: 'Projects | piech.dev' },
expect.objectContaining({
tagName: 'link',
rel: 'canonical',
href: 'https://piech.dev/projects/',
}),
expect.objectContaining({ name: 'description' }),
]),
);
});
});