Skip to content

Commit

Permalink
Migrated NestField tests to @testing-library/react (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpospiech authored Jun 14, 2024
1 parent c047291 commit 26335df
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions packages/uniforms-mui/__tests__/NestField.tsx
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();
});
});

0 comments on commit 26335df

Please sign in to comment.