|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import '@testing-library/jest-dom'; |
| 4 | +import UsaIcon from './UsaIcon'; |
| 5 | + |
| 6 | +describe('<UsaIcon />', () => { |
| 7 | + it('renders an SVG icon with USDWDS classes', () => { |
| 8 | + render(<UsaIcon name="check" />); |
| 9 | + const svgElement = screen.getByRole('img'); |
| 10 | + expect(svgElement).toBeInstanceOf(SVGSVGElement); |
| 11 | + expect(svgElement).toHaveClass('usa-icon'); |
| 12 | + }); |
| 13 | + |
| 14 | + it('renders the icon as unfocusable img role', () => { |
| 15 | + render(<UsaIcon name="check" />); |
| 16 | + const svgElement = screen.getByRole('img'); |
| 17 | + expect(svgElement).toHaveAttribute('focusable', 'false'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('renders the icon as focusable when the role is button', () => { |
| 21 | + render(<UsaIcon name="check" role="button" />); |
| 22 | + const svgElement = screen.getByRole('button'); |
| 23 | + expect(svgElement).toHaveAttribute('focusable', 'true'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('renders the icon as focusable when the role is link', () => { |
| 27 | + render(<UsaIcon name="check" role="link" />); |
| 28 | + const svgElement = screen.getByRole('link'); |
| 29 | + expect(svgElement).toHaveAttribute('focusable', 'true'); |
| 30 | + }); |
| 31 | + |
| 32 | + it('renders the icon with a size class when size is set', () => { |
| 33 | + render(<UsaIcon name="check" size={4} />); |
| 34 | + const svgElement = screen.getByRole('img'); |
| 35 | + expect(svgElement).toHaveClass('usa-icon--size-4'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('uses a role attribute when provided', () => { |
| 39 | + render(<UsaIcon name="check" role="presentation" />); |
| 40 | + const svgElement = screen.getByRole('presentation'); |
| 41 | + expect(svgElement).toBeInTheDocument(); |
| 42 | + }); |
| 43 | +}); |
0 commit comments