UNPKG

@amsterdam/design-system-react

Version:

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

66 lines (65 loc) 3.23 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 { describe, expect, it } from 'vitest'; import { Hint } from '.'; 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)'); }); it('renders the correct class name when `inFieldSet` is true', () => { const { container } = render(_jsx(Hint, { hint: "hint text", inFieldSet: true })); const component = container.querySelector(':only-child'); expect(component).toHaveClass('ams-hint--in-fieldset'); }); it('passes additional props', () => { const { container } = render(_jsx(Hint, { "aria-hidden": "false", "data-test": "data-test", hint: "hint text", id: "id" })); const component = container.querySelector(':only-child'); expect(component).toHaveAttribute('aria-hidden', 'false'); expect(component).toHaveAttribute('id', 'id'); expect(component).toHaveAttribute('data-test', 'data-test'); }); });