52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
|
|
import React from 'react';
|
||
|
|
import {Button} from 'react-md';
|
||
|
|
import {shallow, mount} from 'enzyme';
|
||
|
|
import AnswerSource from '../AnswerSource';
|
||
|
|
import {ANSWER_TYPE} from '../../config/constants'
|
||
|
|
|
||
|
|
it ('renders without crashing', () => {
|
||
|
|
shallow (<AnswerSource />);
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
describe('functional tests', ()=>{
|
||
|
|
let wrapper;
|
||
|
|
beforeEach(()=>{
|
||
|
|
const onSaveAnswerTypeFunction = jest.fn();
|
||
|
|
wrapper = mount(<AnswerSource onSaveAnswerType={onSaveAnswerTypeFunction} />);
|
||
|
|
wrapper.setState({
|
||
|
|
isModalOpen: false,
|
||
|
|
answerType: 0
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
it ('renders only a button', () => {
|
||
|
|
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('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);
|
||
|
|
});
|
||
|
|
});
|