redux-devtools/packages/redux-devtools-ui/test/Dialog.test.tsx

87 lines
1.8 KiB
TypeScript
Raw Permalink Normal View History

2019-01-03 16:00:55 +03:00
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
2019-01-03 16:00:55 +03:00
import { Dialog } from '../src';
describe('Dialog', function () {
2019-01-03 16:00:55 +03:00
it('renders correctly', () => {
const { container } = render(
<Dialog
onDismiss={() => {
// noop
}}
onSubmit={() => {
// noop
}}
/>,
);
expect(container.firstChild).toMatchSnapshot();
2019-01-03 16:00:55 +03:00
});
it('renders with props', () => {
const { container } = render(
<Dialog
title="Dialog Title"
open
fullWidth
onDismiss={() => {
// noop
}}
onSubmit={() => {
// noop
}}
>
2019-01-03 16:00:55 +03:00
Hello Dialog!
</Dialog>,
2019-01-03 16:00:55 +03:00
);
expect(container.firstChild).toMatchSnapshot();
2019-01-03 16:00:55 +03:00
});
it('renders modal', () => {
const { container } = render(
<Dialog
modal
onDismiss={() => {
// noop
}}
onSubmit={() => {
// noop
}}
/>,
);
expect(container.firstChild).toMatchSnapshot();
2019-01-03 16:00:55 +03:00
});
it('should handle dismiss event', async () => {
2019-01-03 16:00:55 +03:00
const onDismiss = jest.fn();
render(
<Dialog
open
onDismiss={onDismiss}
onSubmit={() => {
// noop
}}
/>,
);
2019-01-03 16:00:55 +03:00
await userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
expect(onDismiss).toHaveBeenCalled();
2019-01-03 16:00:55 +03:00
});
it('should handle submit event', async () => {
2019-01-03 16:00:55 +03:00
const onSubmit = jest.fn();
render(
<Dialog
open
onDismiss={() => {
// noop
}}
onSubmit={onSubmit}
/>,
);
2019-01-03 16:00:55 +03:00
await userEvent.click(screen.getByRole('button', { name: 'Submit' }));
expect(onSubmit).toHaveBeenCalled();
2019-01-03 16:00:55 +03:00
});
});