@amsterdam/design-system-react
Version:
All React components from the Amsterdam Design System. Use it to compose pages in your website or application.
68 lines (67 loc) • 3.19 kB
JavaScript
import { jsx as _jsx } 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 { Menu } from './Menu';
describe('Menu', () => {
it('renders', () => {
const { container } = render(_jsx(Menu, {}));
const component = container.querySelector(':only-child');
const list = screen.getByRole('list');
expect(component).toBeInTheDocument();
expect(component).toBeVisible();
expect(component).toContainElement(list);
});
it('renders a design system BEM class name', () => {
const { container } = render(_jsx(Menu, {}));
const component = container.querySelector(':only-child');
expect(component).toHaveClass('ams-menu');
});
it('renders an extra class name', () => {
const { container } = render(_jsx(Menu, { className: "extra" }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass('ams-menu extra');
});
it('renders a `nav` element with the `inWideWindow` prop', () => {
render(_jsx(Menu, { inWideWindow: true }));
const component = screen.getByRole('navigation');
expect(component).toBeInTheDocument();
});
it('renders the class name for the `inWideWindow` prop', () => {
const { container } = render(_jsx(Menu, { inWideWindow: true }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass('ams-menu--in-wide-window');
});
it('supports ForwardRef in React', () => {
const ref = createRef();
const { container } = render(_jsx(Menu, { ref: ref }));
const component = container.querySelector(':only-child');
expect(ref.current).toBe(component);
});
it('renders the default accessible name', () => {
render(_jsx(Menu, { inWideWindow: true }));
const component = screen.getByRole('navigation', { name: 'Hoofdmenu' });
expect(component).toBeInTheDocument();
});
it('renders a custom accessible name', () => {
render(_jsx(Menu, { accessibleName: "Custom accessible name", inWideWindow: true }));
const component = screen.getByRole('navigation', { name: 'Custom accessible name' });
expect(component).toBeInTheDocument();
});
it('doesn’t render a custom accessible name if not in a wide window', () => {
render(_jsx(Menu, { accessibleName: "Custom accessible name" }));
const component = screen.queryByRole('navigation', { name: 'Custom accessible name' });
expect(component).not.toBeInTheDocument();
});
it('passes additional props', () => {
const { container } = render(_jsx(Menu, { "aria-hidden": "false", "data-test": "data-test", id: "id" }));
const component = container.querySelector(':only-child');
expect(component).toHaveAttribute('aria-hidden', 'false');
expect(component).toHaveAttribute('id', 'id');
expect(component).toHaveAttribute('data-test', 'data-test');
});
});