diff --git a/client/src/core-components/__tests__/form-test.js b/client/src/core-components/__tests__/form-test.js index 46136923..a778d6b4 100644 --- a/client/src/core-components/__tests__/form-test.js +++ b/client/src/core-components/__tests__/form-test.js @@ -1,11 +1,16 @@ // MOCKS const ValidationFactoryMock = require('lib-app/__mocks__/validations/validation-factory-mock'); -const Input = ReactMock(); +const FormField = ReactMock(); +const {EditorState} = require('draft-js'); +const draftJsExportHTML = { + stateToHTML: stub().returns('HTML_CODE') +}; // COMPONENT const Form = requireUnit('core-components/form', { 'lib-app/validations/validations-factory': ValidationFactoryMock, - 'core-components/input': Input + 'draft-js-export-html': draftJsExportHTML, + 'core-components/form-field': FormField }); describe('Form component', function () { @@ -15,13 +20,13 @@ describe('Form component', function () { form = TestUtils.renderIntoDocument(
); - fields = TestUtils.scryRenderedComponentsWithType(form, Input); + fields = TestUtils.scryRenderedComponentsWithType(form, FormField); } function resetStubs() { @@ -117,7 +122,7 @@ describe('Form component', function () { }); afterEach(resetStubs); - it('should pass the errors to inputs', function () { + it('should pass the errors to fields', function () { expect(fields[0].props.error).to.equal('MOCK_ERROR_CONTROLLED'); expect(fields[1].props.error).to.equal(undefined); }); @@ -138,13 +143,13 @@ describe('Form component', function () { form = reRenderIntoDocument( ); - fields = TestUtils.scryRenderedComponentsWithType(form, Input); + fields = TestUtils.scryRenderedComponentsWithType(form, FormField); } setErrorsOrRender(); @@ -171,6 +176,19 @@ describe('Form component', function () { expect(form.props.onSubmit).to.have.been.calledWith(form.state.form); }); + it('should tranform EditorState to HTML usign draft-js-export-html library', function () { + draftJsExportHTML.stateToHTML.reset(); + form.state.form.first = EditorState.createEmpty(); + + TestUtils.Simulate.submit(ReactDOM.findDOMNode(form)); + expect(draftJsExportHTML.stateToHTML).to.have.been.calledWith(form.state.form.first.getCurrentContent()); + expect(form.props.onSubmit).to.have.been.calledWith({ + first: 'HTML_CODE', + second: 'value2', + third: 'value3' + }); + }); + it('should validate all fields and not call onSubmit if there are errors', function () { ValidationFactoryMock.validators.defaultValidatorMock.performValidation = stub().returns('MOCK_ERROR'); ValidationFactoryMock.validators.customValidatorMock.performValidation = stub().returns('MOCK_ERROR_2');