diff --git a/frontend/shared/UsaIcon.jsx b/frontend/shared/UsaIcon.jsx index a6b492e0d..1b4f2c7dd 100644 --- a/frontend/shared/UsaIcon.jsx +++ b/frontend/shared/UsaIcon.jsx @@ -1,30 +1,22 @@ import React from 'react'; import PropTypes from 'prop-types'; -function UsaIcon({ focusable = false, role = 'img', name, size = null }) { +function UsaIcon({ role = 'img', name, size = null }) { return ( ); } UsaIcon.propTypes = { - role: PropTypes.string, - focusable: PropTypes.bool, + role: PropTypes.oneOf(['img', 'presentation', 'button', 'link', 'status', 'none']), name: PropTypes.string.isRequired, - size: PropTypes.number, -}; - -UsaIcon.defaultProps = { - role: 'img', - focusable: false, - size: null, + size: PropTypes.oneOf([3, 4, 5, 6, 7, 8, 9]), }; export default UsaIcon; diff --git a/frontend/shared/UsaIcon.test.jsx b/frontend/shared/UsaIcon.test.jsx new file mode 100644 index 000000000..2532d752c --- /dev/null +++ b/frontend/shared/UsaIcon.test.jsx @@ -0,0 +1,43 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import UsaIcon from './UsaIcon'; + +describe('', () => { + it('renders an SVG icon with USDWDS classes', () => { + render(); + const svgElement = screen.getByRole('img'); + expect(svgElement).toBeInstanceOf(SVGSVGElement); + expect(svgElement).toHaveClass('usa-icon'); + }); + + it('renders the icon as unfocusable img role', () => { + render(); + const svgElement = screen.getByRole('img'); + expect(svgElement).toHaveAttribute('focusable', 'false'); + }); + + it('renders the icon as focusable when the role is button', () => { + render(); + const svgElement = screen.getByRole('button'); + expect(svgElement).toHaveAttribute('focusable', 'true'); + }); + + it('renders the icon as focusable when the role is link', () => { + render(); + const svgElement = screen.getByRole('link'); + expect(svgElement).toHaveAttribute('focusable', 'true'); + }); + + it('renders the icon with a size class when size is set', () => { + render(); + const svgElement = screen.getByRole('img'); + expect(svgElement).toHaveClass('usa-icon--size-4'); + }); + + it('uses a role attribute when provided', () => { + render(); + const svgElement = screen.getByRole('presentation'); + expect(svgElement).toBeInTheDocument(); + }); +});