-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewritten tests for DateField for Mui theme
- Loading branch information
Showing
1 changed file
with
24 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
import FormHelperText from '@mui/material/FormHelperText'; | ||
import { screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { DateField } from 'uniforms-mui'; | ||
|
||
import createContext from './_createContext'; | ||
import mount from './_mount'; | ||
import { renderWithZod } from 'uniforms/__suites__'; | ||
import { z } from 'zod'; | ||
|
||
test('<DateField> - renders a Input with correct error text (specified)', () => { | ||
const error = new Error(); | ||
const element = ( | ||
<DateField name="x" error={error} showInlineError errorMessage="Error" /> | ||
); | ||
const wrapper = mount(element, createContext({ x: { type: Date } })); | ||
|
||
expect(wrapper.find(FormHelperText).text()).toBe('Error'); | ||
renderWithZod({ | ||
element: ( | ||
<DateField name="x" error={error} errorMessage="Error" showInlineError /> | ||
), | ||
schema: z.object({ x: z.date() }), | ||
}); | ||
expect(screen.getByText('Error')).toBeInTheDocument(); | ||
}); | ||
|
||
test('<DateField> - renders a Input with correct error text (showInlineError=false)', () => { | ||
const error = new Error(); | ||
const element = ( | ||
<DateField | ||
name="x" | ||
error={error} | ||
showInlineError={false} | ||
errorMessage="Error" | ||
/> | ||
); | ||
const wrapper = mount(element, createContext({ x: { type: Date } })); | ||
|
||
expect(wrapper.find(FormHelperText)).toHaveLength(0); | ||
renderWithZod({ | ||
element: ( | ||
<DateField | ||
name="x" | ||
error={error} | ||
errorMessage="Error" | ||
showInlineError={false} | ||
/> | ||
), | ||
schema: z.object({ x: z.date() }), | ||
}); | ||
expect( | ||
screen.getByText('X').nextElementSibling?.classList.contains('Mui-error'), | ||
).toBe(true); | ||
}); |