Repository navigation
Expand file tree
/
Copy pathUiLibraryPage.test.tsx
More file actions
73 lines (54 loc) · 2.59 KB
/
Copy pathUiLibraryPage.test.tsx
File metadata and controls
73 lines (54 loc) · 2.59 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
import { screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it } from 'vitest';
import { renderWithRoutes } from '@ValenceLanding/testing/renderWithRoutes';
import { UiLibraryPage } from './UiLibraryPage';
describe('UiLibraryPage', () => {
it('introduces itself and lists the groups when no component is chosen', async () => {
await renderWithRoutes(UiLibraryPage, '/ui');
expect(
await screen.findByRole('heading', {
level: 1,
name: 'The parts the Valence web apps are built from',
}),
).toBeInTheDocument();
expect(screen.getAllByRole('link', { name: /Buttons/ }).length).toBeGreaterThan(0);
});
it('shows a component, its examples and its props, read from its source', async () => {
await renderWithRoutes(UiLibraryPage, '/ui/button');
expect(await screen.findByRole('heading', { level: 1, name: 'Button' })).toBeInTheDocument();
expect(screen.getByText('Variants')).toBeInTheDocument();
const props = screen.getByRole('table', { name: 'Props of Button' });
expect(within(props).getByRole('row', { name: /variant/ })).toBeInTheDocument();
});
it('marks the component being looked at in the list', async () => {
await renderWithRoutes(UiLibraryPage, '/ui/badge');
const list = await screen.findAllByRole('navigation', { name: 'Components' });
expect(within(list[0] ?? document.body).getByRole('link', { name: 'Badge' })).toHaveAttribute(
'aria-current',
'page',
);
});
it('narrows the list to what is typed', async () => {
await renderWithRoutes(UiLibraryPage, '/ui');
const [search] = await screen.findAllByRole('searchbox', { name: 'Find a component' });
await userEvent.type(search ?? document.body, 'spinn', { delay: null });
const [list] = screen.getAllByRole('navigation', { name: 'Components' });
expect(
within(list ?? document.body)
.getAllByRole('link')
.map((link) => link.textContent),
).toEqual(['Spinner']);
});
it('says so when the address names no component', async () => {
await renderWithRoutes(UiLibraryPage, '/ui/nothing-here');
expect(
await screen.findByRole('heading', { name: 'There is no component called nothing-here' }),
).toBeInTheDocument();
});
it('opens the list in a drawer on a phone', async () => {
await renderWithRoutes(UiLibraryPage, '/ui/button');
await userEvent.click(await screen.findByRole('button', { name: 'All components' }));
expect(await screen.findByRole('dialog', { name: 'Components' })).toBeInTheDocument();
});
});