mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-27 12:03:56 +03:00
922985f9ea
* chore(deps): update dependency prettier to v3 * Format --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nathan Bierema <nbierema@gmail.com>
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import React from 'react';
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { Form } from '../src';
|
|
import { schema, uiSchema, formData } from '../src/Form/schema';
|
|
|
|
describe('Form', function () {
|
|
let random: () => number;
|
|
|
|
beforeAll(() => {
|
|
random = Math.random;
|
|
Math.random = jest.fn(() => 0.25546350798039463);
|
|
});
|
|
|
|
afterAll(() => {
|
|
Math.random = random;
|
|
console.log(Math.random());
|
|
});
|
|
|
|
it('renders correctly', () => {
|
|
const { container } = render(
|
|
<Form formData={formData} schema={schema} uiSchema={uiSchema} />,
|
|
);
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders with primary button', () => {
|
|
const { container } = render(
|
|
<Form
|
|
primaryButton
|
|
submitText="Custom button"
|
|
formData={formData}
|
|
schema={schema}
|
|
uiSchema={uiSchema}
|
|
/>,
|
|
);
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders with no button', () => {
|
|
const { container } = render(
|
|
<Form formData={formData} schema={schema} uiSchema={uiSchema} noSubmit />,
|
|
);
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('should handle the submit event', async () => {
|
|
const onSubmit = jest.fn();
|
|
render(
|
|
<Form
|
|
formData={formData}
|
|
schema={schema}
|
|
uiSchema={uiSchema}
|
|
onSubmit={onSubmit}
|
|
/>,
|
|
);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: 'Submit' }));
|
|
expect(onSubmit).toHaveBeenCalled();
|
|
});
|
|
});
|