2018-04-03 23:45:53 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import {Button} from 'react-md';
|
|
|
|
|
import {shallow, mount} from 'enzyme';
|
|
|
|
|
import AnswerSource from '../AnswerSource';
|
2018-04-04 01:09:29 +02:00
|
|
|
import {ANSWER_TYPE} from '../../config/constants';
|
2018-04-03 23:45:53 +02:00
|
|
|
|
|
|
|
|
it ('renders without crashing', () => {
|
|
|
|
|
shallow (<AnswerSource />);
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-04 01:09:29 +02:00
|
|
|
describe ('functional tests', () => {
|
2018-04-03 23:45:53 +02:00
|
|
|
let wrapper;
|
2018-04-04 01:09:29 +02:00
|
|
|
beforeEach (() => {
|
|
|
|
|
const onSaveAnswerTypeFunction = jest.fn ();
|
|
|
|
|
wrapper = mount (
|
|
|
|
|
<AnswerSource onSaveAnswerType={onSaveAnswerTypeFunction} />
|
|
|
|
|
);
|
|
|
|
|
wrapper.setState ({
|
2018-04-03 23:45:53 +02:00
|
|
|
isModalOpen: false,
|
2018-04-04 01:09:29 +02:00
|
|
|
answerType: 0,
|
2018-04-03 23:45:53 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-04 01:09:29 +02:00
|
|
|
it ('snapshot', ()=>{
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-03 23:45:53 +02:00
|
|
|
it ('renders only a button', () => {
|
2018-04-04 01:09:29 +02:00
|
|
|
expect (wrapper.first ().text ()).toEqual ('Answer type');
|
|
|
|
|
expect (wrapper.find ('AnswerSourceForm').exists ()).toEqual (false);
|
2018-04-03 23:45:53 +02:00
|
|
|
});
|
|
|
|
|
|
2018-04-04 01:09:29 +02:00
|
|
|
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');
|
2018-04-03 23:45:53 +02:00
|
|
|
});
|
|
|
|
|
|
2018-04-04 01:09:29 +02:00
|
|
|
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);
|
2018-04-03 23:45:53 +02:00
|
|
|
});
|
2018-04-04 01:09:29 +02:00
|
|
|
});
|