AMBARI-14319. Add common tests for Em.computed macros (2) (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8750537a Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8750537a Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8750537a Branch: refs/heads/trunk Commit: 8750537a335f1975bdee53ff229b6a7a2cb07a4d Parents: 4330659 Author: Oleg Nechiporenko <onechipore...@apache.org> Authored: Thu Dec 10 16:07:57 2015 +0200 Committer: Oleg Nechiporenko <onechipore...@apache.org> Committed: Thu Dec 10 16:07:57 2015 +0200 ---------------------------------------------------------------------- .../widgets/hbase_regions_in_transition.js | 4 +- .../views/main/dashboard/widgets/text_widget.js | 4 +- ambari-web/test/aliases/computed/and.js | 75 ++++++++++ ambari-web/test/aliases/computed/or.js | 76 ++++++++++ ambari-web/test/controllers/application_test.js | 31 ++-- .../global/cluster_controller_test.js | 4 + .../global/update_controller_test.js | 2 + .../controllers/main/admin/kerberos_test.js | 2 + .../definitions_configs_controller_test.js | 16 +- .../definitions_details_controller_test.js | 12 ++ ...anage_alert_notifications_controller_test.js | 25 +++- .../main/service/info/summary_test.js | 6 + .../widgets/create/step3_controller_test.js | 23 +-- .../test/controllers/wizard/step2_test.js | 42 +----- .../test/controllers/wizard/step3_test.js | 2 + .../test/controllers/wizard/step6_test.js | 52 +------ .../test/controllers/wizard/step7_test.js | 2 + ambari-web/test/init_computed_aliases.js | 31 +++- .../test/models/alerts/alert_definition_test.js | 10 +- .../objects/service_config_property_test.js | 2 + .../configs/service_config_version_test.js | 41 +----- .../test/models/configs/sub_section_test.js | 14 +- .../test/models/stack_service_component_test.js | 2 + .../configs/widgets/config_widget_view_test.js | 27 ++-- .../common/form/spinner_input_view_test.js | 9 +- .../stack_upgrade/upgrade_task_view_test.js | 29 +--- .../stack_upgrade/upgrade_wizard_view_test.js | 32 +--- .../main/alerts/definition_details_view_test.js | 23 ++- .../widgets/hbase_regions_in_transition_test.js | 2 + .../widgets/node_managers_live_test.js | 82 +---------- .../main/dashboard/widgets/text_widget_test.js | 2 + ambari-web/test/views/wizard/step1_view_test.js | 147 +------------------ 32 files changed, 354 insertions(+), 477 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/app/views/main/dashboard/widgets/hbase_regions_in_transition.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/dashboard/widgets/hbase_regions_in_transition.js b/ambari-web/app/views/main/dashboard/widgets/hbase_regions_in_transition.js index 3c22a5c..18902b5 100644 --- a/ambari-web/app/views/main/dashboard/widgets/hbase_regions_in_transition.js +++ b/ambari-web/app/views/main/dashboard/widgets/hbase_regions_in_transition.js @@ -33,10 +33,8 @@ App.HBaseRegionsInTransitionView = App.TextDashboardWidgetView.extend({ classNameBindings: ['isRed', 'isOrange', 'isGreen', 'isNA'], isGreen: Em.computed.lteProperties('data', 'thresh1'), - isNotGreen: Em.computed.not('isGreen'), isRed: Em.computed.gtProperties('data', 'thresh2'), - isNotRed: Em.computed.not('isRed'), - isOrange: Em.computed.and('isNotGreen', 'isNotRed'), + isOrange: Em.computed.and('!isGreen', '!isRed'), isNA: function () { return this.get('data') === null; }.property('data'), http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/app/views/main/dashboard/widgets/text_widget.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/dashboard/widgets/text_widget.js b/ambari-web/app/views/main/dashboard/widgets/text_widget.js index 4389cb3..6d257a1 100644 --- a/ambari-web/app/views/main/dashboard/widgets/text_widget.js +++ b/ambari-web/app/views/main/dashboard/widgets/text_widget.js @@ -26,10 +26,8 @@ App.TextDashboardWidgetView = App.DashboardWidgetView.extend({ classNameBindings: ['isRed', 'isOrange', 'isGreen', 'isNA'], isRed: Em.computed.lteProperties('data', 'thresh1'), - isNotRed: Em.computed.not('isRed'), - isOrange: Em.computed.and('isNotGreen', 'isNotRed'), + isOrange: Em.computed.and('!isGreen', '!isRed'), isGreen: Em.computed.gtProperties('data', 'thresh2'), - isNotGreen: Em.computed.not('isGreen'), isNA: function () { return this.get('data') === null; http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/aliases/computed/and.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/aliases/computed/and.js b/ambari-web/test/aliases/computed/and.js new file mode 100644 index 0000000..1e6ddf4 --- /dev/null +++ b/ambari-web/test/aliases/computed/and.js @@ -0,0 +1,75 @@ +/** + * 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. + */ + +var objectUtils = require('utils/object_utils'); + +var helpers = App.TestAliases.helpers; + +function getTrulyCombination(dependentKeys) { + var hash = {}; + dependentKeys.forEach(function (key) { + if (key.startsWith('!')) { + hash[key.substr(1)] = false; + } + else { + hash[key] = true; + } + }); + return hash; +} + +/** + * + * @param {Em.Object} context + * @param {string} propertyName + * @param {string[]} dependentKeys + */ +App.TestAliases.testAsComputedAnd = function (context, propertyName, dependentKeys) { + + var realKeys = dependentKeys.map(function (key) { + return key.startsWith('!') ? key.substr(1) : key; + }); + var trulyCombination = getTrulyCombination(dependentKeys); + var binaryCombos = helpers.getBinaryCombos(realKeys); + + describe('#' + propertyName + ' as Em.computed.and', function () { + + afterEach(function () { + helpers.smartRestoreGet(context); + }); + + it('has valid dependent keys', function () { + expect(Em.meta(context).descs[propertyName]._dependentKeys).to.eql(realKeys); + }); + + binaryCombos.forEach(function (combo) { + + var expectedResult = objectUtils.deepEqual(trulyCombination, combo); + + it('`' + expectedResult + '` for ' + JSON.stringify(combo), function() { + helpers.smartStubGet(context, combo) + .propertyDidChange(context, propertyName); + var value = helpers.smartGet(context, propertyName); + expect(value).to.equal(expectedResult); + }); + + }); + + }); + +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/aliases/computed/or.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/aliases/computed/or.js b/ambari-web/test/aliases/computed/or.js new file mode 100644 index 0000000..8bf25c5 --- /dev/null +++ b/ambari-web/test/aliases/computed/or.js @@ -0,0 +1,76 @@ +/** + * 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. + */ + +var objectUtils = require('utils/object_utils'); + +var helpers = App.TestAliases.helpers; + +function getFalsyCombination(dependentKeys) { + var hash = {}; + dependentKeys.forEach(function (key) { + if (key.startsWith('!')) { + hash[key.substr(1)] = true; + } + else { + hash[key] = false; + } + }); + return hash; +} + + +/** + * + * @param {Em.Object} context + * @param {string} propertyName + * @param {string[]} dependentKeys + */ +App.TestAliases.testAsComputedOr = function (context, propertyName, dependentKeys) { + + var realKeys = dependentKeys.map(function (key) { + return key.startsWith('!') ? key.substr(1) : key; + }); + var falsyCombination = getFalsyCombination(dependentKeys); + var binaryCombos = helpers.getBinaryCombos(realKeys); + + describe('#' + propertyName + ' as Em.computed.or', function () { + + afterEach(function () { + helpers.smartRestoreGet(context); + }); + + it('has valid dependent keys', function () { + expect(Em.meta(context).descs[propertyName]._dependentKeys).to.eql(realKeys); + }); + + binaryCombos.forEach(function (combo) { + + var expectedResult = !objectUtils.deepEqual(falsyCombination, combo); + + it('`' + expectedResult + '` for ' + JSON.stringify(combo), function() { + helpers.smartStubGet(context, combo) + .propertyDidChange(context, propertyName); + var value = helpers.smartGet(context, propertyName); + expect(value).to.equal(expectedResult); + }); + + }); + + }); + +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/application_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/application_test.js b/ambari-web/test/controllers/application_test.js index dbe5a96..efe5103 100644 --- a/ambari-web/test/controllers/application_test.js +++ b/ambari-web/test/controllers/application_test.js @@ -20,9 +20,17 @@ var App = require('app'); require('models/cluster'); +function getController() { + return App.ApplicationController.create(); +} + describe('App.ApplicationController', function () { - var applicationController = App.ApplicationController.create(); + var applicationController = getController(); + + App.TestAliases.testAsComputedAnd(getController(), 'isClusterDataLoaded', ['App.router.clusterController.isLoaded','App.router.loggedIn']); + + App.TestAliases.testAsComputedAnd(getController(), 'isExistingClusterDataLoaded', ['App.router.clusterInstallCompleted','isClusterDataLoaded']); describe('#showAboutPopup', function() { var dataToShowRes = {}; @@ -109,25 +117,4 @@ describe('App.ApplicationController', function () { }); }); - describe('#clusterDisplayName', function() { - it ('Should return cluster display name', function() { - applicationController.set('clusterName', ''); - expect(applicationController.get('clusterDisplayName')).to.equal('mycluster'); - }); - }); - - describe('#isClusterDataLoaded', function() { - beforeEach(function () { - var stub = sinon.stub(App, 'get'); - stub.withArgs('router.clusterController.isLoaded').returns(true); - stub.withArgs('router.loggedIn').returns(true); - }); - afterEach(function () { - App.get.restore(); - }); - it ('Should return true, when data loaded', function() { - expect(applicationController.get('isClusterDataLoaded')).to.be.true; - }); - }); - }); http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/global/cluster_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/global/cluster_controller_test.js b/ambari-web/test/controllers/global/cluster_controller_test.js index 2b01ea0..c2f3498 100644 --- a/ambari-web/test/controllers/global/cluster_controller_test.js +++ b/ambari-web/test/controllers/global/cluster_controller_test.js @@ -35,6 +35,10 @@ describe('App.clusterController', function () { {service_name: 'GANGLIA'} ]; + App.TestAliases.testAsComputedAnd(controller, 'isHostContentLoaded', ['isHostsLoaded', 'isComponentsStateLoaded']); + + App.TestAliases.testAsComputedAnd(controller, 'isServiceContentFullyLoaded', ['isServiceMetricsLoaded', 'isComponentsStateLoaded', 'isComponentsConfigLoaded']); + App.TestAliases.testAsComputedAlias(controller, 'clusterName', 'App.clusterName', 'string'); describe('#updateLoadStatus()', function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/global/update_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/global/update_controller_test.js b/ambari-web/test/controllers/global/update_controller_test.js index fc29aa0..482e58c 100644 --- a/ambari-web/test/controllers/global/update_controller_test.js +++ b/ambari-web/test/controllers/global/update_controller_test.js @@ -30,6 +30,8 @@ describe('App.UpdateController', function () { App.TestAliases.testAsComputedAlias(App.UpdateController.create(), 'clusterName', 'App.router.clusterController.clusterName', 'string'); + App.TestAliases.testAsComputedAnd(App.UpdateController.create(), 'updateAlertInstances', ['isWorking', '!App.router.mainAlertInstancesController.isUpdating']); + describe('#getUrl()', function () { it('testMode = true', function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/main/admin/kerberos_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/kerberos_test.js b/ambari-web/test/controllers/main/admin/kerberos_test.js index 8130941..4b58069 100644 --- a/ambari-web/test/controllers/main/admin/kerberos_test.js +++ b/ambari-web/test/controllers/main/admin/kerberos_test.js @@ -26,6 +26,8 @@ describe('App.MainAdminKerberosController', function() { App.TestAliases.testAsComputedSomeBy(controller, 'isPropertiesChanged', 'stepConfigs', 'isPropertiesChanged', true); + App.TestAliases.testAsComputedOr(controller, 'isSaveButtonDisabled', ['isSubmitDisabled', '!isPropertiesChanged']); + describe('#prepareConfigProperties', function() { beforeEach(function() { sinon.stub(App.Service, 'find').returns([ http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js b/ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js index ac06de7..097fc00 100644 --- a/ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js +++ b/ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js @@ -20,16 +20,22 @@ var App = require('app'); var controller; +function getController() { + return App.MainAlertDefinitionConfigsController.create({ + allServices: ['service1', 'service2', 'service3'], + allComponents: ['component1', 'component2', 'component3'], + aggregateAlertNames: ['alertDefinitionName', 'alertDefinitionName2', 'alertDefinitionName3'] + }); +} + describe('App.MainAlertDefinitionConfigsController', function () { beforeEach(function () { - controller = App.MainAlertDefinitionConfigsController.create({ - allServices: ['service1', 'service2', 'service3'], - allComponents: ['component1', 'component2', 'component3'], - aggregateAlertNames: ['alertDefinitionName', 'alertDefinitionName2', 'alertDefinitionName3'] - }); + controller = getController(); }); + App.TestAliases.testAsComputedOr(getController(), 'hasErrors', ['someConfigIsInvalid', 'hasThresholdsError']); + describe('#renderConfigs()', function () { beforeEach(function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js b/ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js index 7b56068..2eb91c8 100644 --- a/ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js +++ b/ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js @@ -36,6 +36,18 @@ describe('App.MainAlertDefinitionDetailsController', function () { App.TestAliases.testAsComputedMapBy(getController(), 'groupsList', 'content.groups', 'displayName'); + App.TestAliases.testAsComputedOr(getController(), 'isEditing', ['editing.label.isEditing', 'App.router.mainAlertDefinitionConfigsController.canEdit']); + + describe('#showSavePopup', function () { + var popup; + beforeEach(function () { + popup = getController().showSavePopup(); + }); + + App.TestAliases.testAsComputedOr(getController().showSavePopup(), 'disablePrimary', ['App.router.mainAlertDefinitionDetailsController.editing.label.isError', 'App.router.mainAlertDefinitionConfigsController.hasErrors']); + + }); + describe('#labelValidation()', function () { it('should set editing.label.isError to true', function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/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 6c48b64..25ed383 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 @@ -20,10 +20,16 @@ var App = require('app'); var controller; var helpers = require('test/helpers'); + +function getController() { + return App.ManageAlertNotificationsController.create({}); +} +var createEditPopupView = getController().showCreateEditPopup(); + describe('App.ManageAlertNotificationsController', function () { beforeEach(function () { - controller = App.ManageAlertNotificationsController.create({}); + controller = getController(); sinon.stub($, 'ajax', Em.K); }); @@ -503,13 +509,11 @@ describe('App.ManageAlertNotificationsController', function () { }); - describe('#bodyClass', function () { - - var view; - - beforeEach(function () { + App.TestAliases.testAsComputedOr(getController().showCreateEditPopup(), 'disablePrimary', ['isSaving', 'hasErrors']); - view = controller.showCreateEditPopup().get('bodyClass').create({ + describe('#bodyClass', function () { + function getBodyClass() { + return createEditPopupView.get('bodyClass').create({ controller: Em.Object.create({ inputFields: { name: {}, @@ -528,9 +532,16 @@ describe('App.ManageAlertNotificationsController', function () { hasErrors: false }) }); + } + + var view; + beforeEach(function () { + view = getBodyClass(); }); + App.TestAliases.testAsComputedOr(getBodyClass(), 'someErrorExists', ['nameError', 'emailToError', 'emailFromError', 'smtpPortError', 'hostError', 'portError', 'passwordError']); + describe('#selectAllGroups', function () { it('should check inputFields.allGroups.value', function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/main/service/info/summary_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service/info/summary_test.js b/ambari-web/test/controllers/main/service/info/summary_test.js index b42175b..bec3be1 100644 --- a/ambari-web/test/controllers/main/service/info/summary_test.js +++ b/ambari-web/test/controllers/main/service/info/summary_test.js @@ -19,6 +19,10 @@ var App = require('app'); require('controllers/main/service/info/summary'); +function getController() { + return App.MainServiceInfoSummaryController.create(); +} + describe('App.MainServiceInfoSummaryController', function () { var controller; @@ -27,6 +31,8 @@ describe('App.MainServiceInfoSummaryController', function () { controller = App.MainServiceInfoSummaryController.create(); }); +App.TestAliases.testAsComputedOr(getController(), 'showTimeRangeControl', ['!isServiceWithEnhancedWidgets', 'someWidgetGraphExists']); + describe('#setRangerPlugins', function () { var cases = [ http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/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 index b6f46f3..144918e 100644 --- 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 @@ -34,28 +34,7 @@ describe('App.WidgetWizardStep3Controller', function () { App.TestAliases.testAsComputedGte(controller, 'isDescriptionInvalid', 'widgetDescription.length', 2049); - 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; - }); - }); + App.TestAliases.testAsComputedOr(controller, 'isSubmitDisabled', ['widgetNameEmpty', 'isNameInvalid', 'isDescriptionInvalid']); describe("#initPreviewData()", function () { beforeEach(function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/wizard/step2_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/wizard/step2_test.js b/ambari-web/test/controllers/wizard/step2_test.js index 9afad41..41782bc 100644 --- a/ambari-web/test/controllers/wizard/step2_test.js +++ b/ambari-web/test/controllers/wizard/step2_test.js @@ -74,6 +74,8 @@ describe('App.WizardStep2Controller', function () { App.TestAliases.testAsComputedAlias(getController(), 'agentUser', 'content.installOptions.agentUser', 'string'); + App.TestAliases.testAsComputedOr(getController(), 'isSubmitDisabled', ['hostsError', 'sshKeyError', 'sshUserError', 'sshPortError', 'agentUserError']); + describe('#hostNames', function() { it('should be equal to content.installOptions.hostNames', function() { var controller = App.WizardStep2Controller.create({content: {installOptions: {hostNames: 'A,b,C'}}}); @@ -471,46 +473,6 @@ describe('App.WizardStep2Controller', function () { }); - describe('#isSubmitDisabled', function () { - - var controller = App.WizardStep2Controller.create({ - hostsError: '', - sshKeyError: '', - sshUserError: '', - sshPortError: '', - agentUserError: '' - }); - - it('should return value if hostsError is not empty', function () { - controller.set('hostsError', 'error'); - expect(controller.get('isSubmitDisabled')).to.be.true; - }); - - it('should return value if sshKeyError is not empty', function () { - controller.set('sshKeyError', 'error'); - controller.set('hostsError', ''); - expect(controller.get('isSubmitDisabled')).to.be.true; - }); - - it('should return value if sshUserError is not empty', function () { - controller.set('sshUserError', 'error'); - controller.set('sshKeyError', ''); - expect(controller.get('isSubmitDisabled')).to.be.true; - }); - - it('should return value if agentUserError is not empty', function () { - controller.set('agentUserError', 'error'); - controller.set('sshUserError', ''); - expect(controller.get('isSubmitDisabled')).to.be.true; - }); - - it('should return value if sshPortError is not empty', function () { - controller.set('sshPortError', 'error'); - controller.set('agentUserError', ''); - expect(controller.get('isSubmitDisabled')).to.be.true; - }); - }); - describe('#installedHostsPopup', function() { beforeEach(function() { sinon.spy(App.ModalPopup, 'show'); http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/wizard/step3_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/wizard/step3_test.js b/ambari-web/test/controllers/wizard/step3_test.js index a699dcc..dd1e918 100644 --- a/ambari-web/test/controllers/wizard/step3_test.js +++ b/ambari-web/test/controllers/wizard/step3_test.js @@ -57,6 +57,8 @@ describe('App.WizardStep3Controller', function () { App.TestAliases.testAsComputedIfThenElse(getController(), 'registrationTimeoutSecs', 'content.installOptions.manualInstall', 15, 120); + App.TestAliases.testAsComputedAnd(getController(), 'isWarningsLoaded', ['isJDKWarningsLoaded', 'isHostsWarningsLoaded']); + describe('#getAllRegisteredHostsCallback', function () { it('One host is already in the cluster, one host is registered', function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/wizard/step6_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/wizard/step6_test.js b/ambari-web/test/controllers/wizard/step6_test.js index 056c30a..fdeaf0d 100644 --- a/ambari-web/test/controllers/wizard/step6_test.js +++ b/ambari-web/test/controllers/wizard/step6_test.js @@ -208,27 +208,7 @@ describe('App.WizardStep6Controller', function () { }); }); - describe('#anyGeneralErrors', function () { - beforeEach(function () { - controller.set('errorMessage', undefined); - }); - it('should return errorMessage', function () { - controller.set('errorMessage', "error 404"); - expect(controller.get('anyGeneralErrors')).to.be.true - }); - it('true if generalErrorMessages is non empty array and errorMessage is undefined', function () { - controller.set('generalErrorMessages', ["error1", "error2"]); - expect(controller.get('anyGeneralErrors')).to.equal(true); - }); - it('false if generalErrorMessages is empty array and errorMessage is undefined', function () { - controller.set('generalErrorMessages', []); - expect(controller.get('anyGeneralErrors')).to.equal(false); - }); - it('undefined if generalErrorMessages is undefined and errorMessage is undefined', function () { - controller.set('generalErrorMessages', undefined); - expect(controller.get('anyGeneralErrors')).to.equal(false); - }); - }); + App.TestAliases.testAsComputedOr(getController(), 'anyGeneralErrors', ['errorMessage', 'generalErrorMessages.length']); describe('#render', function () { it('true if loaded', function () { @@ -309,31 +289,11 @@ describe('App.WizardStep6Controller', function () { }); }); - describe('#anyGeneralIssues', function () { - it('should return error message if errorMessage', function () { - controller.set('errorMessage', "error 404"); - expect(controller.get('anyGeneralIssues')).to.be.true; - }); - it('should return true if we have several errors', function () { - controller.set('generalErrorMessages', ["error 404", "error"]); - expect(controller.get('anyGeneralIssues')).to.be.true; - }); - it('should return true if we have several warnings', function () { - controller.set('generalWarningMessages', ["error 404", "error"]); - expect(controller.get('anyGeneralIssues')).to.be.true; - }); - }); + App.TestAliases.testAsComputedOr(getController(), 'anyGeneralIssues', ['anyGeneralErrors', 'anyGeneralWarnings']); - describe('#anyErrors', function () { - it('true if generalErrorMessages is non empty', function () { - controller.set('generalErrorMessages', ["error 404", "error"]); - expect(controller.get('anyErrors')).to.equal(true); - }); - it('false if generalErrorMessages is empty', function () { - controller.set('generalErrorMessages', []); - expect(controller.get('anyErrors')).to.equal(false); - }); - }); + App.TestAliases.testAsComputedOr(getController(), 'anyErrors', ['anyGeneralErrors', 'anyHostErrors']); + + App.TestAliases.testAsComputedOr(getController(), 'anyWarnings', ['anyGeneralWarnings', 'anyHostWarnings']); describe('#anyWarnings', function () { it('true if generalWarningMessages is non empty', function () { @@ -986,7 +946,7 @@ describe('App.WizardStep6Controller', function () { }); }); -describe('#getCurrentBlueprint', function () { + describe('#getCurrentBlueprint', function () { var tests = Em.A([ { clientComponents: Em.A([{component_name: "name1"}]), http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/controllers/wizard/step7_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/wizard/step7_test.js b/ambari-web/test/controllers/wizard/step7_test.js index 4d43a09..334563d 100644 --- a/ambari-web/test/controllers/wizard/step7_test.js +++ b/ambari-web/test/controllers/wizard/step7_test.js @@ -121,6 +121,8 @@ describe('App.InstallerStep7Controller', function () { App.TestAliases.testAsComputedAlias(getController(), 'slaveComponentHosts', 'content.slaveGroupProperties', 'array'); + App.TestAliases.testAsComputedAnd(getController(), 'isConfigsLoaded', ['wizardController.stackConfigsLoaded', 'isAppliedConfigLoaded']); + describe('#installedServiceNames', function () { var tests = Em.A([ http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/init_computed_aliases.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/init_computed_aliases.js b/ambari-web/test/init_computed_aliases.js index 030480d..62d0842 100644 --- a/ambari-web/test/init_computed_aliases.js +++ b/ambari-web/test/init_computed_aliases.js @@ -49,7 +49,6 @@ App.TestAliases = { return this._stubOneKey.apply(this, args); } return this._stubManyKeys.apply(this, args) - }, /** @@ -136,6 +135,32 @@ App.TestAliases = { return Em.get(self, k); }); return this; + }, + + /** + * Generates array of all possible boolean combinations + * Example: + * <code> + * var keys = ['a', 'b']; + * var result = getBinaryCombos(keys); + * console.log(result); // [{a: true, b: true}, {a: true, b: false}, {a: false, b: true}, {a: false, b: false}] + * </code> + * + * @param {string[]} dependentKeys + * @returns {Array} + */ + getBinaryCombos: function (dependentKeys) { + var n = dependentKeys.length; + var result = []; + var allCombos = Math.pow(2, n); + for (var y = 0; y < allCombos; y++) { + var combo = {}; + for (var x = 0; x < n; x++) { + combo[dependentKeys[x]] = !!((y >> x) & 1); + } + result.push(combo); + } + return result; } } @@ -166,4 +191,6 @@ require('test/aliases/computed/everyBy'); require('test/aliases/computed/mapBy'); require('test/aliases/computed/filterBy'); require('test/aliases/computed/findBy'); -require('test/aliases/computed/sumBy'); \ No newline at end of file +require('test/aliases/computed/sumBy'); +require('test/aliases/computed/and'); +require('test/aliases/computed/or'); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/models/alerts/alert_definition_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/alerts/alert_definition_test.js b/ambari-web/test/models/alerts/alert_definition_test.js index c32dde4..d151faf 100644 --- a/ambari-web/test/models/alerts/alert_definition_test.js +++ b/ambari-web/test/models/alerts/alert_definition_test.js @@ -22,14 +22,18 @@ require('models/alerts/alert_definition'); var model; +function getModel() { + return App.AlertDefinition.createRecord(); +} + describe('App.AlertDefinition', function () { beforeEach(function () { - - model = App.AlertDefinition.createRecord(); - + model = getModel(); }); + App.TestAliases.testAsComputedAnd(getModel(), 'isHostAlertDefinition', ['isAmbariService', 'isAmbariAgentComponent']); + describe('#status', function () { Em.A([ http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/models/configs/objects/service_config_property_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/configs/objects/service_config_property_test.js b/ambari-web/test/models/configs/objects/service_config_property_test.js index 11ea4ab..e292109 100644 --- a/ambari-web/test/models/configs/objects/service_config_property_test.js +++ b/ambari-web/test/models/configs/objects/service_config_property_test.js @@ -333,6 +333,8 @@ describe('App.ServiceConfigProperty', function () { App.TestAliases.testAsComputedFirstNotBlank(getProperty(), 'placeholder', ['placeholderText', 'savedValue']); + App.TestAliases.testAsComputedAnd(getProperty(), 'hideFinalIcon', ['!isFinal', 'isNotEditable']); + describe('#overrideErrorTrigger', function () { it('should be an increment', function () { serviceConfigProperty.set('overrides', configsData[0].overrides); http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/models/configs/service_config_version_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/configs/service_config_version_test.js b/ambari-web/test/models/configs/service_config_version_test.js index e721890..b5b730c 100644 --- a/ambari-web/test/models/configs/service_config_version_test.js +++ b/ambari-web/test/models/configs/service_config_version_test.js @@ -21,10 +21,14 @@ require('models/configs/service_config_version'); var model; +function getModel() { + return App.ServiceConfigVersion.createRecord({}); +} + describe('App.ServiceConfigVersion', function () { beforeEach(function () { - model = App.ServiceConfigVersion.createRecord({}); + model = getModel(); }); describe('#authorFormatted', function () { @@ -51,39 +55,6 @@ describe('App.ServiceConfigVersion', function () { }); - describe('#canBeMadeCurrent', function () { - - var cases = [ - { - isCompatible: true, - isCurrent: true, - canBeMadeCurrent: false, - title: 'current version' - }, - { - isCompatible: true, - isCurrent: false, - canBeMadeCurrent: true, - title: 'compatible version' - }, - { - isCompatible: false, - isCurrent: false, - canBeMadeCurrent: false, - title: 'not compatible version' - } - ]; - - cases.forEach(function (item) { - it(item.title, function () { - model.setProperties({ - isCompatible: item.isCompatible, - isCurrent: item.isCurrent - }); - expect(model.get('canBeMadeCurrent')).to.equal(item.canBeMadeCurrent); - }); - }); - - }); + App.TestAliases.testAsComputedAnd(getModel(), 'canBeMadeCurrent', ['isCompatible', '!isCurrent']); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/models/configs/sub_section_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/configs/sub_section_test.js b/ambari-web/test/models/configs/sub_section_test.js index 1e1e356..afc37b2 100644 --- a/ambari-web/test/models/configs/sub_section_test.js +++ b/ambari-web/test/models/configs/sub_section_test.js @@ -19,12 +19,24 @@ var App = require('app'); var model; +function getModel() { + return App.SubSection.createRecord(); +} + describe('App.SubSection', function () { beforeEach(function () { - model = App.SubSection.createRecord(); + model = getModel(); }); + App.TestAliases.testAsComputedAnd(getModel(), 'showTabs', ['hasTabs', 'someSubSectionTabIsVisible']); + + App.TestAliases.testAsComputedAnd(getModel(), 'addLeftVerticalSplitter', ['!isFirstColumn', 'leftVerticalSplitter']); + + App.TestAliases.testAsComputedAnd(getModel(), 'showTopSplitter', ['!isFirstRow', '!border']); + + App.TestAliases.testAsComputedAnd(getModel(), 'isSectionVisible', ['!isHiddenByFilter', '!isHiddenByConfig', 'someConfigIsVisible']); + describe('#errorsCount', function () { beforeEach(function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/models/stack_service_component_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/stack_service_component_test.js b/ambari-web/test/models/stack_service_component_test.js index cc58fcb..7e971ce 100644 --- a/ambari-web/test/models/stack_service_component_test.js +++ b/ambari-web/test/models/stack_service_component_test.js @@ -302,6 +302,8 @@ describe('App.StackServiceComponent', function() { modelSetup.setupStackServiceComponent(); }); + App.TestAliases.testAsComputedAnd(App.StackServiceComponent.createRecord(), 'isMasterAddableInstallerWizard', ['isMaster', 'isMultipleAllowed', '!isMasterAddableOnlyOnHA', '!isNotAddableOnlyInInstall']); + describe('component properties validation', function() { componentPropertiesValidationTests.forEach(function(test) { describe('properties validation for ' + test.componentName + ' component', function() { http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/views/common/configs/widgets/config_widget_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/common/configs/widgets/config_widget_view_test.js b/ambari-web/test/views/common/configs/widgets/config_widget_view_test.js index d2523ac..e7f979b 100644 --- a/ambari-web/test/views/common/configs/widgets/config_widget_view_test.js +++ b/ambari-web/test/views/common/configs/widgets/config_widget_view_test.js @@ -19,20 +19,29 @@ var App = require('app'); var view; + +function getView() { + return App.ConfigWidgetView.create({ + initPopover: Em.K, + config: Em.Object.create({ + isOriginalSCP: false, + isPropertyOverridable: false, + cantBeUndone: false, + isNotDefaultValue: false + }) + }); +} + describe('App.ConfigWidgetView', function () { beforeEach(function () { - view = App.ConfigWidgetView.create({ - initPopover: Em.K, - config: Em.Object.create({ - isOriginalSCP: false, - isPropertyOverridable: false, - cantBeUndone: false, - isNotDefaultValue: false - }) - }); + view = getView(); }); + App.TestAliases.testAsComputedAnd(getView(), 'showPencil', ['supportSwitchToTextBox', '!disabled']); + + App.TestAliases.testAsComputedOr(getView(), 'doNotShowWidget', ['isPropertyUndefined', 'config.showAsTextBox']); + describe('#undoAllowed', function () { Em.A([ http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/views/common/form/spinner_input_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/common/form/spinner_input_view_test.js b/ambari-web/test/views/common/form/spinner_input_view_test.js index 075ca88..8e668a0 100644 --- a/ambari-web/test/views/common/form/spinner_input_view_test.js +++ b/ambari-web/test/views/common/form/spinner_input_view_test.js @@ -20,10 +20,15 @@ var App = require('app'); var view; var e; + +function getView() { + return App.SpinnerInputView.create({}); +} + describe('App.SpinnerInputView', function () { beforeEach(function () { - view = App.SpinnerInputView.create({}); + view = getView(); e = { preventDefault: Em.K }; @@ -34,6 +39,8 @@ describe('App.SpinnerInputView', function () { e.preventDefault.restore(); }); + App.TestAliases.testAsComputedOr(getView(), 'computedDisabled', ['!content.enabled', 'disabled']); + describe('#keyDown', function () { Em.A([ http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_task_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_task_view_test.js b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_task_view_test.js index de578a1..66e6d41 100644 --- a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_task_view_test.js +++ b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_task_view_test.js @@ -28,6 +28,8 @@ describe('App.upgradeTaskView', function () { view.removeObserver('content.isExpanded', view, 'doPolling'); view.removeObserver('outsideView', view, 'doPolling'); + App.TestAliases.testAsComputedOr(view, 'showContent', ['outsideView', 'content.isExpanded']); + describe("#logTabId", function() { it("", function() { view.reopen({ @@ -158,31 +160,4 @@ describe('App.upgradeTaskView', function () { }); }); - describe("#showContent", function() { - it("outsideView = false, content.isExpanded = false", function() { - view.set('outsideView', false); - view.set('content.isExpanded', false); - view.propertyDidChange('showContent'); - expect(view.get('showContent')).to.be.false; - }); - it("outsideView = true, content.isExpanded = false", function() { - view.set('outsideView', true); - view.set('content.isExpanded', false); - view.propertyDidChange('showContent'); - expect(view.get('showContent')).to.be.true; - }); - it("outsideView = false, content.isExpanded = true", function() { - view.set('outsideView', false); - view.set('content.isExpanded', true); - view.propertyDidChange('showContent'); - expect(view.get('showContent')).to.be.true; - }); - it("outsideView = true, content.isExpanded = true", function() { - view.set('outsideView', true); - view.set('content.isExpanded', true); - view.propertyDidChange('showContent'); - expect(view.get('showContent')).to.be.true; - }); - }); - }); http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_wizard_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_wizard_view_test.js b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_wizard_view_test.js index a9fdfed..9507e08 100644 --- a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_wizard_view_test.js +++ b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_wizard_view_test.js @@ -37,6 +37,8 @@ describe('App.upgradeWizardView', function () { }); view.removeObserver('App.clusterName', view, 'startPolling'); + App.TestAliases.testAsComputedOr(view, 'isManualProceedDisabled', ['!isManualDone', 'controller.requestInProgress']); + App.TestAliases.testAsComputedEqualProperties(view, 'isFinalizeItem', 'manualItem.context', 'controller.finalizeContext'); describe("#upgradeGroups", function () { @@ -231,21 +233,6 @@ describe('App.upgradeWizardView', function () { }); }); - describe("#isManualProceedDisabled", function () { - it("requestInProgress is false", function () { - view.set('isManualDone', true); - view.set('controller.requestInProgress', false); - view.propertyDidChange('isManualProceedDisabled'); - expect(view.get('isManualProceedDisabled')).to.be.false; - }); - it("requestInProgress is true", function () { - view.set('controller.requestInProgress', true); - view.propertyDidChange('isManualProceedDisabled'); - expect(view.get('isManualProceedDisabled')).to.be.true; - }); - - }); - describe("#failedItem", function () { it("no running item", function () { view.set('activeGroup.upgradeItems', []); @@ -390,20 +377,7 @@ describe('App.upgradeWizardView', function () { }); }); - describe("#isDowngradeAvailable", function () { - it("downgrade available", function () { - view.set('controller.isDowngrade', false); - view.set('controller.downgradeAllowed', true); - view.propertyDidChange('isDowngradeAvailable'); - expect(view.get('isDowngradeAvailable')).to.be.true; - }); - it("downgrade unavailable", function () { - view.set('controller.isDowngrade', true); - view.set('controller.downgradeAllowed', true); - view.propertyDidChange('isDowngradeAvailable'); - expect(view.get('isDowngradeAvailable')).to.be.false; - }); - }); + App.TestAliases.testAsComputedAnd(view, 'isDowngradeAvailable', ['!controller.isDowngrade', 'controller.downgradeAllowed']); describe("#taskDetails", function () { it("runningItem present", function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/views/main/alerts/definition_details_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/alerts/definition_details_view_test.js b/ambari-web/test/views/main/alerts/definition_details_view_test.js index ae4ac99..f988ceb 100644 --- a/ambari-web/test/views/main/alerts/definition_details_view_test.js +++ b/ambari-web/test/views/main/alerts/definition_details_view_test.js @@ -20,16 +20,17 @@ var App = require('app'); var view, instanceTableRow; +function getView() { + return App.MainAlertDefinitionDetailsView.create({ + initFilters: Em.K + }); +} + describe('App.MainAlertDefinitionDetailsView', function () { beforeEach(function () { - - view = App.MainAlertDefinitionDetailsView.create({ - initFilters: Em.K - }); - + view = getView(); instanceTableRow = view.get('instanceTableRow').create(); - }); describe("#goToHostAlerts()", function () { @@ -54,3 +55,13 @@ describe('App.MainAlertDefinitionDetailsView', function () { }); }); + +function getInstanceView() { + return App.AlertInstanceServiceHostView.create(); +} + +describe('App.AlertInstanceServiceHostView', function () { + + App.TestAliases.testAsComputedAnd(getInstanceView(), 'showSeparator', ['instance.serviceDisplayName', 'instance.hostName']); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/views/main/dashboard/widgets/hbase_regions_in_transition_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widgets/hbase_regions_in_transition_test.js b/ambari-web/test/views/main/dashboard/widgets/hbase_regions_in_transition_test.js index 3615ccc..ce39742 100644 --- a/ambari-web/test/views/main/dashboard/widgets/hbase_regions_in_transition_test.js +++ b/ambari-web/test/views/main/dashboard/widgets/hbase_regions_in_transition_test.js @@ -109,4 +109,6 @@ describe('App.HBaseRegionsInTransitionView', function() { App.TestAliases.testAsComputedLteProperties(getView(), 'isGreen', 'data', 'thresh1'); + App.TestAliases.testAsComputedAnd(getView(), 'isOrange', ['!isGreen', '!isRed']); + }); http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/views/main/dashboard/widgets/node_managers_live_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widgets/node_managers_live_test.js b/ambari-web/test/views/main/dashboard/widgets/node_managers_live_test.js index cd1c150..3e5fce0 100644 --- a/ambari-web/test/views/main/dashboard/widgets/node_managers_live_test.js +++ b/ambari-web/test/views/main/dashboard/widgets/node_managers_live_test.js @@ -23,84 +23,16 @@ require('views/main/dashboard/widget'); require('views/main/dashboard/widgets/text_widget'); require('views/main/dashboard/widgets/node_managers_live'); -describe('App.NodeManagersLiveView', function() { - - beforeEach(function () { - sinon.stub(App, 'get').withArgs('router.clusterController.isComponentsStateLoaded').returns(true); +function getView() { + return App.NodeManagersLiveView.create({ + parentView: Em.Object.create() }); +} - afterEach(function () { - App.get.restore(); - }); +describe('App.NodeManagersLiveView', function() { - var tests = [ - { - model: { - nodeManagersTotal: 3, - nodeManagerLiveNodes: 2 - }, - e: { - isRed: false, - isOrange: true, - isGreen: false, - isNA: false, - content: '2/3', - data: 67 - } - }, - { - model: { - nodeManagersTotal: 2, - nodeManagerLiveNodes: 2 - }, - e: { - isRed: false, - isOrange: false, - isGreen: true, - isNA: false, - content: '2/2', - data: 100 - } - }, - { - model: { - nodeManagersTotal: 2, - nodeManagerLiveNodes: 0 - }, - e: { - isRed: true, - isOrange: false, - isGreen: false, - isNA: false, - content: '0/2', - data: 0.00 - } - } - ]; + App.TestAliases.testAsComputedAnd(getView(), 'isDataAvailable', ['!model.metricsNotAvailable', 'App.router.clusterController.isComponentsStateLoaded']); - tests.forEach(function(test) { - describe('nodeManagersTotal length - ' + test.model.nodeManagersTotal + ' | nodeManagerLiveNodes length - ' + test.model.nodeManagerLiveNodes, function() { - var AppNodeManagersLiveView = App.NodeManagersLiveView.extend({nodeManagersLive: test.model.nodeManagerLiveNodes}); - var nodeManagersLiveView = AppNodeManagersLiveView.create({model_type:null, model: test.model}); - it('content', function() { - expect(nodeManagersLiveView.get('content')).to.equal(test.e.content); - }); - it('data', function() { - expect(nodeManagersLiveView.get('data')).to.equal(test.e.data); - }); - it('isRed', function() { - expect(nodeManagersLiveView.get('isRed')).to.equal(test.e.isRed); - }); - it('isOrange', function() { - expect(nodeManagersLiveView.get('isOrange')).to.equal(test.e.isOrange); - }); - it('isGreen', function() { - expect(nodeManagersLiveView.get('isGreen')).to.equal(test.e.isGreen); - }); - it('isNA', function() { - expect(nodeManagersLiveView.get('isNA')).to.equal(test.e.isNA); - }); - }); - }); + App.TestAliases.testAsComputedAlias(getView(), 'nodeManagersLive', 'model.nodeManagersCountActive'); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js b/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js index 1f95076..5dbb599 100644 --- a/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js +++ b/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js @@ -89,4 +89,6 @@ describe('App.TextDashboardWidgetView', function() { App.TestAliases.testAsComputedLteProperties(getView(), 'isRed', 'data', 'thresh1'); + App.TestAliases.testAsComputedAnd(getView(), 'isOrange', ['!isGreen', '!isRed']); + }); http://git-wip-us.apache.org/repos/asf/ambari/blob/8750537a/ambari-web/test/views/wizard/step1_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/wizard/step1_view_test.js b/ambari-web/test/views/wizard/step1_view_test.js index a470495..497da5e 100644 --- a/ambari-web/test/views/wizard/step1_view_test.js +++ b/ambari-web/test/views/wizard/step1_view_test.js @@ -28,6 +28,8 @@ function getView() { describe('App.WizardStep1View', function () { + App.TestAliases.testAsComputedAnd(getView(), 'showErrorsWarningCount', ['isSubmitDisabled', 'totalErrorCnt']); + describe('#operatingSystems', function () { beforeEach(function () { sinon.stub(App.Stack, 'find', function () { @@ -210,6 +212,8 @@ describe('App.WizardStep1View', function () { App.TestAliases.testAsComputedEveryBy(getView(), 'isNoOsChecked', 'operatingSystems', 'isSelected', false); + App.TestAliases.testAsComputedOr(getView(), 'isSubmitDisabled', ['invalidFormatUrlExist', 'isNoOsChecked', 'invalidUrlExist', 'controller.content.isCheckInProgress']); + describe('#stacks', function () { var tests = Em.A([ @@ -245,148 +249,9 @@ describe('App.WizardStep1View', function () { }); - describe('#isSubmitDisabled', function () { - - var tests = Em.A([ - { - invalidFormatUrlExist: false, - isNoOsChecked: false, - invalidUrlExist: false, - checkInProgress: false, - e: false - }, - { - invalidFormatUrlExist: true, - isNoOsChecked: false, - invalidUrlExist: false, - checkInProgress: false, - e: true - }, - { - invalidFormatUrlExist: false, - isNoOsChecked: true, - invalidUrlExist: false, - checkInProgress: false, - e: true - }, - { - invalidFormatUrlExist: false, - isNoOsChecked: false, - invalidUrlExist: true, - checkInProgress: false, - e: true - }, - { - invalidFormatUrlExist: true, - isNoOsChecked: false, - invalidUrlExist: true, - checkInProgress: false, - e: true - }, - { - invalidFormatUrlExist: true, - isNoOsChecked: true, - invalidUrlExist: false, - checkInProgress: false, - e: true - }, - { - invalidFormatUrlExist: false, - isNoOsChecked: true, - invalidUrlExist: true, - checkInProgress: false, - e: true - }, - { - invalidFormatUrlExist: true, - isNoOsChecked: true, - invalidUrlExist: true, - checkInProgress: false, - e: true - }, - { - invalidFormatUrlExist: true, - isNoOsChecked: false, - invalidUrlExist: false, - checkInProgress: true, - e: true - } - ]); + App.TestAliases.testAsComputedSomeBy(getView(), 'invalidUrlExist', 'allRepositories', 'validation', App.Repository.validation['INVALID']); - tests.forEach(function (test) { - it(test.invalidFormatUrlExist.toString() + ' ' + test.isNoOsChecked.toString() + ' ' + test.invalidUrlExist.toString()+ ' ' + test.checkInProgress.toString(), function () { - view = App.WizardStep1View.create(); - view.reopen({ - invalidFormatUrlExist: test.invalidFormatUrlExist, - isNoOsChecked: test.isNoOsChecked, - invalidUrlExist: test.invalidUrlExist - }); - view.set('controller', {}); - view.set('controller.content', {}); - view.set('controller.content.isCheckInProgress', test.checkInProgress); - expect(view.get('isSubmitDisabled')).to.equal(test.e); - }); - }); - }); - - describe('#showErrorsWarningCount', function() { - var tests = [ - { - isSubmitDisabled: true, - totalErrorCnt: 0, - e: false - }, - { - isSubmitDisabled: true, - totalErrorCnt: 1, - e: true - }, - { - isSubmitDisabled: false, - totalErrorCnt: 0, - e: false - } - ]; - tests.forEach(function(test) { - it(test.isSubmitDisabled.toString() + ' ' + test.totalErrorCnt.toString(), function () { - var view = App.WizardStep1View.create(); - view.reopen({ - isSubmitDisabled: test.isSubmitDisabled, - totalErrorCnt: test.totalErrorCnt - }); - expect(view.get('showErrorsWarningCount')).to.equal(test.e); - }) - }); - }); - - describe('#invalidUrlExist', function () { - var tests = Em.A([ - { - allRepositories: [Em.Object.create({validation: 'icon-exclamation-sign'})], - m: 'invalidCnt: 1, validation: icon-exclamation-sign', - e: true - }, - { - allRepositories: [Em.Object.create({validation: ''})], - m: 'invalidCnt: 1, validation: ""', - e: false - }, - { - allRepositories: [Em.Object.create({validation: ''})], - m: 'invalidCnt: 0, validation: ""', - e: false - } - ]); - tests.forEach(function (test) { - it(test.m, function () { - view = App.WizardStep1View.create(); - view.reopen({ - allRepositories: test.allRepositories - }); - expect(view.get('invalidUrlExist')).to.equal(test.e); - }); - }); - }); + App.TestAliases.testAsComputedSomeBy(getView(), 'invalidFormatUrlExist', 'allRepositories', 'invalidFormatError', true); describe('#totalErrorCnt', function () { var tests = Em.A([