@amsterdam/design-system-react
Version:
All React components from the Amsterdam Design System. Use it to compose pages in your website or application.
70 lines (69 loc) • 3.25 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 { Grid, gridGaps, gridPaddings, gridTags } from './Grid';
import '@testing-library/jest-dom';
describe('Grid', () => {
it('renders', () => {
const { container } = render(_jsx(Grid, {}));
const component = container.querySelector(':only-child');
expect(component).toBeInTheDocument();
expect(component).toBeVisible();
});
it('renders a design system BEM class name', () => {
const { container } = render(_jsx(Grid, {}));
const component = container.querySelector(':only-child');
expect(component).toHaveClass('ams-grid');
});
it('renders an extra class name', () => {
const { container } = render(_jsx(Grid, { className: "extra" }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass('ams-grid extra');
});
gridGaps.forEach((size) => {
it(`renders the correct class name for a ${size} vertical gap`, () => {
const { container } = render(_jsx(Grid, { gapVertical: size }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass(`ams-grid--gap-vertical--${size}`);
});
});
gridPaddings.forEach((size) => {
it(`renders the correct class name for a ${size} bottom padding`, () => {
const { container } = render(_jsx(Grid, { paddingBottom: size }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass(`ams-grid--padding-bottom--${size}`);
});
});
gridPaddings.forEach((size) => {
it(`renders the correct class name for a ${size} top padding`, () => {
const { container } = render(_jsx(Grid, { paddingTop: size }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass(`ams-grid--padding-top--${size}`);
});
});
gridPaddings.forEach((size) => {
it(`renders the correct class name for a ${size} vertical padding`, () => {
const { container } = render(_jsx(Grid, { paddingVertical: size }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass(`ams-grid--padding-vertical--${size}`);
});
});
gridTags.forEach((tag) => {
it(`renders with a custom ${tag} tag`, () => {
const { container } = render(_jsx(Grid, { "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(Grid, { ref: ref }));
const component = container.querySelector(':only-child');
expect(ref.current).toBe(component);
});
});