Skip to content

Commit

Permalink
UICAL -228: Test for TImeField
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-hellen committed Jun 7, 2024
1 parent 302ad04 commit a577819
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/components/fields/TimeField.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { fireEvent, render, screen } from "@testing-library/react";
import React from 'react'
import { IntlProvider } from "react-intl";
import TimeField from "./TimeField";
import userEvent from "@testing-library/user-event";

describe('TimeField', () => {
it('Renders the TimeField correctly', async () => {
render(
<IntlProvider locale="en">
<TimeField
display={true}
value={undefined}
inputRef={() => {}}
error={undefined}
onBlur={() => {}}
onChange={() => {}}
/>
</IntlProvider>
);

expect(await screen.findByRole('textbox')).toBeInTheDocument();
expect(await screen.findByRole('textbox')).toHaveValue('');
});

it('Renders nothing when display is false', async () => {
render(
<IntlProvider locale="en">
<TimeField
display={false}
value='test'
inputRef={() => {}}
error={undefined}
onBlur={() => {}}
onChange={() => {}}
/>
</IntlProvider>
);

expect(await screen.queryByRole('textbox')).toBeNull();
});

it('Formatse time correctly', async () => {
render(
<IntlProvider locale="en">
<TimeField
display={true}
value='12:30:00'
inputRef={() => {}}
error={undefined}
onBlur={() => {}}
onChange={() => {}}
/>
</IntlProvider>
);

expect(await screen.findByRole('textbox')).toHaveValue('12:30 PM');
});
});

0 comments on commit a577819

Please sign in to comment.