From e05f856ee0555ea5d9ba44f4cddd87eed1ac9417 Mon Sep 17 00:00:00 2001 From: George Schneeloch Date: Thu, 10 Sep 2015 17:32:11 -0400 Subject: [PATCH] Cleared message box on changes to the UI --- ui/jstests/test-learning-resource.jsx | 61 ++++++++++++++++++++++++++ ui/static/ui/js/learning_resources.jsx | 21 ++++++++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/ui/jstests/test-learning-resource.jsx b/ui/jstests/test-learning-resource.jsx index 51f479c6..76dc9c48 100644 --- a/ui/jstests/test-learning-resource.jsx +++ b/ui/jstests/test-learning-resource.jsx @@ -488,6 +488,67 @@ define(['QUnit', 'jquery', 'react', 'lodash', 'learning_resources', } ); + QUnit.test('If terms or description are changed, clear error messages', + function (assert) { + var done = assert.async(); + + var afterMount = function (component) { + waitForAjax(3, function () { + // Set component message then type into description to clear it. + component.setState({message: "Hello, world!"}, function () { + var textarea = React.addons.TestUtils. + findRenderedDOMComponentWithTag( + component, + 'textarea' + ); + + React.addons.TestUtils.Simulate.change(textarea, {value: "x"}); + component.forceUpdate(function () { + assert.equal(component.state.message, undefined); + + // Reset component message then adjust vocabs list to clear it. + component.setState({message: "Hello, world!"}, function () { + var selects = _.map(React.addons.TestUtils. + scryRenderedDOMComponentsWithTag( + component, + 'select' + ), function(piece) { + return React.findDOMNode(piece); + }); + + // First is vocab, second is terms + assert.equal(selects.length, 2); + $(selects[0]).val('difficulty').trigger('change'); + component.forceUpdate(function () { + assert.equal(component.state.message, undefined); + + // Reset component message then adjust term list to clear it. + component.setState({message: {error: "Error!"}}, function () { + $(selects[1]).val('required').trigger('change'); + + component.forceUpdate(function () { + assert.equal(component.state.message, undefined); + + done(); + }); + }); + }); + }); + }); + }); + }); + }; + + React.addons.TestUtils.renderIntoDocument( + + ); + } + ); + QUnit.test( "LearningResourcePanel.loader should populate its stuff", function(assert) { diff --git a/ui/static/ui/js/learning_resources.jsx b/ui/static/ui/js/learning_resources.jsx index 15596a8b..c6feeb18 100644 --- a/ui/static/ui/js/learning_resources.jsx +++ b/ui/static/ui/js/learning_resources.jsx @@ -90,6 +90,9 @@ define('learning_resources', this.props.setValues( _.pluck(this.props.vocabs, 'vocabulary'), selectedValue[0] ); + + // clear message + this.props.reportMessage(undefined); } }); @@ -142,6 +145,10 @@ define('learning_resources', _.filter(e.target.options, function(option) { return option.selected && option.value !== null; }), 'value'); + + // clear messages + this.props.reportMessage(undefined); + // check if the current vocabulary allows free tagging and in case add // the new tags before proceeding if (this.props.selectedVocabulary.vocabulary_type === 'f') { @@ -242,7 +249,8 @@ define('learning_resources', var selectedVocabulary = this.state.selectedVocabulary; selectedVocabulary.terms.push(termObj); this.setState({ - selectedVocabulary: selectedVocabulary + selectedVocabulary: selectedVocabulary, + message: undefined }); }, @@ -264,6 +272,7 @@ define('learning_resources', vocabs={vocabulariesAndTerms} selectedVocabulary={this.state.selectedVocabulary} setValues={this.setSelectedVocabulary} + reportMessage={this.reportMessage} />; termSelector = @@ -297,7 +306,8 @@ define('learning_resources',

@@ -316,6 +326,13 @@ define('learning_resources', ; }, + handleDescription: function(event) { + event.preventDefault(); + this.setState({ + description: event.target.value, + message: undefined + }); + }, saveLearningResourcePanel: function (event) { event.preventDefault(); this.saveForm(false);