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);
});
});
});

View File

@@ -0,0 +1,93 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`functional tests snapshot 1`] = `
<AnswerSource
onSaveAnswerType={[Function]}
>
<div>
<withInk(withTooltip(Button))
flat={true}
inkTransitionEnterTimeout={450}
inkTransitionLeaveTimeout={300}
inkTransitionOverlap={150}
onClick={[Function]}
primary={true}
>
<withTooltip(Button)
flat={true}
ink={
<InkContainer
className={undefined}
disabledInteractions={undefined}
inkClassName={undefined}
inkStyle={undefined}
pulse={undefined}
style={undefined}
transitionEnterTimeout={450}
transitionLeaveTimeout={300}
transitionOverlap={150}
waitForInkTransition={undefined}
/>
}
onClick={[Function]}
primary={true}
>
<Button
fixedPosition="br"
flat={true}
iconBefore={true}
ink={
<InkContainer
className={undefined}
disabledInteractions={undefined}
inkClassName={undefined}
inkStyle={undefined}
pulse={undefined}
style={undefined}
transitionEnterTimeout={450}
transitionLeaveTimeout={300}
transitionOverlap={150}
waitForInkTransition={undefined}
/>
}
onClick={[Function]}
primary={true}
type="button"
>
<button
className="md-btn md-btn--flat md-btn--text md-pointer--hover md-text--theme-primary md-ink--primary md-inline-block"
onClick={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchStart={[Function]}
type="button"
>
<InkContainer
key="ink-container"
transitionEnterTimeout={450}
transitionLeaveTimeout={300}
transitionOverlap={150}
>
<TransitionGroup
childFactory={[Function]}
className="md-ink-container"
component="div"
>
<div
className="md-ink-container"
/>
</TransitionGroup>
</InkContainer>
Answer type
</button>
</Button>
</withTooltip(Button)>
</withInk(withTooltip(Button))>
</div>
</AnswerSource>
`;