Repository: ambari Updated Branches: refs/heads/trunk 91c628dad -> f24ae8c0b
AMBARI-11264 Closing Edit widget wizard navigates to incorrect service. (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f24ae8c0 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f24ae8c0 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f24ae8c0 Branch: refs/heads/trunk Commit: f24ae8c0b241770d7a281cd5f6cbc79c88cd1406 Parents: 91c628d Author: Andrii Tkach <[email protected]> Authored: Wed May 20 14:37:26 2015 +0300 Committer: Andrii Tkach <[email protected]> Committed: Wed May 20 17:50:55 2015 +0300 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 1 + .../service/widgets/create/step3_controller.js | 54 ++--- .../service/widgets/create/wizard_controller.js | 4 +- .../widgets/create/step3_controller_test.js | 208 +++++++++++++++++++ 4 files changed, 240 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/f24ae8c0/ambari-web/app/assets/test/tests.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index 95e9f35..9dc1c12 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -90,6 +90,7 @@ var files = ['test/init_model_test', 'test/controllers/main/service/widgets/create/wizard_controller_test', 'test/controllers/main/service/widgets/create/step1_controller_test', 'test/controllers/main/service/widgets/create/step2_controller_test', + 'test/controllers/main/service/widgets/create/step3_controller_test', 'test/controllers/main/dashboard_test', 'test/controllers/main/host_test', 'test/controllers/main/service/item_test', http://git-wip-us.apache.org/repos/asf/ambari/blob/f24ae8c0/ambari-web/app/controllers/main/service/widgets/create/step3_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/widgets/create/step3_controller.js b/ambari-web/app/controllers/main/service/widgets/create/step3_controller.js index 00b12f4..4c9dc81 100644 --- a/ambari-web/app/controllers/main/service/widgets/create/step3_controller.js +++ b/ambari-web/app/controllers/main/service/widgets/create/step3_controller.js @@ -49,24 +49,9 @@ App.WidgetWizardStep3Controller = Em.Controller.extend({ * @type {string} */ widgetScope: function () { - return this.get('isSharedChecked')? 'Cluster': 'User'; + return this.get('isSharedChecked') ? 'Cluster' : 'User'; }.property('isSharedChecked'), - showConfirmationOnSharing: function () { - var self = this; - if(this.get('isSharedChecked')) { - var bodyMessage = Em.Object.create({ - confirmMsg: Em.I18n.t('dashboard.widgets.browser.action.share.confirmation'), - confirmButton: Em.I18n.t('dashboard.widgets.browser.action.share') - }); - return App.showConfirmationFeedBackPopup(function (query) { - self.set('isSharedChecked', true); - }, bodyMessage, function (query) { - self.set('isSharedChecked', false); - }); - } - }, - /** * @type {string} */ @@ -89,6 +74,13 @@ App.WidgetWizardStep3Controller = Em.Controller.extend({ widgetMetrics: [], /** + * @type {boolean} + */ + isSubmitDisabled: function () { + return this.get('widgetName') ? !Boolean(this.get('widgetName').trim()) : true; + }.property('widgetName'), + + /** * restore widget data set on 2nd step */ initPreviewData: function () { @@ -99,16 +91,29 @@ App.WidgetWizardStep3Controller = Em.Controller.extend({ this.set('widgetName', this.get('content.widgetName')); this.set('widgetDescription', this.get('content.widgetDescription')); this.set('isSharedChecked', this.get('content.widgetScope') == 'CLUSTER'); - // on editing, dont allow changing from shared scope to unshare - this.set('isSharedCheckboxDisabled', this.get('content.widgetScope') == 'CLUSTER' && - this.get('isEditController')); + // on editing, don't allow changing from shared scope to unshare + this.set('isSharedCheckboxDisabled', this.get('content.widgetScope') == 'CLUSTER' && this.get('isEditController')); this.addObserver('isSharedChecked', this, this.showConfirmationOnSharing); }, - isSubmitDisabled: function () { - var widgetName = this.get('widgetName')? this.get('widgetName').trim(): null; - return !(widgetName); - }.property('widgetName'), + /** + * confirmation popup + * @returns {App.ModalPopup|undefined} + */ + showConfirmationOnSharing: function () { + var self = this; + if (this.get('isSharedChecked')) { + var bodyMessage = Em.Object.create({ + confirmMsg: Em.I18n.t('dashboard.widgets.browser.action.share.confirmation'), + confirmButton: Em.I18n.t('dashboard.widgets.browser.action.share') + }); + return App.showConfirmationFeedBackPopup(function (query) { + self.set('isSharedChecked', true); + }, bodyMessage, function (query) { + self.set('isSharedChecked', false); + }); + } + }, /** * collect all needed data to create new widget @@ -136,8 +141,7 @@ App.WidgetWizardStep3Controller = Em.Controller.extend({ }, cancel: function () { - var controller = App.router.get(this.get('content.controllerName')); - controller.cancel(); + App.router.get(this.get('content.controllerName')).cancel(); }, complete: function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/f24ae8c0/ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js b/ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js index 0fec8eb..7dd6cc3 100644 --- a/ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js +++ b/ambari-web/app/controllers/main/service/widgets/create/wizard_controller.js @@ -405,10 +405,10 @@ App.WidgetWizardController = App.WizardController.extend({ * finish wizard */ finishWizard: function () { + var service = App.Service.find(this.get('content.widgetService')); + this.finish(); this.get('popup').hide(); - var serviceName = this.get('content.widgetService'); - var service = App.Service.find(serviceName); App.router.transitionTo('main.services.service.summary', service); if (!App.get('testMode')) { App.clusterStatus.setClusterStatus({ http://git-wip-us.apache.org/repos/asf/ambari/blob/f24ae8c0/ambari-web/test/controllers/main/service/widgets/create/step3_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service/widgets/create/step3_controller_test.js b/ambari-web/test/controllers/main/service/widgets/create/step3_controller_test.js new file mode 100644 index 0000000..041b0ff --- /dev/null +++ b/ambari-web/test/controllers/main/service/widgets/create/step3_controller_test.js @@ -0,0 +1,208 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +App = require('app'); + +require('controllers/main/service/widgets/create/step3_controller'); + + +describe('App.WidgetWizardStep3Controller', function () { + var controller = App.WidgetWizardStep3Controller.create({ + content: Em.Object.create() + }); + + describe("#isEditController", function () { + it("empty name", function () { + controller.set('content.controllerName', ''); + controller.propertyDidChange('isEditController'); + expect(controller.get('isEditController')).to.be.false; + }); + it("widgetEditController name", function () { + controller.set('content.controllerName', 'widgetEditController'); + controller.propertyDidChange('isEditController'); + expect(controller.get('isEditController')).to.be.true; + }); + }); + + describe("#widgetScope", function () { + it("isSharedChecked - false", function () { + controller.set('isSharedChecked', false); + controller.propertyDidChange('widgetScope'); + expect(controller.get('widgetScope')).to.equal('User'); + }); + it("isSharedChecked - true", function () { + controller.set('isSharedChecked', true); + controller.propertyDidChange('widgetScope'); + expect(controller.get('widgetScope')).to.equal('Cluster'); + }); + }); + + describe("#isSubmitDisabled", function () { + it("widgetName - null", function () { + controller.set('widgetName', null); + controller.propertyDidChange('isSubmitDisabled'); + expect(controller.get('isSubmitDisabled')).to.be.true; + }); + it("widgetName empty ", function () { + controller.set('widgetName', ''); + controller.propertyDidChange('isSubmitDisabled'); + expect(controller.get('isSubmitDisabled')).to.be.true; + }); + it("widgetName contains only whitespace", function () { + controller.set('widgetName', ' '); + controller.propertyDidChange('isSubmitDisabled'); + expect(controller.get('isSubmitDisabled')).to.be.true; + }); + it("widgetName correct", function () { + controller.set('widgetName', 'w1'); + controller.propertyDidChange('isSubmitDisabled'); + expect(controller.get('isSubmitDisabled')).to.be.false; + }); + }); + + describe("#initPreviewData()", function () { + beforeEach(function () { + sinon.stub(controller, 'addObserver'); + }); + afterEach(function () { + controller.addObserver.restore(); + }); + it("", function () { + controller.set('content', Em.Object.create({ + widgetProperties: 'widgetProperties', + widgetValues: 'widgetValues', + widgetMetrics: 'widgetMetrics', + widgetAuthor: 'widgetAuthor', + widgetName: 'widgetName', + widgetDescription: 'widgetDescription', + widgetScope: 'CLUSTER', + controllerName: 'widgetEditController' + })); + controller.initPreviewData(); + expect(controller.addObserver.calledWith('isSharedChecked')).to.be.true; + expect(controller.get('widgetProperties')).to.equal('widgetProperties'); + expect(controller.get('widgetValues')).to.equal('widgetValues'); + expect(controller.get('widgetMetrics')).to.equal('widgetMetrics'); + expect(controller.get('widgetAuthor')).to.equal('widgetAuthor'); + expect(controller.get('widgetName')).to.equal('widgetName'); + expect(controller.get('widgetDescription')).to.equal('widgetDescription'); + expect(controller.get('isSharedChecked')).to.be.true; + expect(controller.get('isSharedCheckboxDisabled')).to.be.true; + }); + }); + + describe("#showConfirmationOnSharing()", function () { + beforeEach(function () { + sinon.spy(App, 'showConfirmationFeedBackPopup'); + }); + afterEach(function () { + App.showConfirmationFeedBackPopup.restore(); + }); + it("isSharedChecked - false", function () { + controller.set('isSharedChecked', false); + controller.showConfirmationOnSharing(); + expect(App.showConfirmationFeedBackPopup.called).to.be.false; + }); + it("isSharedChecked - true", function () { + controller.set('isSharedChecked', true); + var popup = controller.showConfirmationOnSharing(); + expect(App.showConfirmationFeedBackPopup.calledOnce).to.be.true; + popup.onSecondary(); + expect(controller.get('isSharedChecked')).to.be.false; + popup.onPrimary(); + expect(controller.get('isSharedChecked')).to.be.true; + }); + }); + + describe("#collectWidgetData()", function () { + it("", function () { + controller.setProperties({ + widgetName: 'widgetName', + content: Em.Object.create({widgetType: 'T1'}), + widgetDescription: 'widgetDescription', + widgetScope: 'Cluster', + widgetAuthor: 'widgetAuthor', + widgetMetrics: [{data: 'data', name: 'm1'}], + widgetValues: [{computedValue: 'cv', value: 'v'}], + widgetProperties: 'widgetProperties' + }); + expect(controller.collectWidgetData()).to.eql({ + "WidgetInfo": { + "widget_name": "widgetName", + "widget_type": "T1", + "description": "widgetDescription", + "scope": "CLUSTER", + "author": "widgetAuthor", + "metrics": [ + { + "name": "m1" + } + ], + "values": [ + { + "value": "v" + } + ], + "properties": "widgetProperties" + } + }); + }); + }); + + describe("#cancel()", function () { + var mock = { + cancel: Em.K + }; + beforeEach(function () { + sinon.spy(mock, 'cancel'); + sinon.stub(App.router, 'get').returns(mock); + }); + afterEach(function () { + App.router.get.restore(); + mock.cancel.restore(); + }); + it("", function () { + controller.cancel(); + expect(mock.cancel.calledOnce).to.be.true; + }); + }); + + describe("#complete()", function () { + var mock = { + finishWizard: Em.K + }; + beforeEach(function () { + sinon.spy(mock, 'finishWizard'); + sinon.stub(controller, 'collectWidgetData'); + sinon.stub(App.router, 'get').returns(mock); + sinon.stub(App.router, 'send'); + }); + afterEach(function () { + App.router.get.restore(); + App.router.send.restore(); + controller.collectWidgetData.restore(); + mock.finishWizard.restore(); + }); + it("", function () { + controller.complete(); + expect(controller.collectWidgetData.calledOnce).to.be.true; + expect(App.router.send.calledWith('complete')).to.be.true; + expect(mock.finishWizard.calledOnce).to.be.true; + }); + }); +});
