From 6a7bdb00145726e04f5675549c4a42bb7883f82f Mon Sep 17 00:00:00 2001 From: Matthew Warman Date: Wed, 4 Sep 2024 08:53:10 -0400 Subject: [PATCH] tests --- .../Input/__tests__/SelectInput.test.tsx | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/common/components/Input/__tests__/SelectInput.test.tsx diff --git a/src/common/components/Input/__tests__/SelectInput.test.tsx b/src/common/components/Input/__tests__/SelectInput.test.tsx new file mode 100644 index 0000000..fe92c27 --- /dev/null +++ b/src/common/components/Input/__tests__/SelectInput.test.tsx @@ -0,0 +1,68 @@ +import { describe, expect, it } from 'vitest'; +import { IonSelectOption } from '@ionic/react'; +import { Form, Formik } from 'formik'; +import userEvent from '@testing-library/user-event'; + +import { render, screen, waitFor } from 'test/test-utils'; + +import SelectInput from '../SelectInput'; + +describe('SelectInput', () => { + it('should render successfully', async () => { + // ARRANGE + render( + {}}> +
+ + Able + +
+
, + ); + await screen.findByTestId('input'); + + // ASSERT + expect(screen.getByTestId('input')).toBeDefined(); + }); + + it('should change value', async () => { + // ARRANGE + const value = 'a'; + let submittedValue = ''; + render( + { + submittedValue = values.selectInput; + }} + > + {(formikProps) => ( +
+ formikProps.submitForm()} + > + Alpha + Bravo + +
+ )} +
, + ); + await screen.findByTestId('input'); + + // ACT + // open the select + await userEvent.click(screen.getByTestId('input')); + await waitFor(() => expect(screen.getAllByRole('radio').length).toBe(2)); + // select the second option + await userEvent.click(screen.getAllByRole('radio')[1]); + await waitFor(() => expect(submittedValue).toBe('b')); + + // ASSERT + expect(screen.getByTestId('input')).toBeDefined(); + expect(submittedValue).toBe('b'); + }); +});