@amsterdam/design-system-react
Version:
All React components from the Amsterdam Design System. Use it to compose pages in your website or application.
54 lines (53 loc) • 2.47 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
/**
* @license EUPL-1.2+
* Copyright Gemeente Amsterdam
*/
import { DocumentIcon, StarIcon } from '@amsterdam/design-system-react-icons';
import { render, screen } from '@testing-library/react';
import { createRef } from 'react';
import { describe, expect, it } from 'vitest';
import { Menu } from './Menu';
describe('MenuLink', () => {
it('renders', () => {
const { container } = render(_jsx(Menu.Link, { href: "#", icon: DocumentIcon }));
const listItem = screen.getByRole('listitem');
const link = screen.getByRole('link');
const icon = container.querySelector('svg');
expect(listItem).toBeInTheDocument();
expect(listItem).toBeVisible();
expect(link).toBeInTheDocument();
expect(link).toBeVisible();
expect(icon).toBeInTheDocument();
expect(icon).not.toBeVisible(); // The icon is hidden by default, and only shown when the CSS loads.
});
it('renders a design system BEM class name', () => {
render(_jsx(Menu.Link, { href: "#", icon: DocumentIcon }));
const component = screen.getByRole('link');
expect(component).toHaveClass('ams-menu__link');
});
it('renders an extra class name', () => {
render(_jsx(Menu.Link, { className: "extra", href: "#", icon: DocumentIcon }));
const component = screen.getByRole('link');
expect(component).toHaveClass('ams-menu__link extra');
});
it('supports ForwardRef in React', () => {
const ref = createRef();
render(_jsx(Menu.Link, { href: "#", icon: DocumentIcon, ref: ref }));
const component = screen.getByRole('link');
expect(ref.current).toBe(component);
});
it('shows a custom icon', () => {
render(_jsx(Menu.Link, { href: "#", icon: _jsx(StarIcon, { className: "test-class" }) }));
const component = screen.getByRole('link');
const icon = component.querySelector('.test-class');
expect(icon).toBeInTheDocument();
});
it('passes additional props', () => {
render(_jsx(Menu.Link, { "aria-hidden": "false", "data-test": "data-test", href: "#", icon: DocumentIcon, id: "id" }));
const component = screen.getByRole('link');
expect(component).toHaveAttribute('aria-hidden', 'false');
expect(component).toHaveAttribute('id', 'id');
expect(component).toHaveAttribute('data-test', 'data-test');
});
});