Repository: ambari Updated Branches: refs/heads/trunk ecaf2d15f -> 9dfbf91df
AMBARI-10534. Alert notification with invalid parameters can be created after switching method value (alexantonenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9dfbf91d Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9dfbf91d Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9dfbf91d Branch: refs/heads/trunk Commit: 9dfbf91df05320ab382a714d1186685645c4c35e Parents: ecaf2d1 Author: Alex Antonenko <hiv...@gmail.com> Authored: Thu Apr 16 21:10:51 2015 +0300 Committer: Alex Antonenko <hiv...@gmail.com> Committed: Thu Apr 16 21:10:51 2015 +0300 ---------------------------------------------------------------------- .../manage_alert_notifications_controller.js | 51 ++++++++++++++++---- ...anage_alert_notifications_controller_test.js | 44 +++++++++++++---- 2 files changed, 76 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/9dfbf91d/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js index 101df64..19d2f9e 100644 --- a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js +++ b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js @@ -233,6 +233,37 @@ App.ManageAlertNotificationsController = Em.Controller.extend({ 'mail.smtp.starttls.enable' ], + validationMap: { + EMAIL: [ + { + errorKey: 'emailToError', + validator: 'emailToValidation' + }, + { + errorKey: 'emailFromError', + validator: 'emailFromValidation' + }, + { + errorKey: 'smtpPortError', + validator: 'smtpPortValidation' + }, + { + errorKey: 'passwordError', + validator: 'retypePasswordValidation' + } + ], + SNMP: [ + { + errorKey: 'portError', + validator: 'portValidation' + }, + { + errorKey: 'hostError', + validator: 'hostsValidation' + } + ] + }, + /** * Load all Alert Notifications from server * @method loadAlertNotifications @@ -372,15 +403,17 @@ App.ManageAlertNotificationsController = Em.Controller.extend({ return this.get('controller.inputFields.method.value') === 'EMAIL'; }.property('controller.inputFields.method.value'), - clearValidationErrors: function () { - var linkedErrorsMap = { - EMAIL: ['emailToError', 'emailFromError', 'smtpPortError', 'passwordError'], - SNMP: ['portError', 'hostError'] - }, - method = this.get('controller.inputFields.method.value'); - Em.keys(linkedErrorsMap).forEach(function (name) { - if (name != method) { - linkedErrorsMap[name].forEach(function (key) { + methodObserver: function () { + var currentMethod = this.get('controller.inputFields.method.value'), + validationMap = self.get('validationMap'); + self.get('methods').forEach(function (method) { + var validations = validationMap[method]; + if (method == currentMethod) { + validations.mapProperty('validator').forEach(function (key) { + this.get(key).call(this); + }, this); + } else { + validations.mapProperty('errorKey').forEach(function (key) { this.set(key, false); }, this); } http://git-wip-us.apache.org/repos/asf/ambari/blob/9dfbf91d/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js index 7f68fce..a74839b 100644 --- a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js +++ b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js @@ -645,18 +645,39 @@ describe('App.ManageAlertNotificationsController', function () { }); - describe('#clearValidationErrors', function () { + describe('#methodObserver', function () { var cases = [ - { - method: 'EMAIL', - errors: ['portError', 'hostError'] - }, - { - method: 'SNMP', - errors: ['emailToError', 'emailFromError', 'smtpPortError', 'passwordError'] - } - ]; + { + method: 'EMAIL', + errors: ['portError', 'hostError'], + validators: ['emailToValidation', 'emailFromValidation', 'smtpPortValidation', 'retypePasswordValidation'] + }, + { + method: 'SNMP', + errors: ['emailToError', 'emailFromError', 'smtpPortError', 'passwordError'], + validators: ['portValidation', 'hostsValidation'] + } + ], + validators = []; + + before(function () { + cases.forEach(function (item) { + validators.pushObjects(item.validators); + }); + }); + + beforeEach(function () { + validators.forEach(function (item) { + sinon.stub(view, item, Em.K); + }); + }); + + afterEach(function () { + validators.forEach(function (item) { + view.get(item).restore(); + }); + }); cases.forEach(function (item) { it(item.method, function () { @@ -667,6 +688,9 @@ describe('App.ManageAlertNotificationsController', function () { item.errors.forEach(function (errorName) { expect(view.get(errorName)).to.be.false; }); + validators.forEach(function (validatorName) { + expect(view.get(validatorName).calledOnce).to.equal(item.validators.contains(validatorName)); + }); }); });