2019-01-03 16:00:55 +03:00
|
|
|
import React from 'react';
|
2021-10-22 07:18:03 +03:00
|
|
|
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';
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('Dialog', function () {
|
2019-01-03 16:00:55 +03:00
|
|
|
it('renders correctly', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Dialog
|
|
|
|
onDismiss={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
|
|
|
onSubmit={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2020-09-09 17:35:22 +03:00
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders with props', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Dialog
|
|
|
|
title="Dialog Title"
|
|
|
|
open
|
|
|
|
fullWidth
|
|
|
|
onDismiss={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
|
|
|
onSubmit={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
|
|
|
>
|
2019-01-03 16:00:55 +03:00
|
|
|
Hello Dialog!
|
2023-07-12 21:03:20 +03:00
|
|
|
</Dialog>,
|
2019-01-03 16:00:55 +03:00
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders modal', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Dialog
|
|
|
|
modal
|
|
|
|
onDismiss={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
|
|
|
onSubmit={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2020-09-09 17:35:22 +03:00
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
it('should handle dismiss event', async () => {
|
2019-01-03 16:00:55 +03:00
|
|
|
const onDismiss = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Dialog
|
|
|
|
open
|
|
|
|
onDismiss={onDismiss}
|
|
|
|
onSubmit={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2020-09-09 17:35:22 +03:00
|
|
|
);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
await userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(onDismiss).toHaveBeenCalled();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
it('should handle submit event', async () => {
|
2019-01-03 16:00:55 +03:00
|
|
|
const onSubmit = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Dialog
|
|
|
|
open
|
|
|
|
onDismiss={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
|
|
|
onSubmit={onSubmit}
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2020-09-09 17:35:22 +03:00
|
|
|
);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
await userEvent.click(screen.getByRole('button', { name: 'Submit' }));
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(onSubmit).toHaveBeenCalled();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
});
|