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

87 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-01-03 16:00:55 +03:00
import React from 'react';
import { render, mount } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import { Dialog } from '../src';
describe('Dialog', function () {
2019-01-03 16:00:55 +03:00
it('renders correctly', () => {
const wrapper = render(
<Dialog
onDismiss={() => {
// noop
}}
onSubmit={() => {
// noop
}}
/>
);
2019-01-03 16:00:55 +03:00
expect(renderToJson(wrapper)).toMatchSnapshot();
});
it('renders with props', () => {
const wrapper = render(
<Dialog
title="Dialog Title"
open
fullWidth
onDismiss={() => {
// noop
}}
onSubmit={() => {
// noop
}}
>
2019-01-03 16:00:55 +03:00
Hello Dialog!
</Dialog>
);
expect(renderToJson(wrapper)).toMatchSnapshot();
});
it('renders modal', () => {
const wrapper = render(
<Dialog
modal
onDismiss={() => {
// noop
}}
onSubmit={() => {
// noop
}}
/>
);
2019-01-03 16:00:55 +03:00
expect(renderToJson(wrapper)).toMatchSnapshot();
});
it('should handle dismiss event', () => {
const onDismiss = jest.fn();
const wrapper = mount(
<Dialog
open
onDismiss={onDismiss}
onSubmit={() => {
// noop
}}
/>
);
2019-01-03 16:00:55 +03:00
wrapper.find('button').first().simulate('click');
2019-01-03 16:00:55 +03:00
expect(onDismiss).toBeCalled();
});
it('should handle submit event', () => {
const onSubmit = jest.fn();
const wrapper = mount(
<Dialog
open
onDismiss={() => {
// noop
}}
onSubmit={onSubmit}
/>
);
2019-01-03 16:00:55 +03:00
wrapper.find('button').last().simulate('click');
2019-01-03 16:00:55 +03:00
expect(onSubmit).toBeCalled();
});
});