Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated NestField tests to @testing-library/react #1350

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
Loading