@amsterdam/design-system-react
Version:
All React components from the Amsterdam Design System. Use it to compose pages in your website or application.
55 lines (54 loc) • 2.2 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 { describe, expect, it } from 'vitest';
import { SearchField } from './SearchField';
describe('SearchFieldButton', () => {
it('renders a submit button', () => {
render(_jsx(SearchField.Button, { children: "Click me!" }));
const button = screen.getByRole('button', {
name: 'Click me!',
});
expect(button).toBeInTheDocument();
expect(button).toBeVisible();
expect(button).toHaveAttribute('type', 'submit');
});
it('renders a default label', () => {
render(_jsx(SearchField.Button, {}));
const button = screen.getByRole('button');
expect(button).toHaveTextContent('Zoeken');
});
it('renders the primary variant of the Button component', () => {
render(_jsx(SearchField.Button, { children: "Click me!" }));
const button = screen.getByRole('button', {
name: 'Click me!',
});
expect(button).toHaveClass('ams-button ams-button--primary');
});
it('renders an extra class name', () => {
render(_jsx(SearchField.Button, { className: "extra", children: "Click me!" }));
const button = screen.getByRole('button', {
name: 'Click me!',
});
expect(button).toHaveClass('ams-button extra');
});
it('is able to pass a React ref', () => {
const ref = createRef();
render(_jsx(SearchField.Button, { ref: ref, children: "Click me!" }));
const button = screen.getByRole('button', {
name: 'Click me!',
});
expect(ref.current).toBe(button);
});
it('passes additional props', () => {
render(_jsx(SearchField.Button, { "aria-hidden": "false", "data-test": "data-test", id: "id" }));
const component = screen.getByRole('button');
expect(component).toHaveAttribute('aria-hidden', 'false');
expect(component).toHaveAttribute('id', 'id');
expect(component).toHaveAttribute('data-test', 'data-test');
});
});