redux-devtools/packages/devui/tests/Form.test.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-01-03 16:00:55 +03:00
import React from 'react';
import { shallow, mount } from 'enzyme';
import { shallowToJson } from 'enzyme-to-json';
import { Form } from '../src';
import { schema, uiSchema, formData } from '../src/Form/stories/schema';
describe('Form', function () {
2019-01-03 16:00:55 +03:00
it('renders correctly', () => {
const wrapper = shallow(
2019-01-10 21:51:14 +03:00
<Form formData={formData} schema={schema} uiSchema={uiSchema} />
);
2019-01-03 16:00:55 +03:00
expect(shallowToJson(wrapper)).toMatchSnapshot();
});
it('renders with primary button', () => {
const wrapper = shallow(
<Form
primaryButton
submitText="Custom button"
formData={formData}
schema={schema}
uiSchema={uiSchema}
2019-01-10 21:51:14 +03:00
/>
);
2019-01-03 16:00:55 +03:00
expect(shallowToJson(wrapper)).toMatchSnapshot();
});
it('renders with no button', () => {
const wrapper = shallow(
2019-01-10 21:51:14 +03:00
<Form formData={formData} schema={schema} uiSchema={uiSchema} noSubmit />
);
2019-01-03 16:00:55 +03:00
expect(shallowToJson(wrapper)).toMatchSnapshot();
});
it('should handle the submit event', () => {
const onSubmit = jest.fn();
const wrapper = mount(
<Form
formData={formData}
schema={schema}
uiSchema={uiSchema}
onSubmit={onSubmit}
/>
);
wrapper.find('form').simulate('submit');
expect(onSubmit).toBeCalled();
});
});