Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarman committed Sep 4, 2024
1 parent 9e4f5f6 commit 6a7bdb0
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/common/components/Input/__tests__/SelectInput.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<Formik initialValues={{ selectInput: '' }} onSubmit={() => {}}>
<Form>
<SelectInput name="selectInput" testid="input">
<IonSelectOption value="a">Able</IonSelectOption>
</SelectInput>
</Form>
</Formik>,
);
await screen.findByTestId('input');

// ASSERT
expect(screen.getByTestId('input')).toBeDefined();
});

it('should change value', async () => {
// ARRANGE
const value = 'a';
let submittedValue = '';
render(
<Formik
initialValues={{ selectInput: value }}
onSubmit={(values) => {
submittedValue = values.selectInput;
}}
>
{(formikProps) => (
<Form>
<SelectInput
name="selectInput"
interface="popover"
testid="input"
onIonChange={() => formikProps.submitForm()}
>
<IonSelectOption value="a">Alpha</IonSelectOption>
<IonSelectOption value="b">Bravo</IonSelectOption>
</SelectInput>
</Form>
)}
</Formik>,
);
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');
});
});

0 comments on commit 6a7bdb0

Please sign in to comment.