UNPKG

@amsterdam/design-system-react

Version:

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

41 lines (40 loc) 2.48 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { render, screen } from '@testing-library/react'; import { createRef } from 'react'; import { Tabs } from './Tabs'; import '@testing-library/jest-dom'; describe('Tabs Panel', () => { it('renders', () => { render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { tab: "one" }) }), _jsx(Tabs.Panel, { tab: "one" })] })); const component = screen.getByRole('tabpanel'); expect(component).toBeInTheDocument(); }); it('renders a design system BEM class name', () => { render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { tab: "one" }) }), _jsx(Tabs.Panel, { tab: "one" })] })); const component = screen.getByRole('tabpanel'); expect(component).toHaveClass('ams-tabs__panel'); }); it('renders an additional class name', () => { render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { tab: "one" }) }), _jsx(Tabs.Panel, { className: "extra", tab: "one" })] })); const component = screen.getByRole('tabpanel'); expect(component).toHaveClass('ams-tabs__panel extra'); }); it('renders the correct id based on the tabs prop', () => { const { container } = render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { tab: "one" }) }), _jsx(Tabs.Panel, { tab: "one" })] })); // The start of the id is generated by useId, so we only check the end of the id const component = container.querySelector('[id$="panel-one"]'); expect(component).toBeInTheDocument(); }); it('should associate the tab with the correct button', () => { render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { tab: "one" }) }), _jsx(Tabs.Panel, { tab: "one" })] })); const component = screen.getByRole('tabpanel'); // The start of the attribute value is generated by useId, so we only check the end of the value expect(component).toHaveAttribute('aria-labelledby', expect.stringMatching(/-tab-one$/)); }); it('supports ForwardRef in React', () => { const ref = createRef(); render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { tab: "one" }) }), _jsx(Tabs.Panel, { ref: ref, tab: "one" })] })); const component = screen.getByRole('tabpanel'); expect(ref.current).toBe(component); }); });