forked from cloud-gov/pages-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsaIcon.test.jsx
43 lines (37 loc) · 1.54 KB
/
UsaIcon.test.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import UsaIcon from './UsaIcon';
describe('<UsaIcon />', () => {
it('renders an SVG icon with USDWDS classes', () => {
render(<UsaIcon name="check" />);
const svgElement = screen.getByRole('img');
expect(svgElement).toBeInstanceOf(SVGSVGElement);
expect(svgElement).toHaveClass('usa-icon');
});
it('renders the icon as unfocusable img role', () => {
render(<UsaIcon name="check" />);
const svgElement = screen.getByRole('img');
expect(svgElement).toHaveAttribute('focusable', 'false');
});
it('renders the icon as focusable when the role is button', () => {
render(<UsaIcon name="check" role="button" />);
const svgElement = screen.getByRole('button');
expect(svgElement).toHaveAttribute('focusable', 'true');
});
it('renders the icon as focusable when the role is link', () => {
render(<UsaIcon name="check" role="link" />);
const svgElement = screen.getByRole('link');
expect(svgElement).toHaveAttribute('focusable', 'true');
});
it('renders the icon with a size class when size is set', () => {
render(<UsaIcon name="check" size={4} />);
const svgElement = screen.getByRole('img');
expect(svgElement).toHaveClass('usa-icon--size-4');
});
it('uses a role attribute when provided', () => {
render(<UsaIcon name="check" role="presentation" />);
const svgElement = screen.getByRole('presentation');
expect(svgElement).toBeInTheDocument();
});
});