add snapshot tests for 'import-from-source' part

This commit is contained in:
GotPPay
2018-04-04 01:09:29 +02:00
parent ecb06fd4e2
commit 4d2cf52e4c
10 changed files with 1260 additions and 37 deletions

View File

@@ -2,51 +2,60 @@ import React from 'react';
import {Button} from 'react-md';
import {shallow, mount} from 'enzyme';
import AnswerSource from '../AnswerSource';
import {ANSWER_TYPE} from '../../config/constants'
import {ANSWER_TYPE} from '../../config/constants';
it ('renders without crashing', () => {
shallow (<AnswerSource />);
});
describe('functional tests', ()=>{
describe ('functional tests', () => {
let wrapper;
beforeEach(()=>{
const onSaveAnswerTypeFunction = jest.fn();
wrapper = mount(<AnswerSource onSaveAnswerType={onSaveAnswerTypeFunction} />);
wrapper.setState({
beforeEach (() => {
const onSaveAnswerTypeFunction = jest.fn ();
wrapper = mount (
<AnswerSource onSaveAnswerType={onSaveAnswerTypeFunction} />
);
wrapper.setState ({
isModalOpen: false,
answerType: 0
answerType: 0,
});
});
it ('snapshot', ()=>{
expect(wrapper).toMatchSnapshot();
});
it ('renders only a button', () => {
expect(wrapper.first().text()).toEqual('Answer type');
expect(wrapper.find('AnswerSourceForm').exists()).toEqual(false);
expect (wrapper.first ().text ()).toEqual ('Answer type');
expect (wrapper.find ('AnswerSourceForm').exists ()).toEqual (false);
});
it('answer type button click opens modal form', () => {
expect(wrapper.find('AnswerSourceFormA').exists()).toEqual(false);
expect(wrapper.state().isModalOpen).toEqual(false);
const AnswerTypeButton = wrapper.find('button').first();
AnswerTypeButton.simulate('click');
expect(wrapper.state().isModalOpen).toEqual(true);
expect(wrapper.find('AnswerSourceForm').exists()).toEqual(true);
expect(wrapper.find('button').length).toBe(3);
expect(wrapper.find('button').first().text()).toEqual('Answer type');
it ('answer type button click opens modal form', () => {
expect (wrapper.find ('AnswerSourceFormA').exists ()).toEqual (false);
expect (wrapper.state ().isModalOpen).toEqual (false);
const AnswerTypeButton = wrapper.find ('button').first ();
AnswerTypeButton.simulate ('click');
expect (wrapper.state ().isModalOpen).toEqual (true);
expect (wrapper.find ('AnswerSourceForm').exists ()).toEqual (true);
expect (wrapper.find ('button').length).toBe (3);
expect (wrapper.find ('button').first ().text ()).toEqual ('Answer type');
});
it('save button changes answerType value in state and closes the form ', () => {
const AnswerTypeButton = wrapper.find('button').first();
AnswerTypeButton.simulate('click');
const saveButton = wrapper.find('button').at(2);
const optionControl = wrapper.find('SelectionControlGroup');
expect(saveButton.text()).toEqual('Save');
expect(optionControl.exists()).toEqual(true);
optionControl.simulate('change',{target:{value:String(ANSWER_TYPE.EXTERNAL_SOURCE_WP_NEWS)}});
saveButton.simulate('click');
expect(wrapper.state().answerType).toBe(ANSWER_TYPE.EXTERNAL_SOURCE_WP_NEWS)
expect(wrapper.state().isModalOpen).toEqual(false);
expect(wrapper.find('button').length).toBe(1);
it ('save button changes answerType value in state and closes the form ', () => {
const AnswerTypeButton = wrapper.find ('button').first ();
AnswerTypeButton.simulate ('click');
const saveButton = wrapper.find ('button').at (2);
const optionControl = wrapper.find ('SelectionControlGroup');
expect (saveButton.text ()).toEqual ('Save');
expect (optionControl.exists ()).toEqual (true);
optionControl.simulate ('change', {
target: {value: String (ANSWER_TYPE.EXTERNAL_SOURCE_WP_NEWS)},
});
saveButton.simulate ('click');
expect (wrapper.state ().answerType).toBe (
ANSWER_TYPE.EXTERNAL_SOURCE_WP_NEWS
);
expect (wrapper.state ().isModalOpen).toEqual (false);
expect (wrapper.find ('button').length).toBe (1);
});
});
});