AMBARI-15511. Refactor alerts models (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2925a6aa Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2925a6aa Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2925a6aa Branch: refs/heads/trunk Commit: 2925a6aa5adbdcad2a7311207f754dd79cd6b5fb Parents: 7f5e903 Author: Oleg Nechiporenko <onechipore...@apache.org> Authored: Tue Mar 22 12:09:57 2016 +0200 Committer: Oleg Nechiporenko <onechipore...@apache.org> Committed: Tue Mar 22 12:09:57 2016 +0200 ---------------------------------------------------------------------- .../app/models/alerts/alert_definition.js | 56 ++------------- ambari-web/app/models/alerts/alert_instance.js | 24 ++++--- ambari-web/app/templates.js | 1 + .../common/modal_popups/alerts_popup.hbs | 14 ++-- .../alert_definition_summary.hbs | 17 +++-- .../main/alerts/alert_instance/status.hbs | 26 +++++++ .../main/alerts/definition_details.hbs | 5 +- .../app/templates/main/host/host_alerts.hbs | 18 ++--- .../main/service/info/service_alert_popup.hbs | 1 + ambari-web/app/utils/ember_computed.js | 32 ++++++++- .../alert_definition_summary.js | 76 ++++++++++---------- ambari-web/test/aliases/computed/getByKey.js | 55 ++++++++++++++ ...anage_alert_notifications_controller_test.js | 1 + ambari-web/test/init_computed_aliases.js | 3 +- .../test/models/alerts/alert_definition_test.js | 44 +----------- .../test/models/alerts/alert_instance_test.js | 34 ++------- ambari-web/test/utils/ember_computed_test.js | 56 +++++++++++++++ 17 files changed, 271 insertions(+), 192 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/models/alerts/alert_definition.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/alerts/alert_definition.js b/ambari-web/app/models/alerts/alert_definition.js index 84d876d..0acfc33 100644 --- a/ambari-web/app/models/alerts/alert_definition.js +++ b/ambari-web/app/models/alerts/alert_definition.js @@ -135,51 +135,15 @@ App.AlertDefinition = DS.Model.extend({ */ componentNameFormatted: Em.computed.formatRole('componentName', false), - /** - * Status generates from child-alerts - * Format: OK(1) WARN(2) CRIT(1) UNKN(1) - * If single host: show: OK/WARNING/CRITICAL/UNKNOWN - * If some there are no alerts with some state, this state isn't shown - * If no OK/WARN/CRIT/UNKN state, then show PENDING - * Order is equal to example - * @type {string} - */ - status: function () { + hostCnt: function () { var order = this.get('order'), - summary = this.get('summary'), - hostCnt = 0, - self = this; + summary = this.get('summary'), + hostCnt = 0; order.forEach(function (state) { hostCnt += summary[state] ? summary[state].count + summary[state].maintenanceCount : 0; }); - if (hostCnt > 1) { - // multiple hosts - return order.map(function (state) { - var shortState = self.get('shortState')[state]; - var result = ''; - result += summary[state].count ? '<span class="alert-state-single-host label alert-state-' + state + '">' + shortState + ' (' + summary[state].count + ')</span>' : ''; - // add status with maintenance mode icon - result += summary[state].maintenanceCount ? - '<span class="alert-state-single-host label alert-state-PENDING"><span class="icon-medkit"></span> ' + shortState + ' (' + summary[state].maintenanceCount + ')</span>' : ''; - return result; - }).without('').join(' '); - } else if (hostCnt === 1) { - // single host, single status - return order.map(function (state) { - var shortState = self.get('shortState')[state]; - var result = ''; - result += summary[state].count ? '<span class="alert-state-single-host label alert-state-' + state + '">' + shortState + '</span>' : ''; - // add status with maintenance mode icon - result += summary[state].maintenanceCount ? - '<span class="alert-state-single-host label alert-state-PENDING"><span class="icon-medkit"></span> ' + shortState + '</span>' : ''; - return result; - }).without('').join(' '); - } else if (!hostCnt) { - // none - return '<span class="alert-state-single-host label alert-state-PENDING">NONE</span>'; - } - return ''; - }.property('summary'), + return hostCnt; + }.property('order', 'summary'), latestText: function () { var order = this.get('order'), summary = this.get('summary'), text = ''; @@ -198,20 +162,14 @@ App.AlertDefinition = DS.Model.extend({ isHostAlertDefinition: Em.computed.and('isAmbariService', 'isAmbariAgentComponent'), - typeIconClass: function () { - var typeIcons = this.get('typeIcons'), - type = this.get('type'); - return typeIcons[type]; - }.property('type'), + typeIconClass: Em.computed.getByKey('typeIcons', 'type'), /** * if this definition is in state: CRITICAL / WARNING, if true, will show up in alerts fast access popup * instances with maintenance mode ON are ignored * @type {boolean} */ - isCriticalOrWarning: function () { - return !!(this.get('summary.CRITICAL.count') || this.get('summary.WARNING.count')); - }.property('summary'), + isCriticalOrWarning: Em.computed.or('summary.CRITICAL.count', 'summary.WARNING.count'), /** * if this definition is in state: CRITICAL http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/models/alerts/alert_instance.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/alerts/alert_instance.js b/ambari-web/app/models/alerts/alert_instance.js index 20f4560..d8710a0 100644 --- a/ambari-web/app/models/alerts/alert_instance.js +++ b/ambari-web/app/models/alerts/alert_instance.js @@ -40,17 +40,21 @@ App.AlertInstance = DS.Model.extend({ notification: DS.hasMany('App.AlertNotification'), /** - * Status icon markup + * @type {boolean} + */ + isMaintenanceStateOn: Em.computed.equal('maintenanceState', 'ON'), + + /** + * @type {string} + */ + shortStateMsg: Em.computed.getByKey('shortState', 'state'), + + /** * @type {string} */ - status: function () { - var isMaintenanceStateOn = this.get('maintenanceState') === 'ON'; - var state = this.get('state'); - var stateClass = isMaintenanceStateOn ? 'PENDING' : state; - var shortState = this.get('shortState')[state]; - var maintenanceIcon = isMaintenanceStateOn ? '<span class="icon-medkit"></span> ' : ''; - return '<div class="label alert-state-single-host alert-state-' + stateClass + '">' + maintenanceIcon + shortState + '</div>'; - }.property('state'), + stateClass: function () { + return 'alert-state-' + (this.get('isMaintenanceStateOn') ? 'PENDING' : this.get('state')); + }.property('isMaintenanceStateOn'), /** * For alerts we will have processes which are not typical @@ -124,7 +128,7 @@ App.AlertInstance = DS.Model.extend({ */ escapeSpecialCharactersFromTooltip: function () { var displayedText = this.get('text'); - return displayedText.replace(/[<>]/g, ''); + return displayedText.replace(/[<>]/g, ''); }.property('text'), /** http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/templates.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates.js b/ambari-web/app/templates.js index b181cc2..80a3176 100644 --- a/ambari-web/app/templates.js +++ b/ambari-web/app/templates.js @@ -22,6 +22,7 @@ require('templates/main/service/info/summary/base'); require('templates/common/progress'); +require('templates/main/alerts/alert_instance/status'); require("templates/main/service/widgets/create/step2_number"); require("templates/main/service/widgets/create/step2_template"); require("templates/main/service/widgets/create/step2_graph"); http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/templates/common/modal_popups/alerts_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/common/modal_popups/alerts_popup.hbs b/ambari-web/app/templates/common/modal_popups/alerts_popup.hbs index 06a1b94..4debe10 100644 --- a/ambari-web/app/templates/common/modal_popups/alerts_popup.hbs +++ b/ambari-web/app/templates/common/modal_popups/alerts_popup.hbs @@ -28,24 +28,24 @@ {{#if view.isAlertEmptyList}} <div class="alert-list-wrap">{{t alerts.fastAccess.popup.body.noalerts}}</div> {{else}} - {{#each alertInstance in view.pageContent}} + {{#each instance in view.pageContent}} <div class="alert-list-wrap"> <div class="alert-list-line-cursor"> <div class="service-text"> - {{view App.AlertInstanceServiceHostView instanceBinding="alertInstance"}} + {{view App.AlertInstanceServiceHostView instanceBinding="instance"}} </div> <div class="name-text"> <div> - <a href="#" {{action "gotoAlertDetails" alertInstance target="view"}}>{{alertInstance.label}}</a> + <a href="#" {{action "gotoAlertDetails" instance target="view"}}>{{instance.label}}</a> </div> <div class="instance-text"> - {{alertInstance.text}} + {{instance.text}} </div> </div> - <div class="status-col" {{bindAttr title="alertInstance.lastTriggered"}}> + <div class="status-col" {{bindAttr title="instance.lastTriggered"}}> + {{template "templates/main/alerts/alert_instance/status"}} <span> - <span class="status-icon">{{{alertInstance.status}}}</span> - <time>{{alertInstance.lastTriggeredForFormatted}}</time> + <time>{{instance.lastTriggeredForFormatted}}</time> </span> </div> </div> http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/templates/main/alerts/alert_definition/alert_definition_summary.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/alerts/alert_definition/alert_definition_summary.hbs b/ambari-web/app/templates/main/alerts/alert_definition/alert_definition_summary.hbs index 930d440..411c8be 100644 --- a/ambari-web/app/templates/main/alerts/alert_definition/alert_definition_summary.hbs +++ b/ambari-web/app/templates/main/alerts/alert_definition/alert_definition_summary.hbs @@ -16,13 +16,16 @@ * limitations under the License. }} -{{#if view.hostCount}} - {{#each state in view.states}} - <span {{bindAttr class=":alert-state-single-host :label state.stateClass"}}> - {{#if state.isMaintenance}}<span class="icon-medkit"></span>{{/if}} - {{state.shortStateWithCounter}} - </span> +{{#if view.hasMultipleCount}} + {{#each st in view.definitionState}} + {{#if st.count}} + <span {{bindAttr class=":alert-state-single-host :label st.state"}}>{{st.count}}</span> + {{/if}} + {{#if st.maintenanceCount}} + <span class="alert-state-single-host label alert-state-PENDING"><span + class="icon-medkit"></span> {{st.maintenanceCount}}</span> + {{/if}} {{/each}} {{else}} - <span class="alert-state-single-host label alert-state-PENDING">NONE</span> + <span class="alert-state-single-host label alert-state-PENDING">{{view.content.shortState.PENDING}}</span> {{/if}} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/templates/main/alerts/alert_instance/status.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/alerts/alert_instance/status.hbs b/ambari-web/app/templates/main/alerts/alert_instance/status.hbs new file mode 100644 index 0000000..d82bc7b --- /dev/null +++ b/ambari-web/app/templates/main/alerts/alert_instance/status.hbs @@ -0,0 +1,26 @@ +{{! +* 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. +}} + +{{! instance - App.AlertInstance }} + +<div {{bindAttr class=":label :alert-state-single-host instance.stateClass"}}> + {{#if instance.isMaintenanceStateOn}} + <span class="icon-medkit"></span> + {{/if}} + {{instance.shortStateMsg}} +</div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/templates/main/alerts/definition_details.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/alerts/definition_details.hbs b/ambari-web/app/templates/main/alerts/definition_details.hbs index 883cae3..d831141 100644 --- a/ambari-web/app/templates/main/alerts/definition_details.hbs +++ b/ambari-web/app/templates/main/alerts/definition_details.hbs @@ -55,7 +55,7 @@ </div> <div class="status span4"> - {{{controller.content.status}}} + {{view App.AlertDefinitionSummary contentBinding="view.controller.content"}} </div> </div> @@ -211,7 +211,8 @@ </a> {{/if}} </td> - <td>{{{instance.status}}} + <td> + {{template "templates/main/alerts/alert_instance/status"}} <time class="timeago" rel="tooltip" {{bindAttr data-original-title="instance.statusChangedAndLastCheckedFormatted"}}> {{instance.lastTriggeredForFormatted}} http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/templates/main/host/host_alerts.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/host/host_alerts.hbs b/ambari-web/app/templates/main/host/host_alerts.hbs index e15b395..42029e4 100644 --- a/ambari-web/app/templates/main/host/host_alerts.hbs +++ b/ambari-web/app/templates/main/host/host_alerts.hbs @@ -39,24 +39,24 @@ </thead> <tbody> {{#if view.pageContent}} - {{#each alertInstance in view.pageContent}} + {{#each instance in view.pageContent}} <tr> <td class="first"> - {{#if alertInstance.isAmbariServiceName}} - {{alertInstance.serviceDisplayName}} + {{#if instance.isAmbariServiceName}} + {{instance.serviceDisplayName}} {{else}} - <a href="#" {{action routeToService alertInstance.service}}>{{alertInstance.serviceDisplayName}}</a> + <a href="#" {{action routeToService instance.service}}>{{instance.serviceDisplayName}}</a> {{/if}} </td> <td> - <a href="#" {{action routeToAlertDefinition alertInstance.definitionId target="controller"}}>{{alertInstance.label}}</a> + <a href="#" {{action routeToAlertDefinition instance.definitionId target="controller"}}>{{instance.label}}</a> </td> - <td>{{{alertInstance.status}}} - <time class="timeago" {{bindAttr data-original-title="alertInstance.statusChangedAndLastCheckedFormatted"}}>{{alertInstance.lastTriggeredForFormatted}}</time> + <td>{{template "templates/main/alerts/alert_instance/status"}} + <time class="timeago" {{bindAttr data-original-title="instance.statusChangedAndLastCheckedFormatted"}}>{{instance.lastTriggeredForFormatted}}</time> </td> <td><span - class="alert-text" {{bindAttr data-original-title="alertInstance.escapeSpecialCharactersFromTooltip"}} - class="alert-text">{{alertInstance.text}}</span></td> + class="alert-text" {{bindAttr data-original-title="instance.escapeSpecialCharactersFromTooltip"}} + class="alert-text">{{instance.text}}</span></td> </tr> {{/each}} {{else}} http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/templates/main/service/info/service_alert_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/service/info/service_alert_popup.hbs b/ambari-web/app/templates/main/service/info/service_alert_popup.hbs index 730906f..cbadf06 100644 --- a/ambari-web/app/templates/main/service/info/service_alert_popup.hbs +++ b/ambari-web/app/templates/main/service/info/service_alert_popup.hbs @@ -30,6 +30,7 @@ </div> </div> <div class="span4 status-col" rel="alert-status-tooltip" > + {{view App.AlertDefinitionSummary contentBinding="alert"}} <span class="timeago" {{bindAttr data-original-title="alert.lastTriggeredVerboseDisplay"}}> <span class="status-icon">{{{alert.status}}}</span> <time>{{alert.lastTriggeredForFormatted}}</time> http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/utils/ember_computed.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/ember_computed.js b/ambari-web/app/utils/ember_computed.js index 8d964ee..0eb0c9c 100644 --- a/ambari-web/app/utils/ember_computed.js +++ b/ambari-web/app/utils/ember_computed.js @@ -1049,7 +1049,7 @@ computed.firstNotBlank = generateComputedWithValues(function (values) { computed.formatUnavailable = function(dependentKey) { return computed(dependentKey, function () { var value = smartGet(this, dependentKey); - return (value || value == 0) ? value : Em.I18n.t('services.service.summary.notAvailable'); + return value || value == 0 ? value : Em.I18n.t('services.service.summary.notAvailable'); }); }; @@ -1089,4 +1089,32 @@ computed.countBasedMessage = function (dependentKey, zeroMsg, oneMsg, manyMsg) { } return oneMsg; }); -}; \ No newline at end of file +}; + +/** + * A computed property that returns property value according to the property key and object key + * App.*-keys are supported + * <pre> + * var o = Em.Object.create({ + * p1: {a: 1, b: 2, c: 3}, + * p2: 'a', + * p3: Em.computed.getByKey('p1', 'p2') + * }); + * console.log(o.get('p3')); // 1 + * o.set('p2', 'b'); + * console.log(o.get('p3')); // 2 + * o.set('p2', 'c'); + * console.log(o.get('p3')); // 3 + * </pre> + * + * @param {string} objectKey + * @param {string} propertyKey + * @returns {Ember.ComputedProperty} + */ +computed.getByKey = function (objectKey, propertyKey) { + return computed(objectKey, propertyKey, function () { + var object = smartGet(this, objectKey); + var property = smartGet(this, propertyKey); + return object ? object[property] : null; + }); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/app/views/main/alerts/alert_definition/alert_definition_summary.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/alerts/alert_definition/alert_definition_summary.js b/ambari-web/app/views/main/alerts/alert_definition/alert_definition_summary.js index ecf262c..b102b3b 100644 --- a/ambari-web/app/views/main/alerts/alert_definition/alert_definition_summary.js +++ b/ambari-web/app/views/main/alerts/alert_definition/alert_definition_summary.js @@ -21,45 +21,49 @@ App.AlertDefinitionSummary = Em.View.extend({ templateName: require('templates/main/alerts/alert_definition/alert_definition_summary'), - didInsertElement: function() { - this.stateObserver(); - }, + /** + * Bound from the template + * @type {App.AlertDefinition} + */ + content: null, - hostCount: 0, - states: [], + hasMultipleCount: Em.computed.gt('content.hostCnt', 0), - stateObserver: function () { - var order = this.get('content.order'), - summary = this.get('content.summary'), - shortState = this.get('content.shortState'); - - var hostCnt = 0; + definitionState: function () { + var content = this.get('content'); + if (!content) { + return []; + } + var order = content.get('order'); + var summary = content.get('summary'); + var hostCnt = content.get('hostCnt'); + var showCounts = hostCnt > 1; + var ret = []; order.forEach(function (state) { - hostCnt += summary[state] ? summary[state].count + summary[state].maintenanceCount : 0; - }); - var states = []; - if (hostCnt) { - order.forEach(function (state) { - if (summary[state]) { - if (summary[state].count) { - states.push({ - 'shortStateWithCounter': shortState[state] + (summary[state].count > 1 ? ' (' + summary[state].count + ')' : ''), - 'isMaintenance': false, - 'stateClass': 'alert-state-' + state - }); - } - if (summary[state].maintenanceCount) { - states.push({ - 'shortStateWithCounter': shortState[state] + (summary[state].maintenanceCount > 1 ? ' (' + summary[state].maintenanceCount + ')' : ''), - 'isMaintenance': true, - 'stateClass': 'alert-state-PENDING' - }); - } + var shortState = content.get('shortState')[state]; + var _stateSummary = { + state: 'alert-state-' + state, + count: '', + maintenanceCount: '' + }; + if (summary[state].count) { + var count = shortState; + if (showCounts) { + count += ' (' + summary[state].count + ')'; } - }, this); - } - this.set('hostCount', hostCnt); - this.set('states', states); - }.observes('content.summary') + _stateSummary.count = count; + } + // add status with maintenance mode icon + if (summary[state].maintenanceCount) { + var maintenanceCount = shortState; + if (showCounts) { + maintenanceCount += ' (' + summary[state].maintenanceCount + ')'; + } + _stateSummary.maintenanceCount = maintenanceCount; + } + ret.push(_stateSummary); + }); + return ret; + }.property('content.summary', 'content.hostCnt') }); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/test/aliases/computed/getByKey.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/aliases/computed/getByKey.js b/ambari-web/test/aliases/computed/getByKey.js new file mode 100644 index 0000000..149f0d7 --- /dev/null +++ b/ambari-web/test/aliases/computed/getByKey.js @@ -0,0 +1,55 @@ +/** + * 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 helpers = App.TestAliases.helpers; + +/** + * + * @param {Em.Object} context + * @param {string} propertyName + * @param {string} dependentKey + * @param {number} neededValue + */ +App.TestAliases.testAsComputedGetByKey = function (context, propertyName, objectKey, propertyKey) { + + var obj = Em.get(context, objectKey); + var toCheck = Object.keys(obj); + + describe('#' + propertyName + ' as Em.computed.getByKey', function () { + + afterEach(function () { + helpers.smartRestoreGet(context); + }); + + it('has valid dependent keys', function () { + expect(Em.meta(context).descs[propertyName]._dependentKeys).to.eql([objectKey, propertyKey]); + }); + + toCheck.forEach(function (key) { + var expectedValue = obj[key]; + it('should be `' + JSON.stringify(expectedValue) + '` if '+ JSON.stringify(propertyKey) + 'is ' + JSON.stringify(key), function () { + helpers.smartStubGet(context, propertyKey, key) + .propertyDidChange(context, propertyName); + var value = helpers.smartGet(context, propertyName); + expect(value).to.be.equal(expectedValue); + }); + }); + + }); + +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/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 f16bf4d..ac6ef93 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 @@ -19,6 +19,7 @@ var App = require('app'); var controller; var helpers = require('test/helpers'); +require('templates/main/alerts/alert_instance/status'); function getController() { http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/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 c911453..814f28e 100644 --- a/ambari-web/test/init_computed_aliases.js +++ b/ambari-web/test/init_computed_aliases.js @@ -193,4 +193,5 @@ require('test/aliases/computed/findBy'); require('test/aliases/computed/sumBy'); require('test/aliases/computed/and'); require('test/aliases/computed/or'); -require('test/aliases/computed/formatUnavailable'); \ No newline at end of file +require('test/aliases/computed/formatUnavailable'); +require('test/aliases/computed/getByKey'); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/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 d151faf..3de8aa6 100644 --- a/ambari-web/test/models/alerts/alert_definition_test.js +++ b/ambari-web/test/models/alerts/alert_definition_test.js @@ -34,48 +34,6 @@ describe('App.AlertDefinition', function () { App.TestAliases.testAsComputedAnd(getModel(), 'isHostAlertDefinition', ['isAmbariService', 'isAmbariAgentComponent']); - describe('#status', function () { - - Em.A([ - { - summary: {OK: {count: 1, maintenanceCount: 0}, UNKNOWN: {count: 1, maintenanceCount: 0}, WARNING: {count: 2, maintenanceCount: 0}, CRITICAL: {count: 0, maintenanceCount: 0}}, - m: 'No CRITICAL', - e: '<span class="alert-state-single-host label alert-state-OK">OK (1)</span> ' + - '<span class="alert-state-single-host label alert-state-WARNING">WARN (2)</span> ' + - '<span class="alert-state-single-host label alert-state-UNKNOWN">UNKWN (1)</span>' - }, - { - summary: {WARNING: {count: 2, maintenanceCount: 0}, CRITICAL: {count: 3, maintenanceCount: 0}, UNKNOWN: {count: 1, maintenanceCount: 0}, OK: {count: 1, maintenanceCount: 0}}, - m: 'All states exists', - e: '<span class="alert-state-single-host label alert-state-OK">OK (1)</span> ' + - '<span class="alert-state-single-host label alert-state-WARNING">WARN (2)</span> ' + - '<span class="alert-state-single-host label alert-state-CRITICAL">CRIT (3)</span> ' + - '<span class="alert-state-single-host label alert-state-UNKNOWN">UNKWN (1)</span>' - }, - { - summary: {OK: {count: 1, maintenanceCount: 0}, UNKNOWN: {count: 0, maintenanceCount: 0}, WARNING: {count: 0, maintenanceCount: 0}, CRITICAL: {count: 0, maintenanceCount: 0}}, - m: 'Single host', - e: '<span class="alert-state-single-host label alert-state-OK">OK</span>' - }, - { - summary: {OK: {count: 0, maintenanceCount: 1}, UNKNOWN: {count: 0, maintenanceCount: 0}, WARNING: {count: 0, maintenanceCount: 0}, CRITICAL: {count: 0, maintenanceCount: 0}}, - m: 'Maintenance OK alert', - e: '<span class="alert-state-single-host label alert-state-PENDING"><span class="icon-medkit"></span> OK</span>' - }, - { - summary: {}, - m: 'Pending', - e: '<span class="alert-state-single-host label alert-state-PENDING">NONE</span>' - } - ]).forEach(function (test) { - it(test.m, function () { - model.set('summary', test.summary); - expect(model.get('status')).to.equal(test.e); - }); - }); - - }); - describe('#isCriticalOrWarning', function () { Em.A([ @@ -207,6 +165,8 @@ describe('App.AlertDefinition', function () { }); + App.TestAliases.testAsComputedGetByKey(getModel(), 'typeIconClass', 'typeIcons', 'type'); + describe('REOPEN', function () { describe('#getSortDefinitionsByStatus', function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/test/models/alerts/alert_instance_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/alerts/alert_instance_test.js b/ambari-web/test/models/alerts/alert_instance_test.js index f3abd79..af9632f 100644 --- a/ambari-web/test/models/alerts/alert_instance_test.js +++ b/ambari-web/test/models/alerts/alert_instance_test.js @@ -22,14 +22,18 @@ require('models/alerts/alert_instance'); var model; +function getModel() { + return App.AlertInstance.createRecord(); +} + describe('App.AlertInstance', function () { beforeEach(function () { - - model = App.AlertInstance.createRecord(); - + model = getModel(); }); + App.TestAliases.testAsComputedGetByKey(getModel(), 'shortStateMsg', 'shortState', 'state'); + describe('#serviceDisplayName', function () { it('should get name for non-existing service', function () { @@ -56,30 +60,6 @@ describe('App.AlertInstance', function () { }); - describe('#status', function () { - - it('should show maint mode icon', function () { - - model.set('maintenanceState', 'ON'); - model.set('state', 'OK'); - var status = model.get('status'); - - expect(status).to.equal('<div class="label alert-state-single-host alert-state-PENDING"><span class="icon-medkit"></span> OK</div>'); - - }); - - it('should not show maint mode icon', function () { - - model.set('maintenanceState', 'OFF'); - model.set('state', 'OK'); - var status = model.get('status'); - - expect(status).to.equal('<div class="label alert-state-single-host alert-state-OK">OK</div>'); - - }); - - }); - describe('#escapeSpecialCharactersFromTooltip', function () { it('it Should Display Alert Without special characters "<" and ">"', function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/2925a6aa/ambari-web/test/utils/ember_computed_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/utils/ember_computed_test.js b/ambari-web/test/utils/ember_computed_test.js index 6491a26..410f445 100644 --- a/ambari-web/test/utils/ember_computed_test.js +++ b/ambari-web/test/utils/ember_computed_test.js @@ -1468,4 +1468,60 @@ describe('Ember.computed macros', function () { }); + describe('#getByKey', function () { + + beforeEach(function () { + this.obj = Em.Object.create({ + prop1: {a: 1, b: 2, c: 3}, + prop2: 'a', + prop3: Em.computed.getByKey('prop1', 'prop2'), + prop4: Em.computed.getByKey('prop1', 'App.someRandomTestingKey') + }); + App.set('someAnotherKey', 'a'); + }); + + it('prop3 dependent keys are valid', function () { + expect(Em.meta(this.obj).descs.prop3._dependentKeys).to.eql(['prop1', 'prop2']); + }); + + it('prop4 dependent keys are valid', function () { + expect(Em.meta(this.obj).descs.prop4._dependentKeys).to.eql(['prop1', 'App.someRandomTestingKey']); + }); + + it('prop3 value is 1', function () { + expect(this.obj.get('prop3')).to.be.equal(1); + }); + + it('prop3 value is 2', function () { + this.obj.set('prop2', 'b'); + expect(this.obj.get('prop3')).to.be.equal(2); + }); + + it('prop3 value is 3', function () { + this.obj.set('prop2', 'c'); + expect(this.obj.get('prop3')).to.be.equal(3); + }); + + it('prop3 value is 4', function () { + this.obj.set('prop1.c', 4); + this.obj.set('prop2', 'c'); + expect(this.obj.get('prop3')).to.be.equal(4); + }); + + it('prop4 values is 1', function () { + expect(this.obj.get('prop4')).to.be.equal(1); + }); + + it('prop4 values is 2', function () { + App.set('someAnotherKey', 'b'); + expect(this.obj.get('prop4')).to.be.equal(2); + }); + + it('prop4 values is 3', function () { + App.set('someAnotherKey', 'c'); + expect(this.obj.get('prop4')).to.be.equal(3); + }); + + }); + }); \ No newline at end of file