diff --git a/test/utils/IconInput.test.tsx b/test/utils/IconInput.test.tsx new file mode 100644 index 00000000..a5d863d0 --- /dev/null +++ b/test/utils/IconInput.test.tsx @@ -0,0 +1,24 @@ +import type { IconProp } from '@fortawesome/fontawesome-svg-core'; +import { faAppleAlt, faCalendar, faTable } from '@fortawesome/free-solid-svg-icons'; +import { screen } from '@testing-library/react'; +import { IconInput } from '../../src/utils/IconInput'; +import { renderWithEvents } from '../__helpers__/setUpTest'; + +describe('', () => { + const setUp = (icon: IconProp, placeholder?: string) => renderWithEvents( + , + ); + + it.each([faCalendar, faAppleAlt, faTable])('displays provided icon', (icon) => { + const { container } = setUp(icon); + expect(container).toMatchSnapshot(); + }); + + it('focuses input on icon click', async () => { + const { user } = setUp(faCalendar, 'foo'); + + expect(screen.getByPlaceholderText('foo')).not.toHaveFocus(); + await user.click(screen.getByRole('img', { hidden: true })); + expect(screen.getByPlaceholderText('foo')).toHaveFocus(); + }); +}); diff --git a/test/utils/__snapshots__/IconInput.test.tsx.snap b/test/utils/__snapshots__/IconInput.test.tsx.snap new file mode 100644 index 00000000..cc72248c --- /dev/null +++ b/test/utils/__snapshots__/IconInput.test.tsx.snap @@ -0,0 +1,85 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` displays provided icon 1`] = ` +
+
+ + +
+
+`; + +exports[` displays provided icon 2`] = ` +
+
+ + +
+
+`; + +exports[` displays provided icon 3`] = ` +
+
+ + +
+
+`;