From 4d2cf52e4c3d6102242462ca649c39ea7f7e83a9 Mon Sep 17 00:00:00 2001 From: GotPPay Date: Wed, 4 Apr 2018 01:09:29 +0200 Subject: [PATCH] add snapshot tests for 'import-from-source' part --- web/package-lock.json | 3 +- web/package.json | 1 + .../components/__tests__/AnswerSource.test.js | 73 +- .../__snapshots__/AnswerSource.test.js.snap | 93 +++ .../helper/__tests__/AnswerSourceForm.test.js | 5 + .../helper/__tests__/AnswerTextBox.test.js | 12 + .../components/helper/__tests__/Modal.test.js | 17 +- .../AnswerSourceForm.test.js.snap | 675 ++++++++++++++++++ .../__snapshots__/AnswerTextBox.test.js.snap | 376 ++++++++++ .../__snapshots__/Modal.test.js.snap | 42 ++ 10 files changed, 1260 insertions(+), 37 deletions(-) create mode 100644 web/src/components/__tests__/__snapshots__/AnswerSource.test.js.snap create mode 100644 web/src/components/helper/__tests__/__snapshots__/AnswerSourceForm.test.js.snap create mode 100644 web/src/components/helper/__tests__/__snapshots__/AnswerTextBox.test.js.snap create mode 100644 web/src/components/helper/__tests__/__snapshots__/Modal.test.js.snap diff --git a/web/package-lock.json b/web/package-lock.json index ea0b362..42c84e5 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -4382,8 +4382,7 @@ }, "jsbn": { "version": "0.1.1", - "bundled": true, - "optional": true + "bundled": true }, "json-schema": { "version": "0.2.3", diff --git a/web/package.json b/web/package.json index 542eca5..25bc015 100644 --- a/web/package.json +++ b/web/package.json @@ -29,6 +29,7 @@ "babel-jest": "^22.4.3", "enzyme": "^3.3.0", "enzyme-adapter-react-16": "^1.1.1", + "enzyme-to-json": "^3.3.3", "jest": "^20.0.3", "jest-enzyme": "^6.0.0", "nodemon": "^1.12.1", diff --git a/web/src/components/__tests__/AnswerSource.test.js b/web/src/components/__tests__/AnswerSource.test.js index 437a47b..c775523 100644 --- a/web/src/components/__tests__/AnswerSource.test.js +++ b/web/src/components/__tests__/AnswerSource.test.js @@ -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 (); }); - -describe('functional tests', ()=>{ +describe ('functional tests', () => { let wrapper; - beforeEach(()=>{ - const onSaveAnswerTypeFunction = jest.fn(); - wrapper = mount(); - wrapper.setState({ + beforeEach (() => { + const onSaveAnswerTypeFunction = jest.fn (); + wrapper = mount ( + + ); + 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); }); -}); \ No newline at end of file +}); diff --git a/web/src/components/__tests__/__snapshots__/AnswerSource.test.js.snap b/web/src/components/__tests__/__snapshots__/AnswerSource.test.js.snap new file mode 100644 index 0000000..3279bc9 --- /dev/null +++ b/web/src/components/__tests__/__snapshots__/AnswerSource.test.js.snap @@ -0,0 +1,93 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`functional tests snapshot 1`] = ` + +
+ + + } + onClick={[Function]} + primary={true} + > + + + + +
+
+`; diff --git a/web/src/components/helper/__tests__/AnswerSourceForm.test.js b/web/src/components/helper/__tests__/AnswerSourceForm.test.js index 37b8f45..d42a78a 100644 --- a/web/src/components/helper/__tests__/AnswerSourceForm.test.js +++ b/web/src/components/helper/__tests__/AnswerSourceForm.test.js @@ -7,6 +7,11 @@ it('renders without crashing', () => { shallow({}} onSave={()=>{}} onSourceChange={()=>{}} />); }); +it ('snapshot',()=>{ + const wrapper = mount({}} onSave={()=>{}} onSourceChange={()=>{}} />); + expect(wrapper).toMatchSnapshot(); +}) + it('calls onClose when cancel is pressed', () => { const onClose = jest.fn(); const wrapper = mount({}} onSourceChange={()=>{}} />); diff --git a/web/src/components/helper/__tests__/AnswerTextBox.test.js b/web/src/components/helper/__tests__/AnswerTextBox.test.js index e88b745..d74dfb8 100644 --- a/web/src/components/helper/__tests__/AnswerTextBox.test.js +++ b/web/src/components/helper/__tests__/AnswerTextBox.test.js @@ -23,6 +23,10 @@ describe ('predefined answer selected', () => { textField = wrapper.find ('TextField').first (); }); + it ('snapshot', () =>{ + expect(wrapper).toMatchSnapshot(); + }); + it ('renders text box for normal answer', () => { expect (textField.props ().label).toEqual ('Answer'); }); @@ -47,6 +51,10 @@ describe ('WordPress titles selected', () => { textField = wrapper.find ('TextField').first (); }); + it ('snapshot', () =>{ + expect(wrapper).toMatchSnapshot(); + }); + it ('renders text box for external source input', () => { expect (textField.props ().label).toEqual ('Answer source'); }); @@ -71,6 +79,10 @@ describe ('WordPress latest news selected', () => { textField = wrapper.find ('TextField').first (); }); + it ('snapshot', () =>{ + expect(wrapper).toMatchSnapshot(); + }); + it ('renders text box for external source input', () => { expect (textField.props ().label).toEqual ('Answer source'); }); diff --git a/web/src/components/helper/__tests__/Modal.test.js b/web/src/components/helper/__tests__/Modal.test.js index 1355844..b2df126 100644 --- a/web/src/components/helper/__tests__/Modal.test.js +++ b/web/src/components/helper/__tests__/Modal.test.js @@ -6,10 +6,21 @@ it('renders without crashing', () => { shallow(); }); +let actionButton; +let childButton; +let wrapper; + +beforeEach(()=>{ + actionButton = ; + childButton = ; + wrapper = mount({childButton}); +}); + +it ('snapshot', () => { + expect(wrapper).toMatchSnapshot(); +}); + it('receives props as expected', () =>{ - const actionButton = ; - const childButton = ; - const wrapper = mount({childButton}); expect(wrapper.props().title).toEqual('Dummy title'); expect(wrapper.props().actions).toEqual([actionButton]); expect(wrapper.props().children).toEqual(childButton); diff --git a/web/src/components/helper/__tests__/__snapshots__/AnswerSourceForm.test.js.snap b/web/src/components/helper/__tests__/__snapshots__/AnswerSourceForm.test.js.snap new file mode 100644 index 0000000..6945070 --- /dev/null +++ b/web/src/components/helper/__tests__/__snapshots__/AnswerSourceForm.test.js.snap @@ -0,0 +1,675 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snapshot 1`] = ` + + + Cancel + , + + Save + , + ] + } + title="Answer type" + > +
+
+

+ Answer type +

+ +
+ + Import answer from: + + + check_box + + } + checkedRadioIcon={ + + radio_button_checked + + } + className="" + id="answer-source0" + key="control0" + label="Predefined answer" + name="answer-source" + type="radio" + uncheckedCheckboxIcon={ + + check_box_outline_blank + + } + uncheckedRadioIcon={ + + radio_button_unchecked + + } + value="0" + > +
+ +
+
+
+ + + } + onClick={[Function]} + swapTheming={true} + > + + + + + + + } + onClick={[Function]} + primary={true} + swapTheming={true} + > + + + + +
+
+
+
+
+`; diff --git a/web/src/components/helper/__tests__/__snapshots__/AnswerTextBox.test.js.snap b/web/src/components/helper/__tests__/__snapshots__/AnswerTextBox.test.js.snap new file mode 100644 index 0000000..8de1500 --- /dev/null +++ b/web/src/components/helper/__tests__/__snapshots__/AnswerTextBox.test.js.snap @@ -0,0 +1,376 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`WordPress latest news selected snapshot 1`] = ` + +
+ + remove_red_eye + + } + placeholder="Answer source" + rightIconStateful={true} + type="text" + value="Dummy answer" + > +
+ + + + + + + + +
+
+
+ +
+ + +
+ 12 / 150 +
+
+
+
+
+
+
+
+`; + +exports[`WordPress titles selected snapshot 1`] = ` + +
+ + remove_red_eye + + } + placeholder="Answer source" + rightIconStateful={true} + type="text" + value="Dummy answer" + > +
+ + + + + + + + +
+
+
+ +
+ + +
+ 12 / 150 +
+
+
+
+
+
+
+
+`; + +exports[`predefined answer selected snapshot 1`] = ` + +
+ + remove_red_eye + + } + placeholder="Answer" + rightIconStateful={true} + type="text" + value="Dummy answer" + > +
+ + + + + + + + +
+
+
+ +
+ + +
+ 12 / 150 +
+
+
+
+
+
+
+
+`; diff --git a/web/src/components/helper/__tests__/__snapshots__/Modal.test.js.snap b/web/src/components/helper/__tests__/__snapshots__/Modal.test.js.snap new file mode 100644 index 0000000..2404e5d --- /dev/null +++ b/web/src/components/helper/__tests__/__snapshots__/Modal.test.js.snap @@ -0,0 +1,42 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snapshot 1`] = ` + + Dummy action button + , + ] + } + title="Dummy title" +> +
+
+

+ Dummy title +

+ +
+ +
+
+
+
+`;