Skip to content

Commit

Permalink
Rewritten tests for DateField for Mui theme
Browse files Browse the repository at this point in the history
  • Loading branch information
zaxovaiko committed May 24, 2024
1 parent fd7c7f2 commit dbb79d3
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions packages/uniforms-mui/__tests__/DateField.tsx
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);
});

0 comments on commit dbb79d3

Please sign in to comment.