From a5778196eb7f43103630ccc9fdfc19aa1cafcbc3 Mon Sep 17 00:00:00 2001 From: Chris Hellen Date: Fri, 7 Jun 2024 15:05:48 -0500 Subject: [PATCH] UICAL -228: Test for TImeField --- src/components/fields/TimeField.test.tsx | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/components/fields/TimeField.test.tsx diff --git a/src/components/fields/TimeField.test.tsx b/src/components/fields/TimeField.test.tsx new file mode 100644 index 0000000..e2acc8f --- /dev/null +++ b/src/components/fields/TimeField.test.tsx @@ -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( + + {}} + error={undefined} + onBlur={() => {}} + onChange={() => {}} + /> + + ); + + expect(await screen.findByRole('textbox')).toBeInTheDocument(); + expect(await screen.findByRole('textbox')).toHaveValue(''); + }); + + it('Renders nothing when display is false', async () => { + render( + + {}} + error={undefined} + onBlur={() => {}} + onChange={() => {}} + /> + + ); + + expect(await screen.queryByRole('textbox')).toBeNull(); + }); + + it('Formatse time correctly', async () => { + render( + + {}} + error={undefined} + onBlur={() => {}} + onChange={() => {}} + /> + + ); + + expect(await screen.findByRole('textbox')).toHaveValue('12:30 PM'); + }); +}); \ No newline at end of file