UNPKG

@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
import { jsx as _jsx } from "react/jsx-runtime"; /** * @license EUPL-1.2+ * Copyright Gemeente Amsterdam */ import { render } from '@testing-library/react'; import { createRef } from 'react'; import { Hint } from '.'; import '@testing-library/jest-dom'; describe('Hint', () => { it('renders', () => { const { container } = render(_jsx(Hint, { hint: "hint" })); const component = container.querySelector(':only-child'); expect(component).toBeInTheDocument(); expect(component).toBeVisible(); }); it('renders a design system BEM class name', () => { const { container } = render(_jsx(Hint, { optional: true })); const component = container.querySelector(':only-child'); expect(component).toHaveClass('ams-hint'); }); it('renders an extra class name', () => { const { container } = render(_jsx(Hint, { className: "extra", optional: true })); const component = container.querySelector(':only-child'); expect(component).toHaveClass('ams-hint extra'); }); it('supports ForwardRef in React', () => { const ref = createRef(); const { container } = render(_jsx(Hint, { ref: ref })); const component = container.querySelector(':only-child'); expect(ref.current).toBe(component); }); it('renders the provided hint text', () => { const { container } = render(_jsx(Hint, { hint: "hint text" })); const component = container.querySelector(':only-child'); expect(component).toHaveTextContent('(hint text)'); }); it('renders the default hint text', () => { const { container } = render(_jsx(Hint, { optional: true })); const component = container.querySelector(':only-child'); expect(component).toHaveTextContent('(niet verplicht)'); }); it('renders the provided hint text when `optional` is set to `false`', () => { const { container } = render(_jsx(Hint, { hint: "not required", optional: true })); const component = container.querySelector(':only-child'); expect(component).toHaveTextContent('(not required)'); }); it('renders the provided hint text "required" while also being marked as not optional', () => { const { container } = render(_jsx(Hint, { hint: "required", optional: false })); const component = container.querySelector(':only-child'); expect(component).toHaveTextContent('(required)'); }); });