created tests for components related to importing from source
This commit is contained in:
71
web/src/components/helper/__tests__/AnswerSourceForm.test.js
Normal file
71
web/src/components/helper/__tests__/AnswerSourceForm.test.js
Normal file
@@ -0,0 +1,71 @@
|
||||
import React from 'react';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
import AnswerSourceForm from '../AnswerSourceForm';
|
||||
import {ANSWER_TYPE} from '../../../config/constants'
|
||||
|
||||
it('renders without crashing', () => {
|
||||
shallow(<AnswerSourceForm onClose={()=>{}} onSave={()=>{}} onSourceChange={()=>{}} />);
|
||||
});
|
||||
|
||||
it('calls onClose when cancel is pressed', () => {
|
||||
const onClose = jest.fn();
|
||||
const wrapper = mount(<AnswerSourceForm onClose={onClose} onSave={()=>{}} onSourceChange={()=>{}} />);
|
||||
const cancelButton = wrapper.find('button').at(0);
|
||||
expect(cancelButton.text()).toEqual('Cancel');
|
||||
cancelButton.simulate('click');
|
||||
expect(onClose).toBeCalled();
|
||||
});
|
||||
|
||||
it('calls onSave when save is pressed', () => {
|
||||
const onSave = jest.fn();
|
||||
const wrapper = mount(<AnswerSourceForm onClose={()=>{}} onSave={onSave} onSourceChange={()=>{}} />);
|
||||
const saveButton = wrapper.find('button').at(1);
|
||||
expect(saveButton.text()).toEqual('Save');
|
||||
saveButton.simulate('click');
|
||||
expect(onSave).toBeCalled();
|
||||
});
|
||||
|
||||
it('sets PREDEFINED value when Predefined answer is selected', () => {
|
||||
let selectedValue = null;
|
||||
|
||||
const wrapper = mount(<AnswerSourceForm
|
||||
onClose={()=>{}}
|
||||
onSave={()=>{}}
|
||||
onSourceChange={(value)=>{selectedValue=value}} />);
|
||||
|
||||
const optionControl = wrapper.find('SelectionControlGroup');
|
||||
expect(optionControl.exists()).toEqual(true);
|
||||
optionControl.simulate('change',{target:{value:String(ANSWER_TYPE.PREDEFINED)}});
|
||||
expect(selectedValue).toBe(String(ANSWER_TYPE.PREDEFINED));
|
||||
|
||||
});
|
||||
|
||||
it('sets EXTERNAL_SOURCE_WP_TITLES value when WordPress titles is selected', () => {
|
||||
let selectedValue = null;
|
||||
|
||||
const wrapper = mount(<AnswerSourceForm
|
||||
onClose={()=>{}}
|
||||
onSave={()=>{}}
|
||||
onSourceChange={(value)=>{selectedValue=value}} />);
|
||||
|
||||
const optionControl = wrapper.find('SelectionControlGroup');
|
||||
expect(optionControl.exists()).toEqual(true);
|
||||
optionControl.simulate('change',{target:{value:String(ANSWER_TYPE.EXTERNAL_SOURCE_WP_TITLES)}});
|
||||
expect(selectedValue).toBe(String(ANSWER_TYPE.EXTERNAL_SOURCE_WP_TITLES));
|
||||
|
||||
});
|
||||
|
||||
it('sets EXTERNAL_SOURCE_WP_NEWS value when WordPress latest news is selected', () => {
|
||||
let selectedValue = null;
|
||||
|
||||
const wrapper = mount(<AnswerSourceForm
|
||||
onClose={()=>{}}
|
||||
onSave={()=>{}}
|
||||
onSourceChange={(value)=>{selectedValue=value}} />);
|
||||
|
||||
const optionControl = wrapper.find('SelectionControlGroup');
|
||||
expect(optionControl.exists()).toEqual(true);
|
||||
optionControl.simulate('change',{target:{value:String(ANSWER_TYPE.EXTERNAL_SOURCE_WP_NEWS)}});
|
||||
expect(selectedValue).toBe(String(ANSWER_TYPE.EXTERNAL_SOURCE_WP_NEWS));
|
||||
|
||||
});
|
||||
81
web/src/components/helper/__tests__/AnswerTextBox.test.js
Normal file
81
web/src/components/helper/__tests__/AnswerTextBox.test.js
Normal file
@@ -0,0 +1,81 @@
|
||||
import React from 'react';
|
||||
import {shallow, mount} from 'enzyme';
|
||||
import AnswerTextBox from '../AnswerTextBox';
|
||||
import {ANSWER_TYPE} from '../../../config/constants';
|
||||
|
||||
it ('renders without crashing', () => {
|
||||
shallow (<AnswerTextBox />);
|
||||
});
|
||||
|
||||
describe ('predefined answer selected', () => {
|
||||
let wrapper;
|
||||
let textField;
|
||||
|
||||
beforeEach (() => {
|
||||
const onChange = jest.fn();
|
||||
wrapper = mount (
|
||||
<AnswerTextBox
|
||||
answerType={ANSWER_TYPE.PREDEFINED}
|
||||
answer={'Dummy answer'}
|
||||
handleAnswerEdit={onChange}
|
||||
/>
|
||||
);
|
||||
textField = wrapper.find ('TextField').first ();
|
||||
});
|
||||
|
||||
it ('renders text box for normal answer', () => {
|
||||
expect (textField.props ().label).toEqual ('Answer');
|
||||
});
|
||||
|
||||
it ('receives valid answer text', () => {
|
||||
expect (textField.props ().value).toEqual ('Dummy answer');
|
||||
});
|
||||
});
|
||||
|
||||
describe ('WordPress titles selected', () => {
|
||||
let wrapper;
|
||||
let textField;
|
||||
beforeEach (() => {
|
||||
const onChange = jest.fn();
|
||||
wrapper = mount (
|
||||
<AnswerTextBox
|
||||
answerType={ANSWER_TYPE.EXTERNAL_SOURCE_WP_TITLES}
|
||||
externalAnswerSource={'Dummy answer'}
|
||||
handleAnswerSourceEdit={onChange}
|
||||
/>
|
||||
);
|
||||
textField = wrapper.find ('TextField').first ();
|
||||
});
|
||||
|
||||
it ('renders text box for external source input', () => {
|
||||
expect (textField.props ().label).toEqual ('Answer source');
|
||||
});
|
||||
|
||||
it ('receives valid answer text', () => {
|
||||
expect (textField.props ().value).toEqual ('Dummy answer');
|
||||
});
|
||||
});
|
||||
|
||||
describe ('WordPress latest news selected', () => {
|
||||
let wrapper;
|
||||
let textField;
|
||||
beforeEach (() => {
|
||||
const onChange = jest.fn();
|
||||
wrapper = mount (
|
||||
<AnswerTextBox
|
||||
answerType={ANSWER_TYPE.EXTERNAL_SOURCE_WP_NEWS}
|
||||
externalAnswerSource={'Dummy answer'}
|
||||
handleAnswerSourceEdit={onChange}
|
||||
/>
|
||||
);
|
||||
textField = wrapper.find ('TextField').first ();
|
||||
});
|
||||
|
||||
it ('renders text box for external source input', () => {
|
||||
expect (textField.props ().label).toEqual ('Answer source');
|
||||
});
|
||||
|
||||
it ('receives valid answer text', () => {
|
||||
expect (textField.props ().value).toEqual ('Dummy answer');
|
||||
});
|
||||
});
|
||||
16
web/src/components/helper/__tests__/Modal.test.js
Normal file
16
web/src/components/helper/__tests__/Modal.test.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import React from 'react';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
import Modal from '../Modal';
|
||||
|
||||
it('renders without crashing', () => {
|
||||
shallow(<Modal />);
|
||||
});
|
||||
|
||||
it('receives props as expected', () =>{
|
||||
const actionButton = <button key={0}>Dummy action button</button>;
|
||||
const childButton = <button key={1}>Child button</button>;
|
||||
const wrapper = mount(<Modal title={'Dummy title'} actions={[actionButton]}>{childButton}</Modal>);
|
||||
expect(wrapper.props().title).toEqual('Dummy title');
|
||||
expect(wrapper.props().actions).toEqual([actionButton]);
|
||||
expect(wrapper.props().children).toEqual(childButton);
|
||||
});
|
||||
Reference in New Issue
Block a user