|
| 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