UNPKG

@amsterdam/design-system-react

Version:

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

64 lines (63 loc) 3.09 kB
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 { FieldSet } from './FieldSet'; import '@testing-library/jest-dom'; describe('FieldSet', () => { it('renders', () => { render(_jsx(FieldSet, { legend: "Test" })); const component = screen.getByRole('group', { name: 'Test' }); expect(component).toBeInTheDocument(); expect(component).toBeVisible(); }); it('renders a design system BEM class name', () => { render(_jsx(FieldSet, { legend: "Test" })); const component = screen.getByRole('group', { name: 'Test' }); expect(component).toHaveClass('ams-field-set'); }); it('renders an extra class name', () => { render(_jsx(FieldSet, { className: "extra", legend: "Test" })); const component = screen.getByRole('group', { name: 'Test' }); expect(component).toHaveClass('ams-field-set extra'); }); it('renders the correct legend class name', () => { const { container } = render(_jsx(FieldSet, { legend: "Test" })); const component = container.querySelector('legend'); expect(component).toHaveClass('ams-field-set__legend'); }); it('renders the error class', () => { const { container } = render(_jsx(FieldSet, { invalid: true, legend: "Test" })); const component = container.querySelector(':only-child'); expect(component).toHaveClass('ams-field-set--invalid'); }); it('supports ForwardRef in React', () => { const ref = createRef(); render(_jsx(FieldSet, { legend: "Test", ref: ref })); const component = screen.getByRole('group', { name: 'Test' }); expect(ref.current).toBe(component); }); it('renders the provided hint text after the legend', () => { render(_jsx(FieldSet, { hint: "hint text", legend: "Legend" })); const component = screen.getByRole('group', { name: 'Legend (hint text)' }); expect(component).toBeInTheDocument(); }); it('renders the default hint text after the legend', () => { render(_jsx(FieldSet, { legend: "Legend", optional: true })); const component = screen.getByRole('group', { name: 'Legend (niet verplicht)' }); expect(component).toBeInTheDocument(); }); it('renders the provided hint text after the legend when both `optional` and `hint` props are used', () => { render(_jsx(FieldSet, { hint: "not required", legend: "Legend", optional: true })); const component = screen.getByRole('group', { name: 'Legend (not required)' }); expect(component).toBeInTheDocument(); }); it('renders the provided hint text after the legend while `optional` is set to `false`', () => { render(_jsx(FieldSet, { hint: "required", legend: "Legend", optional: false })); const component = screen.getByRole('group', { name: 'Legend (required)' }); expect(component).toBeInTheDocument(); }); });