Cleaning up tests
This commit is contained in:
parent
f90b4a7bed
commit
692b9fa2df
@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow, mount } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import { Form } from 'components/Form';
|
import { Form } from 'components/Form';
|
||||||
import { translate, I18nWrapper } from '__mocks__/i18n';
|
import { translate } from '__mocks__/i18n';
|
||||||
|
|
||||||
const syntaxes = {
|
const syntaxes = {
|
||||||
js: 'Javascript',
|
js: 'Javascript',
|
||||||
@ -81,20 +81,13 @@ describe('Form', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('submitting expression', () => {
|
describe('submitting expression', () => {
|
||||||
const build = (props = {}) => {
|
|
||||||
const component = mount(
|
|
||||||
<I18nWrapper>
|
|
||||||
<Form syntaxes={ syntaxes } { ...props }/>
|
|
||||||
</I18nWrapper>
|
|
||||||
);
|
|
||||||
return component;
|
|
||||||
};
|
|
||||||
|
|
||||||
test('submitting form', () => {
|
test('submitting form', () => {
|
||||||
const onSubmit = jest.fn();
|
const onSubmit = jest.fn();
|
||||||
const component = build({ onSubmit });
|
const component = shallow(
|
||||||
|
<Form t={ translate } syntaxes={ syntaxes } onSubmit={ onSubmit }/>
|
||||||
|
);
|
||||||
const eventObj = { preventDefault: jest.fn() };
|
const eventObj = { preventDefault: jest.fn() };
|
||||||
component.find(Form).instance().setState({ syntax: 'test', expr: 'Test expression' });
|
component.setState({ syntax: 'test', expr: 'Test expression' });
|
||||||
component.find('form').simulate('submit', eventObj);
|
component.find('form').simulate('submit', eventObj);
|
||||||
|
|
||||||
expect(eventObj.preventDefault).toHaveBeenCalled();
|
expect(eventObj.preventDefault).toHaveBeenCalled();
|
||||||
@ -105,9 +98,15 @@ describe('Form', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('submitting form with Shift+Enter', () => {
|
test('submitting form with Shift+Enter', () => {
|
||||||
const component = build({ onSubmit: Function.prototype });
|
const component = shallow(
|
||||||
const form = component.find(Form).instance();
|
<Form t={ translate } syntaxes={ syntaxes } onSubmit={ Function.prototype }/>
|
||||||
const eventObj = { charCode: 13, shiftKey: true };
|
);
|
||||||
|
const form = component.instance();
|
||||||
|
const eventObj = {
|
||||||
|
preventDefault: Function.prototype,
|
||||||
|
charCode: 13,
|
||||||
|
shiftKey: true
|
||||||
|
};
|
||||||
jest.spyOn(form, 'handleSubmit');
|
jest.spyOn(form, 'handleSubmit');
|
||||||
component.find('textarea').simulate('keypress', eventObj);
|
component.find('textarea').simulate('keypress', eventObj);
|
||||||
|
|
||||||
@ -115,9 +114,15 @@ describe('Form', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('not submitting with just Enter', () => {
|
test('not submitting with just Enter', () => {
|
||||||
const component = build({ onSubmit: Function.prototype });
|
const component = shallow(
|
||||||
const form = component.find(Form).instance();
|
<Form t={ translate } syntaxes={ syntaxes } onSubmit={ Function.protoytpe }/>
|
||||||
const eventObj = { charCode: 13, shiftKey: false };
|
);
|
||||||
|
const form = component.instance();
|
||||||
|
const eventObj = {
|
||||||
|
preventDefault: Function.prototype,
|
||||||
|
charCode: 13,
|
||||||
|
shiftKey: false
|
||||||
|
};
|
||||||
jest.spyOn(form, 'handleSubmit');
|
jest.spyOn(form, 'handleSubmit');
|
||||||
component.find('textarea').simulate('keypress', eventObj);
|
component.find('textarea').simulate('keypress', eventObj);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user