-
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated
NestField
tests to @testing-library/react (#1350)
- Loading branch information
1 parent
c047291
commit 26335df
Showing
1 changed file
with
29 additions
and
28 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,36 +1,37 @@ | ||
import FormHelperText from '@mui/material/FormHelperText'; | ||
import FormLabel from '@mui/material/FormLabel'; | ||
import { screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { NestField } from 'uniforms-mui'; | ||
import { renderWithZod } from 'uniforms/__suites__'; | ||
import { z } from 'zod'; | ||
|
||
import createContext from './_createContext'; | ||
import mount from './_mount'; | ||
describe('@RTL - NestField tests', () => { | ||
test('<NestField> - renders a label (required annotation)', () => { | ||
const { container } = renderWithZod({ | ||
element: <NestField name="x" label="y" />, | ||
schema: z.object({ | ||
x: z.object({ | ||
a: z.string(), | ||
b: z.number(), | ||
}), | ||
}), | ||
}); | ||
|
||
test('<NestField> - renders a Subheader', () => { | ||
const element = <NestField name="x" label="y" />; | ||
const wrapper = mount( | ||
element, | ||
createContext({ | ||
x: { type: Object }, | ||
'x.a': { type: String }, | ||
'x.b': { type: Number }, | ||
}), | ||
); | ||
const label = container.getElementsByTagName('legend')[0]?.textContent; | ||
|
||
expect(wrapper.find(FormLabel).at(0).text()).toBe('y *'); | ||
}); | ||
expect(label).toBe('y *'); | ||
}); | ||
|
||
test('<NestField> - renders a helperText', () => { | ||
const element = <NestField name="x" helperText="Helper" />; | ||
const wrapper = mount( | ||
element, | ||
createContext({ | ||
x: { type: Object }, | ||
'x.a': { type: String }, | ||
'x.b': { type: Number }, | ||
}), | ||
); | ||
test('<NestField> - renders a helperText', () => { | ||
renderWithZod({ | ||
element: <NestField name="x" helperText="Helper" />, | ||
schema: z.object({ | ||
x: z.object({ | ||
a: z.string(), | ||
b: z.number(), | ||
}), | ||
}), | ||
}); | ||
|
||
expect(wrapper.find(FormHelperText)).toHaveLength(1); | ||
expect(wrapper.find(FormHelperText).text()).toBe('Helper'); | ||
expect(screen.getByText('Helper')).toBeInTheDocument(); | ||
}); | ||
}); |