@amsterdam/design-system-react
Version:
All React components from the Amsterdam Design System. Use it to compose pages in your website or application.
47 lines (46 loc) • 2.13 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 { ariaRoleForTag } from '../common/accessibility';
import { Spotlight, spotlightColors, spotlightTags } from './Spotlight';
import '@testing-library/jest-dom';
describe('Spotlight', () => {
it('renders', () => {
const { container } = render(_jsx(Spotlight, {}));
const component = container.querySelector(':only-child');
expect(component).toBeInTheDocument();
expect(component).toBeVisible();
});
it('renders a design system BEM class name', () => {
const { container } = render(_jsx(Spotlight, {}));
const component = container.querySelector(':only-child');
expect(component).toHaveClass('ams-spotlight');
});
it('renders an extra class name', () => {
const { container } = render(_jsx(Spotlight, { className: "extra" }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass('ams-spotlight extra');
});
spotlightTags.forEach((tag) => {
it(`renders with a custom ${tag} tag`, () => {
const { container } = render(_jsx(Spotlight, { "aria-label": tag === 'section' ? 'Accessible name' : undefined, as: tag }));
const component = tag === 'div' ? container.querySelector(tag) : screen.getByRole(ariaRoleForTag[tag]);
expect(component).toBeInTheDocument();
});
});
it('supports ForwardRef in React', () => {
const ref = createRef();
const { container } = render(_jsx(Spotlight, { ref: ref }));
const component = container.querySelector(':only-child');
expect(ref.current).toBe(component);
});
spotlightColors.map((color) => it(`renders with ${color} color`, () => {
const { container } = render(_jsx(Spotlight, { color: color }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass(`ams-spotlight--${color}`);
}));
});