Skip to content

Commit 9d784ed

Browse files
authored
test: add breadcrumb tests (#2029)
* test: add breadcrumb tests * chore: add breadcrumb kitchen sink * chore: update snaos
1 parent 56c3235 commit 9d784ed

File tree

5 files changed

+1146
-0
lines changed

5 files changed

+1146
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { composeStories } from '@storybook/react';
2+
import * as BreadcrumbStories from './Breadcrumb.stories';
3+
import { Box } from '~components/Box';
4+
import { Heading } from '~components/Typography';
5+
6+
const allStories = Object.values(composeStories(BreadcrumbStories));
7+
8+
export const Breadcrumb = (): JSX.Element => {
9+
return (
10+
<Box display="flex" flexDirection="column" gap="spacing.4">
11+
{allStories.map((Story) => {
12+
return (
13+
<>
14+
<Heading>{Story.storyName}</Heading>
15+
<Story />
16+
</>
17+
);
18+
})}
19+
</Box>
20+
);
21+
};
22+
23+
export default {
24+
title: 'Components/KitchenSink/Breadcrumb',
25+
component: Breadcrumb,
26+
parameters: {
27+
// enable Chromatic's snapshotting only for kitchensink
28+
chromatic: { disableSnapshot: false },
29+
options: { showPanel: false },
30+
},
31+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Breadcrumb, BreadcrumbItem } from '../';
2+
import { HomeIcon } from '~components/Icons';
3+
import renderWithSSR from '~utils/testing/renderWithSSR.web';
4+
5+
describe('<Breadcrumb />', () => {
6+
it('should render breadcrumb', () => {
7+
const { container } = renderWithSSR(
8+
<Breadcrumb showLastSeparator size="large">
9+
<BreadcrumbItem icon={HomeIcon} href="/">
10+
Home
11+
</BreadcrumbItem>
12+
<BreadcrumbItem href="/about">About</BreadcrumbItem>
13+
<BreadcrumbItem href="/contact" isCurrentPage>
14+
Contact
15+
</BreadcrumbItem>
16+
</Breadcrumb>,
17+
);
18+
expect(container).toMatchSnapshot();
19+
});
20+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import userEvent from '@testing-library/user-event';
2+
import { Breadcrumb, BreadcrumbItem } from '../';
3+
import renderWithTheme from '~utils/testing/renderWithTheme.web';
4+
import assertAccessible from '~utils/testing/assertAccessible.web';
5+
6+
describe('<Breadcrumb />', () => {
7+
it('should render', () => {
8+
const { container } = renderWithTheme(
9+
<Breadcrumb>
10+
<BreadcrumbItem href="/">Home</BreadcrumbItem>
11+
<BreadcrumbItem href="/about">About</BreadcrumbItem>
12+
<BreadcrumbItem href="/contact">Contact</BreadcrumbItem>
13+
</Breadcrumb>,
14+
);
15+
16+
expect(container).toMatchSnapshot();
17+
});
18+
19+
test('current item should have aria-current', () => {
20+
const { container, getByText } = renderWithTheme(
21+
<Breadcrumb>
22+
<BreadcrumbItem href="/">Home</BreadcrumbItem>
23+
<BreadcrumbItem href="/about">About</BreadcrumbItem>
24+
<BreadcrumbItem href="/contact" isCurrentPage>
25+
Contact
26+
</BreadcrumbItem>
27+
</Breadcrumb>,
28+
);
29+
30+
expect(container).toMatchSnapshot();
31+
expect(getByText('Contact').closest('li')).toHaveAttribute('aria-current', 'page');
32+
});
33+
34+
test('should work with showLastSeparator', () => {
35+
const { container } = renderWithTheme(
36+
<Breadcrumb showLastSeparator>
37+
<BreadcrumbItem href="/">Home</BreadcrumbItem>
38+
<BreadcrumbItem href="/about">About</BreadcrumbItem>
39+
<BreadcrumbItem href="/contact">Contact</BreadcrumbItem>
40+
</Breadcrumb>,
41+
);
42+
43+
expect(container).toMatchSnapshot();
44+
});
45+
46+
test('should work with onClick', async () => {
47+
const onClick = jest.fn();
48+
const { getByText } = renderWithTheme(
49+
<Breadcrumb showLastSeparator>
50+
<BreadcrumbItem onClick={onClick} href="/home">
51+
Home
52+
</BreadcrumbItem>
53+
</Breadcrumb>,
54+
);
55+
const link = getByText('Home');
56+
await userEvent.click(link);
57+
expect(onClick).toHaveBeenCalledTimes(1);
58+
});
59+
60+
it('should pass a11y render', async () => {
61+
const { container } = renderWithTheme(
62+
<Breadcrumb>
63+
<BreadcrumbItem href="/">Home</BreadcrumbItem>
64+
<BreadcrumbItem href="/about">About</BreadcrumbItem>
65+
<BreadcrumbItem href="/contact">Contact</BreadcrumbItem>
66+
</Breadcrumb>,
67+
);
68+
69+
await assertAccessible(container);
70+
});
71+
});

0 commit comments

Comments
 (0)