Skip to content

Commit

Permalink
(test) O3-2081: Fix tests for the PatientRegistration component (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush-AI authored Aug 18, 2023
1 parent 3eeffc1 commit 1950921
Show file tree
Hide file tree
Showing 2 changed files with 244 additions and 370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,6 @@ import userEvent from '@testing-library/user-event';
import { Formik, Form } from 'formik';
import { Input } from './input.component';

describe.skip('number input', () => {
const setupInput = async () => {
render(
<Formik initialValues={{ number: 0 }} onSubmit={null}>
<Form>
<Input id="number" type="number" labelText="Number" name="number" />
</Form>
</Formik>,
);
return screen.getByLabelText('Number (optional)') as HTMLInputElement;
};

it('exists', async () => {
const input = await setupInput();
expect(input.type).toEqual('number');
});

it('can input data', async () => {
const user = userEvent.setup();

const input = await setupInput();
const expected = 1;

await user.type(input, expected.toString());
await user.tab();

expect(input.valueAsNumber).toEqual(expected);
});
});

describe('text input', () => {
const setupInput = async () => {
render(
Expand Down Expand Up @@ -100,108 +70,3 @@ describe('text input', () => {
expect(screen.getByLabelText('Text (optional)')).toBeInTheDocument();
});
});

describe.skip('telephone number input', () => {
const setupInput = async () => {
render(
<Formik initialValues={{ telephoneNumber: '' }} onSubmit={null}>
<Form>
<Input id="tel" labelText="Telephone Number" name="telephoneNumber" placeholder="Enter telephone number" />
</Form>
</Formik>,
);
return screen.getByLabelText('telephoneNumber') as HTMLInputElement;
};

it('exists', async () => {
const input = await setupInput();
expect(input.type).toEqual('tel');
});

it('can input data', async () => {
const user = userEvent.setup();

const input = await setupInput();
const expected = '0800001066';

await user.type(input, expected);
await user.tab();

expect(input.value).toEqual(expected);
});
});

describe.skip('date input', () => {
const setupInput = async () => {
render(
<Formik initialValues={{ date: '' }} onSubmit={null}>
<Form>
<Input id="date" labelText="date" name="date" />
</Form>
</Formik>,
);
return screen.getByLabelText('date') as HTMLInputElement;
};

it('exists', async () => {
const input = await setupInput();
expect(input.type).toEqual('date');
});

it('can input data', async () => {
const user = userEvent.setup();

const input = await setupInput();
const expected = '1990-09-10';

await user.type(input, expected);
await user.tab();

expect(input.value).toEqual(expected);
});
});

describe.skip('checkbox input', () => {
const setupInput = async () => {
render(
<Formik initialValues={{ checkbox: false }} onSubmit={null}>
<Form>
<Input id="checkbox" labelText="checkbox" name="checkbox" />
</Form>
</Formik>,
);
return screen.getByLabelText('checkbox') as HTMLInputElement;
};

it('exists', async () => {
const input = await setupInput();
expect(input.type).toEqual('checkbox');
});

it('can input data', async () => {
const user = userEvent.setup();
const input = await setupInput();

const expected = true;

await user.click(input);
await user.tab();

expect(input.checked).toEqual(expected);
});

it('can update data', async () => {
const user = userEvent.setup();
const input = await setupInput();

const expected = false;

await user.click(input);
await user.tab();

await user.click(input);
await user.tab();

expect(input.checked).toEqual(expected);
});
});
Loading

0 comments on commit 1950921

Please sign in to comment.