UNPKG

@amsterdam/design-system-react

Version:

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

61 lines (60 loc) 2.67 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 { describe, expect, it } from 'vitest'; import { aspectRatioOptions } from '../common/types'; import { generateAspectRatioClass } from './generateAspectRatioClass'; import { Image } from './Image'; describe('Image', () => { it('renders', () => { render(_jsx(Image, { alt: "" })); const component = screen.getByRole('presentation'); expect(component).toBeInTheDocument(); expect(component).toBeVisible(); }); it('renders a design system BEM class name', () => { render(_jsx(Image, { alt: "" })); const component = screen.getByRole('presentation'); expect(component).toHaveClass('ams-image'); }); it('renders an extra class name', () => { render(_jsx(Image, { alt: "", className: "extra" })); const component = screen.getByRole('presentation'); expect(component).toHaveClass('ams-image extra'); }); aspectRatioOptions.forEach((aspectRatio) => { it(`renders class names to display the image in the ${aspectRatio} aspect ratio`, () => { render(_jsx(Image, { alt: "", aspectRatio: aspectRatio })); const component = screen.getByRole('presentation'); const aspectRatioClass = generateAspectRatioClass(aspectRatio) || ''; expect(component).toHaveClass(aspectRatioClass); }); }); it('sets a default width attribute', () => { render(_jsx(Image, { alt: "" })); const component = screen.getByRole('presentation'); expect(component).toHaveAttribute('width', '600'); }); it('overrides the default width attribute', () => { render(_jsx(Image, { alt: "", width: 300 })); const component = screen.getByRole('presentation'); expect(component).toHaveAttribute('width', '300'); }); it('supports ForwardRef in React', () => { const ref = createRef(); render(_jsx(Image, { alt: "", ref: ref })); const component = screen.getByRole('presentation'); expect(ref.current).toBe(component); }); it('passes additional props', () => { render(_jsx(Image, { alt: "", "aria-hidden": "false", "data-test": "data-test", id: "id" })); const component = screen.getByRole('presentation'); expect(component).toHaveAttribute('aria-hidden', 'false'); expect(component).toHaveAttribute('id', 'id'); expect(component).toHaveAttribute('data-test', 'data-test'); }); });