UNPKG

@amsterdam/design-system-react

Version:

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

73 lines (72 loc) 3.57 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 { createRef } from 'react'; import { describe, expect, it } from 'vitest'; import { TabNavigation } from './TabNavigation'; describe('TabNavigation', () => { it('renders', () => { render(_jsx(TabNavigation, {})); const component = screen.getByRole('navigation'); expect(component).toBeInTheDocument(); expect(component).toBeVisible(); }); it('renders a design system BEM class name', () => { render(_jsx(TabNavigation, {})); const component = screen.getByRole('navigation'); expect(component).toHaveClass('ams-tab-navigation'); }); it('renders an extra class name', () => { render(_jsx(TabNavigation, { className: "extra" })); const component = screen.getByRole('navigation'); expect(component).toHaveClass('ams-tab-navigation extra'); }); it('renders the default accessible name for the navigation', () => { render(_jsx(TabNavigation, {})); const component = screen.getByRole('navigation', { name: 'Navigatie' }); expect(component).toBeInTheDocument(); }); it('renders an accessible name for the navigation', () => { render(_jsx(TabNavigation, { accessibleName: "Test accessible name" })); const component = screen.getByRole('navigation', { name: 'Test accessible name' }); expect(component).toBeInTheDocument(); }); it('sets a custom id for the accessible name', () => { render(_jsx(TabNavigation, { accessibleNameId: "test-accessible-name-id" })); const component = screen.getByRole('navigation', { name: 'Navigatie' }); expect(component).toHaveAttribute('aria-labelledby', 'test-accessible-name-id'); }); it('renders children', () => { render(_jsx(TabNavigation, { children: _jsxs(TabNavigation.List, { children: [_jsx(TabNavigation.Link, { href: "/one", children: "One" }), _jsx(TabNavigation.Link, { href: "/two", children: "Two" })] }) })); const navigation = screen.getByRole('navigation'); const links = screen.getAllByRole('link'); expect(navigation).toBeInTheDocument(); expect(links).toHaveLength(2); }); it('supports ForwardRef in React', () => { const ref = createRef(); const { container } = render(_jsx(TabNavigation, { ref: ref })); const component = container.querySelector(':only-child'); expect(ref.current).toBe(component); }); it('renders a vertical variant', () => { render(_jsx(TabNavigation, { orientation: "vertical" })); const component = screen.getByRole('navigation'); expect(component).toHaveClass('ams-tab-navigation--vertical'); }); it('does not render the vertical class for horizontal orientation', () => { render(_jsx(TabNavigation, { orientation: "horizontal" })); const component = screen.getByRole('navigation'); expect(component).not.toHaveClass('ams-tab-navigation--vertical'); }); it('passes additional props', () => { render(_jsx(TabNavigation, { "aria-hidden": false, "data-test": "data-test", id: "id" })); const component = screen.getByRole('navigation'); expect(component).toHaveAttribute('aria-hidden', 'false'); expect(component).toHaveAttribute('id', 'id'); expect(component).toHaveAttribute('data-test', 'data-test'); }); });