UNPKG

@amsterdam/design-system-react

Version:

All React components from the Amsterdam Design System. Use it to compose pages in your website or application.

45 lines (44 loc) 2.08 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /** * @license EUPL-1.2+ * Copyright Gemeente Amsterdam */ import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { createRef } from 'react'; import { Accordion } from './Accordion'; import '@testing-library/jest-dom'; describe('Accordion', () => { it('renders an accordion', () => { const { container } = render(_jsx(Accordion, { headingLevel: 2 })); const accordion = container.querySelector('.ams-accordion'); expect(accordion).toBeInTheDocument(); expect(accordion).toBeVisible(); }); it('renders an extra class name', () => { const { container } = render(_jsx(Accordion, { className: "test", headingLevel: 2 })); const accordion = container.querySelector('.ams-accordion'); expect(accordion).toHaveClass('test'); }); it('sets focus on Accordion buttons when using arrow keys', async () => { const user = userEvent.setup(); render(_jsxs(Accordion, { headingLevel: 2, children: [_jsx(Accordion.Section, { label: "one" }), _jsx(Accordion.Section, { label: "two" }), _jsx(Accordion.Section, { label: "three" })] })); const firstButton = screen.getByRole('button', { name: 'one' }); const thirdButton = screen.getByRole('button', { name: 'three' }); await user.click(firstButton); expect(firstButton).toHaveFocus(); // Click the down arrow key twice await user.keyboard('{ArrowDown}'); await user.keyboard('{ArrowDown}'); expect(thirdButton).toHaveFocus(); expect(firstButton).not.toHaveFocus(); await user.keyboard('{ArrowDown}'); expect(firstButton).toHaveFocus(); }); it('supports ForwardRef in React', () => { const ref = createRef(); const { container } = render(_jsx(Accordion, { headingLevel: 2, ref: ref })); const accordion = container.querySelector('.ams-accordion'); expect(ref.current).toBe(accordion); }); });