ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From onechipore...@apache.org
Subject ambari git commit: AMBARI-15515. Improve Em.computed.getByKey (onechiporenko)
Date Wed, 23 Mar 2016 07:53:17 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 215a61df1 -> 3ae91d255


AMBARI-15515. Improve Em.computed.getByKey (onechiporenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3ae91d25
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3ae91d25
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3ae91d25

Branch: refs/heads/trunk
Commit: 3ae91d255e717055dcc66ed514de2eec67f71f94
Parents: 215a61d
Author: Oleg Nechiporenko <onechiporenko@apache.org>
Authored: Tue Mar 22 16:57:06 2016 +0200
Committer: Oleg Nechiporenko <onechiporenko@apache.org>
Committed: Wed Mar 23 09:53:02 2016 +0200

----------------------------------------------------------------------
 ambari-web/app/models/host.js                   | 27 ++----
 ambari-web/app/models/host_component.js         | 27 ++----
 ambari-web/app/models/hosts.js                  | 88 +++++++-------------
 ambari-web/app/models/service.js                | 31 +++----
 ambari-web/app/models/service/flume.js          | 42 ++++------
 ambari-web/app/utils/ember_computed.js          | 20 ++++-
 ambari-web/test/aliases/computed/getByKey.js    | 28 +++++--
 .../test/models/alerts/alert_definition_test.js | 10 ++-
 .../test/models/alerts/alert_instance_test.js   | 10 ++-
 ambari-web/test/models/host_component_test.js   | 48 ++---------
 ambari-web/test/models/host_test.js             | 54 ++----------
 ambari-web/test/models/hosts_test.js            | 87 +++++++------------
 ambari-web/test/models/service/flume_test.js    | 57 ++++---------
 ambari-web/test/models/service_test.js          | 45 +++-------
 ambari-web/test/utils/ember_computed_test.js    | 12 ++-
 15 files changed, 207 insertions(+), 379 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/ambari-web/app/models/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/host.js b/ambari-web/app/models/host.js
index 4c6e9fb..1b7b326 100644
--- a/ambari-web/app/models/host.js
+++ b/ambari-web/app/models/host.js
@@ -209,25 +209,14 @@ App.Host = DS.Model.extend({
     return statusMap[this.get('healthStatus')] || 'health-status-DEAD-YELLOW';
   }.property('healthStatus'),
 
-  healthIconClass: function () {
-    switch (this.get('healthClass')) {
-      case 'health-status-LIVE':
-        return App.healthIconClassGreen;
-        break;
-      case 'health-status-DEAD-RED':
-        return App.healthIconClassRed;
-        break;
-      case 'health-status-DEAD-YELLOW':
-        return App.healthIconClassYellow;
-        break;
-      case 'health-status-DEAD-ORANGE':
-        return App.healthIconClassOrange;
-        break;
-      default:
-        return "";
-        break;
-    }
-  }.property('healthClass'),
+  healthIconClass: Em.computed.getByKey('healthIconClassMap', 'healthClass', ''),
+
+  healthIconClassMap: {
+    'health-status-LIVE': App.healthIconClassGreen,
+    'health-status-DEAD-RED': App.healthIconClassRed,
+    'health-status-DEAD-YELLOW': App.healthIconClassYellow,
+    'health-status-DEAD-ORANGE': App.healthIconClassOrange
+  },
 
   /**
    * Tooltip for host indicator

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/ambari-web/app/models/host_component.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/host_component.js b/ambari-web/app/models/host_component.js
index d3f1684..668c171 100644
--- a/ambari-web/app/models/host_component.js
+++ b/ambari-web/app/models/host_component.js
@@ -154,24 +154,15 @@ App.HostComponent = DS.Model.extend({
     return this.get('isActive') ? this.get('workStatus') : 'icon-medkit';
   }.property('workStatus', 'isActive'),
 
-  statusIconClass: function () {
-    switch (this.get('statusClass')) {
-      case 'STARTED':
-      case 'STARTING':
-        return App.healthIconClassGreen;
-        break;
-      case 'INSTALLED':
-      case 'STOPPING':
-        return App.healthIconClassRed;
-        break;
-      case 'UNKNOWN':
-        return App.healthIconClassYellow;
-        break;
-      default:
-        return "";
-        break;
-    }
-  }.property('statusClass'),
+  statusIconClass: Em.computed.getByKey('statusIconClassMap', 'statusClass', ''),
+
+  statusIconClassMap: {
+    STARTED: App.healthIconClassGreen,
+    STARTING: App.healthIconClassGreen,
+    INSTALLED: App.healthIconClassRed,
+    STOPPING: App.healthIconClassRed,
+    UNKNOWN: App.healthIconClassYellow
+  },
 
   componentTextStatus: function () {
     return App.HostComponentStatus.getTextStatus(this.get("workStatus"));

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/ambari-web/app/models/hosts.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/hosts.js b/ambari-web/app/models/hosts.js
index 85feab5..9275b3e 100644
--- a/ambari-web/app/models/hosts.js
+++ b/ambari-web/app/models/hosts.js
@@ -29,65 +29,39 @@ App.HostInfo = Ember.Object.extend({
   bootLog:null,
   bootStatus: 'PENDING',
   
-  bootStatusForDisplay:function () {
-    switch (this.get('bootStatus')) {
-      case 'PENDING':
-        return 'Preparing';
-      case 'REGISTERED':
-        return 'Success';
-      case 'FAILED':
-        return 'Failed';
-      case 'RUNNING':
-        return 'Installing';
-      case 'DONE':
-      case 'REGISTERING':
-      default:
-        return 'Registering';
-    }
-  }.property('bootStatus'),
+  bootStatusForDisplay: Em.computed.getByKey('bootStatusForDisplayMap', 'bootStatus', 'Registering'),
 
-  bootBarColor:function () {
-    switch (this.get('bootStatus')) {
-      case 'REGISTERED':
-        return 'progress-success';
-      case 'FAILED':
-        return 'progress-danger';
-      case 'PENDING':
-      case 'RUNNING':
-      case 'DONE':
-      case 'REGISTERING':
-      default:
-        return 'progress-info';
-    }
-  }.property('bootStatus'),
+  bootStatusForDisplayMap: {
+    PENDING: 'Preparing',
+    REGISTERED: 'Success',
+    FAILED: 'Failed',
+    RUNNING: 'Installing',
+    DONE: 'Registering',
+    REGISTERING: 'Registering'
+  },
 
-  bootStatusColor:function () {
-    switch (this.get('bootStatus')) {
-      case 'REGISTERED':
-        return 'text-success';
-      case 'FAILED':
-        return 'text-error';
-      case 'PENDING':
-      case 'RUNNING':
-      case 'DONE':
-      case 'REGISTERING':
-      default:
-        return 'text-info';
-    }
-  }.property('bootStatus'),
+  bootBarColor: Em.computed.getByKey('bootBarColorMap', 'bootStatus', 'progress-info'),
 
-  isBootDone:function () {
-    switch (this.get('bootStatus')) {
-      case 'REGISTERED':
-      case 'FAILED':
-        return true;
-      case 'PENDING':
-      case 'RUNNING':
-      case 'DONE':
-      case 'REGISTERING':
-      default:
-        return false;
-    }
+  bootBarColorMap: {
+    REGISTERED: 'progress-success',
+    FAILED: 'progress-danger',
+    PENDING: 'progress-info',
+    RUNNING: 'progress-info',
+    DONE: 'progress-info',
+    REGISTERING: 'progress-info'
+  },
+
+  bootStatusColor:Em.computed.getByKey('bootStatusColorMap', 'bootStatus', 'text-info'),
+
+  bootStatusColorMap: {
+    REGISTERED: 'text-success',
+    FAILED: 'text-error',
+    PENDING: 'text-info',
+    RUNNING: 'text-info',
+    DONE: 'text-info',
+    REGISTERING: 'text-info'
+  },
+
+  isBootDone: Em.computed.existsIn('bootStatus', ['REGISTERED', 'FAILED'])
 
-  }.property('bootStatus')
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/ambari-web/app/models/service.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/service.js b/ambari-web/app/models/service.js
index c3347c2..3cf0a8c 100644
--- a/ambari-web/app/models/service.js
+++ b/ambari-web/app/models/service.js
@@ -52,27 +52,16 @@ App.Service = DS.Model.extend({
     return clientComponents.concat(slaveComponents).concat(masterComponents);
   }.property('clientComponents.@each', 'slaveComponents.@each','masterComponents.@each'),
 
-  // Instead of making healthStatus a computed property that listens on hostComponents.@each.workStatus,
-  // we are creating a separate observer _updateHealthStatus.  This is so that healthStatus
is updated
-  // only once after the run loop.  This is because Ember invokes the computed property every
time
-  // a property that it depends on changes.  For example, App.statusMapper's map function
would invoke
-  // the computed property too many times and freezes the UI without this hack.
-  // See http://stackoverflow.com/questions/12467345/ember-js-collapsing-deferring-expensive-observers-or-computed-properties
-  healthStatus: function(){
-    switch(this.get('workStatus')){
-      case 'STARTED':
-        return 'green';
-      case 'STARTING':
-        return 'green-blinking';
-      case 'INSTALLED':
-        return 'red';
-      case 'STOPPING':
-        return 'red-blinking';
-      case 'UNKNOWN':
-      default:
-        return 'yellow';
-    }
-  }.property('workStatus'),
+  healthStatus: Em.computed.getByKey('healthStatusMap', 'workStatus', 'yellow'),
+
+  healthStatusMap: {
+    STARTED: 'green',
+    STARTING: 'green-blinking',
+    INSTALLED: 'red',
+    STOPPING: 'red-blinking',
+    UNKNOWN: 'yellow'
+  },
+
   isStopped: Em.computed.equal('workStatus', 'INSTALLED'),
 
   isStarted: Em.computed.equal('workStatus', 'STARTED'),

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/ambari-web/app/models/service/flume.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/service/flume.js b/ambari-web/app/models/service/flume.js
index 9bbcc1a..d482ab6 100644
--- a/ambari-web/app/models/service/flume.js
+++ b/ambari-web/app/models/service/flume.js
@@ -41,35 +41,21 @@ App.FlumeAgent = DS.Model.extend({
   sourcesCount: DS.attr('number'),
   sinksCount: DS.attr('number'),
 
-  healthClass : function() {
-    switch (this.get('status')) {
-    case 'RUNNING':
-      return App.healthIconClassGreen;
-      break;
-    case 'NOT_RUNNING':
-      return App.healthIconClassRed;
-      break;
-    case 'UNKNOWN':
-    default:
-      return App.healthIconClassYellow;
-      break;
-    }
-  }.property('status'),
+  healthClass: Em.computed.getByKey('healthClassMap', 'status', App.healthIconClassYellow),
 
-  displayStatus : function() {
-    switch (this.get('status')) {
-      case 'RUNNING':
-        return Em.I18n.t('common.running');
-        break;
-      case 'NOT_RUNNING':
-        return Em.I18n.t('common.stopped');
-        break;
-      case 'UNKNOWN':
-      default:
-        return Em.I18n.t('common.unknown');
-        break;
-    }
-  }.property('status')
+  healthClassMap: {
+    RUNNING: App.healthIconClassGreen,
+    NOT_RUNNING: App.healthIconClassRed,
+    UNKNOWN: App.healthIconClassYellow
+  },
+
+  displayStatus: Em.computed.getByKey('displayStatusMap', 'status', Em.I18n.t('common.unknown')),
+
+  displayStatusMap: {
+    RUNNING: Em.I18n.t('common.running'),
+    NOT_RUNNING: Em.I18n.t('common.stopped'),
+    UNKNOWN: Em.I18n.t('common.unknown')
+  }
 
 });
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/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 0eb0c9c..b5e8349 100644
--- a/ambari-web/app/utils/ember_computed.js
+++ b/ambari-web/app/utils/ember_computed.js
@@ -1107,14 +1107,30 @@ computed.countBasedMessage = function (dependentKey, zeroMsg, oneMsg,
manyMsg) {
  *   console.log(o.get('p3')); // 3
  * </pre>
  *
+ * With `defaultValue`
+ * <pre>
+ *   var o = Em.Object.create({
+ *    p1: {a: 1, b: 2, c: 3},
+ *    p2: 'd',
+ *    p3: Em.computed.getByKey('p1', 'p2', 100500)
+ *   });
+ *   console.log(o.get('p3')); // 100500 - default value is returned, because there is no
key `d` in the `p1`
+ * </pre>
+ * <b>IMPORTANT!</b> This CP <b>SHOULD NOT</b> be used with for object
with values equal to the views (like <code>{a: App.MyViewA, b: App.MyViewB}</code>)
+ * This restriction exists because views may be undefined on the moment when this CP is calculated
(files are not `required` yet)
+ *
  * @param {string} objectKey
  * @param {string} propertyKey
+ * @param {*} [defaultValue]
  * @returns {Ember.ComputedProperty}
  */
-computed.getByKey = function (objectKey, propertyKey) {
+computed.getByKey = function (objectKey, propertyKey, defaultValue) {
   return computed(objectKey, propertyKey, function () {
     var object = smartGet(this, objectKey);
     var property = smartGet(this, propertyKey);
-    return object ? object[property] : null;
+    if (!object) {
+      return null;
+    }
+    return object.hasOwnProperty(property) ? object[property] : defaultValue;
   });
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/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
index 149f0d7..d3153f7 100644
--- a/ambari-web/test/aliases/computed/getByKey.js
+++ b/ambari-web/test/aliases/computed/getByKey.js
@@ -22,13 +22,15 @@ var helpers = App.TestAliases.helpers;
  *
  * @param {Em.Object} context
  * @param {string} propertyName
- * @param {string} dependentKey
- * @param {number} neededValue
+ * @param {string} objectKey
+ * @param {string} propertyKey
+ * @param {{defaultValue: *, map: object}} [checks]
  */
-App.TestAliases.testAsComputedGetByKey = function (context, propertyName, objectKey, propertyKey)
{
+App.TestAliases.testAsComputedGetByKey = function (context, propertyName, objectKey, propertyKey,
checks) {
 
-  var obj = Em.get(context, objectKey);
-  var toCheck = Object.keys(obj);
+  var _checks = checks || {};
+  var obj = _checks.map || Em.get(context, objectKey);
+  var defaultValueIsSet = _checks.hasOwnProperty('defaultValue');
 
   describe('#' + propertyName + ' as Em.computed.getByKey', function () {
 
@@ -40,16 +42,26 @@ App.TestAliases.testAsComputedGetByKey = function (context, propertyName,
object
       expect(Em.meta(context).descs[propertyName]._dependentKeys).to.eql([objectKey, propertyKey]);
     });
 
-    toCheck.forEach(function (key) {
+    Object.keys(obj).forEach(function (key) {
       var expectedValue = obj[key];
-      it('should be `' + JSON.stringify(expectedValue) + '` if '+ JSON.stringify(propertyKey)
+ 'is ' + JSON.stringify(key), function () {
+      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);
+        expect(value).to.be.eql(expectedValue);
       });
     });
 
+    if (defaultValueIsSet) {
+      var defaultValue = _checks.defaultValue;
+      it('should be `' + JSON.stringify(defaultValue) + '` if ' + JSON.stringify(propertyKey)
+ ' is not exist in the tested object', function () {
+        helpers.smartStubGet(context, propertyKey, '' + Math.random())
+          .propertyDidChange(context, propertyName);
+        var value = helpers.smartGet(context, propertyName);
+        expect(value).to.be.eql(defaultValue);
+      });
+    }
+
   });
 
 };
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/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 3de8aa6..2bc8565 100644
--- a/ambari-web/test/models/alerts/alert_definition_test.js
+++ b/ambari-web/test/models/alerts/alert_definition_test.js
@@ -165,7 +165,15 @@ describe('App.AlertDefinition', function () {
 
   });
 
-  App.TestAliases.testAsComputedGetByKey(getModel(), 'typeIconClass', 'typeIcons', 'type');
+  App.TestAliases.testAsComputedGetByKey(getModel(), 'typeIconClass', 'typeIcons', 'type',
{map: {
+    METRIC: 'icon-bolt',
+    SCRIPT: 'icon-file-text',
+    WEB: 'icon-globe',
+    PORT: 'icon-signin',
+    AGGREGATE: 'icon-plus',
+    SERVER: 'icon-desktop',
+    RECOVERY: 'icon-desktop'
+  }});
 
   describe('REOPEN', function () {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/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 af9632f..8a88b3f 100644
--- a/ambari-web/test/models/alerts/alert_instance_test.js
+++ b/ambari-web/test/models/alerts/alert_instance_test.js
@@ -32,7 +32,15 @@ describe('App.AlertInstance', function () {
     model = getModel();
   });
 
-  App.TestAliases.testAsComputedGetByKey(getModel(), 'shortStateMsg', 'shortState', 'state');
+  App.TestAliases.testAsComputedGetByKey(getModel(), 'shortStateMsg', 'shortState', 'state',
{
+    map: {
+      CRITICAL: 'CRIT',
+      WARNING: 'WARN',
+      OK: 'OK',
+      UNKNOWN: 'UNKWN',
+      PENDING: 'NONE'
+    }
+  });
 
   describe('#serviceDisplayName', function () {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/ambari-web/test/models/host_component_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/host_component_test.js b/ambari-web/test/models/host_component_test.js
index 5f88eac..ab1a1e3 100644
--- a/ambari-web/test/models/host_component_test.js
+++ b/ambari-web/test/models/host_component_test.js
@@ -180,47 +180,13 @@ describe('App.HostComponent', function() {
     });
   });
 
-  describe('#statusIconClass', function () {
-    var testCases = [
-      {
-        statusClass: 'STARTED',
-        result: 'icon-ok-sign'
-      },
-      {
-        statusClass: 'STARTING',
-        result: 'icon-ok-sign'
-      },
-      {
-        statusClass: 'INSTALLED',
-        result: 'icon-warning-sign'
-      },
-      {
-        statusClass: 'STOPPING',
-        result: 'icon-warning-sign'
-      },
-      {
-        statusClass: 'UNKNOWN',
-        result: 'icon-question-sign'
-      },
-      {
-        statusClass: '',
-        result: ''
-      }
-    ];
-
-    beforeEach(function () {
-      hc.reopen({
-        statusClass: ''
-      });
-    });
-    testCases.forEach(function (test) {
-      it('statusClass - ' + test.statusClass, function () {
-        hc.set('statusClass', test.statusClass);
-        hc.propertyDidChange('statusIconClass');
-        expect(hc.get('statusIconClass')).to.equal(test.result);
-      });
-    });
-  });
+  App.TestAliases.testAsComputedGetByKey(hc, 'statusIconClass', 'statusIconClassMap', 'statusClass',
{defaultValue: '', map: {
+    STARTED: App.healthIconClassGreen,
+    STARTING: App.healthIconClassGreen,
+    INSTALLED: App.healthIconClassRed,
+    STOPPING: App.healthIconClassRed,
+    UNKNOWN: App.healthIconClassYellow
+  }});
 
   describe('#componentTextStatus', function () {
     before(function () {

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/ambari-web/test/models/host_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/host_test.js b/ambari-web/test/models/host_test.js
index d047a70..5b63b10 100644
--- a/ambari-web/test/models/host_test.js
+++ b/ambari-web/test/models/host_test.js
@@ -425,53 +425,11 @@ describe('App.Host', function () {
     });
   });
 
-  describe('#healthIconClass', function () {
-    var testCases = [
-      {
-        params: {
-          healthClass: 'health-status-LIVE'
-        },
-        result: 'icon-ok-sign'
-      },
-      {
-        params: {
-          healthClass: 'health-status-DEAD-RED'
-        },
-        result: 'icon-warning-sign'
-      },
-      {
-        params: {
-          healthClass: 'health-status-DEAD-YELLOW'
-        },
-        result: 'icon-question-sign'
-      },
-      {
-        params: {
-          healthClass: 'health-status-DEAD-ORANGE'
-        },
-        result: 'icon-minus-sign'
-      },
-      {
-        params: {
-          healthClass: ''
-        },
-        result: ''
-      }
-    ];
-
-    beforeEach(function() {
-      host1.reopen({
-        healthClass: ''
-      });
-    });
-
-    testCases.forEach(function (test) {
-      it('healthClass - ' + test.params.healthClass, function () {
-        host1.set('healthClass', test.params.healthClass);
-        host1.propertyDidChange('healthIconClass');
-        expect(host1.get('healthIconClass')).to.equal(test.result);
-      });
-    });
-  });
+  App.TestAliases.testAsComputedGetByKey(host1, 'healthIconClass', 'healthIconClassMap',
'healthClass', {defaultValue: '', map: {
+    'health-status-LIVE': App.healthIconClassGreen,
+    'health-status-DEAD-RED': App.healthIconClassRed,
+    'health-status-DEAD-YELLOW': App.healthIconClassYellow,
+    'health-status-DEAD-ORANGE': App.healthIconClassOrange
+  }});
 
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/ambari-web/test/models/hosts_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/hosts_test.js b/ambari-web/test/models/hosts_test.js
index 288d425..b9c99c0 100644
--- a/ambari-web/test/models/hosts_test.js
+++ b/ambari-web/test/models/hosts_test.js
@@ -20,68 +20,37 @@ var App = require('app');
 
 require('models/hosts');
 
-var hostInfo,
-  statusCases = [
-    {
-      status: 'REGISTERED',
-      bootStatusForDisplay: 'Success',
-      bootBarColor: 'progress-success',
-      bootStatusColor: 'text-success',
-      isBootDone: true
-    },
-    {
-      status: 'FAILED',
-      bootStatusForDisplay: 'Failed',
-      bootBarColor: 'progress-danger',
-      bootStatusColor: 'text-error',
-      isBootDone: true
-    },
-    {
-      status: 'PENDING',
-      bootStatusForDisplay: 'Preparing',
-      bootBarColor: 'progress-info',
-      bootStatusColor: 'text-info',
-      isBootDone: false
-    },
-    {
-      status: 'RUNNING',
-      bootStatusForDisplay: 'Installing',
-      bootBarColor: 'progress-info',
-      bootStatusColor: 'text-info',
-      isBootDone: false
-    },
-    {
-      status: 'DONE',
-      bootStatusForDisplay: 'Registering',
-      bootBarColor: 'progress-info',
-      bootStatusColor: 'text-info',
-      isBootDone: false
-    },
-    {
-      status: 'REGISTERING',
-      bootStatusForDisplay: 'Registering',
-      bootBarColor: 'progress-info',
-      bootStatusColor: 'text-info',
-      isBootDone: false
-    }
-  ],
-  tests = ['bootStatusForDisplay', 'bootBarColor', 'bootStatusColor', 'isBootDone'];
+function getModel() {
+  return App.HostInfo.create();
+}
 
 describe('App.HostInfo', function () {
 
-  beforeEach(function () {
-    hostInfo = App.HostInfo.create();
-  });
+  App.TestAliases.testAsComputedGetByKey(getModel(), 'bootStatusForDisplay', 'bootStatusForDisplayMap',
'bootStatus', {defaultValue: 'Registering', map: {PENDING: 'Preparing',
+    REGISTERED: 'Success',
+    FAILED: 'Failed',
+    RUNNING: 'Installing',
+    DONE: 'Registering',
+    REGISTERING: 'Registering'}});
 
-  tests.forEach(function (property) {
-    describe('#' + property, function () {
-      statusCases.forEach(function (testCase) {
-        it('should be ' + testCase[property], function () {
-          hostInfo.set('bootStatus', testCase.status);
-          expect(hostInfo.get(property)).to.equal(testCase[property]);
-        });
-      });
-    });
-  });
+  App.TestAliases.testAsComputedGetByKey(getModel(), 'bootBarColor', 'bootBarColorMap', 'bootStatus',
{defaultValue: 'progress-info', map: {
+    REGISTERED: 'progress-success',
+    FAILED: 'progress-danger',
+    PENDING: 'progress-info',
+    RUNNING: 'progress-info',
+    DONE: 'progress-info',
+    REGISTERING: 'progress-info'
+  }});
+
+  App.TestAliases.testAsComputedGetByKey(getModel(), 'bootStatusColor', 'bootStatusColorMap',
'bootStatus', {defaultValue: 'text-info', map: {
+    REGISTERED: 'text-success',
+    FAILED: 'text-error',
+    PENDING: 'text-info',
+    RUNNING: 'text-info',
+    DONE: 'text-info',
+    REGISTERING: 'text-info'
+  }});
+
+  App.TestAliases.testAsComputedExistsIn(getModel(), 'isBootDone', 'bootStatus', ['REGISTERED',
'FAILED']);
 
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/ambari-web/test/models/service/flume_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/service/flume_test.js b/ambari-web/test/models/service/flume_test.js
index efad7e5..55fd135 100644
--- a/ambari-web/test/models/service/flume_test.js
+++ b/ambari-web/test/models/service/flume_test.js
@@ -25,29 +25,11 @@ var flumeAgent,
   flumeAgentData = {
     id: 'agent',
     name: 'agent'
-  },
-  cases = [
-    {
-      status: 'RUNNING',
-      healthClass: App.healthIconClassGreen,
-      displayStatus: Em.I18n.t('common.running')
-    },
-    {
-      status: 'NOT_RUNNING',
-      healthClass: App.healthIconClassRed,
-      displayStatus: Em.I18n.t('common.stopped')
-    },
-    {
-      status: 'UNKNOWN',
-      healthClass: App.healthIconClassYellow,
-      displayStatus: Em.I18n.t('common.unknown')
-    },
-    {
-      status: 'ANOTHER_STATUS',
-      healthClass: App.healthIconClassYellow,
-      displayStatus: Em.I18n.t('common.unknown')
-    }
-  ];
+  };
+
+function getModel() {
+  return App.FlumeAgent.createRecord();
+}
 
 describe('App.FlumeAgent', function () {
 
@@ -59,23 +41,16 @@ describe('App.FlumeAgent', function () {
     modelSetup.deleteRecord(flumeAgent);
   });
 
-  describe('#healthClass', function () {
-    cases.forEach(function (item) {
-      var healthClass = item.healthClass;
-      it('should be ' + healthClass, function () {
-        flumeAgent.set('status', item.status);
-        expect(flumeAgent.get('healthClass')).to.equal(healthClass);
-      });
-    });
-  });
+  App.TestAliases.testAsComputedGetByKey(getModel(), 'healthClass', 'healthClassMap', 'status',
{defaultValue: App.healthIconClassYellow, map: {
+    RUNNING: App.healthIconClassGreen,
+    NOT_RUNNING: App.healthIconClassRed,
+    UNKNOWN: App.healthIconClassYellow
+  }});
+
+  App.TestAliases.testAsComputedGetByKey(getModel(), 'displayStatus', 'displayStatusMap',
'status', {defaultValue: Em.I18n.t('common.unknown'), map: {
+    RUNNING: Em.I18n.t('common.running'),
+    NOT_RUNNING: Em.I18n.t('common.stopped'),
+    UNKNOWN: Em.I18n.t('common.unknown')
+  }});
 
-  describe('#displayStatus', function () {
-    cases.forEach(function (item) {
-      var displayStatus = item.displayStatus;
-      it('should be ' + displayStatus, function () {
-        flumeAgent.set('status', item.status);
-        expect(flumeAgent.get('displayStatus')).to.equal(displayStatus);
-      });
-    });
-  });
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/ambari-web/test/models/service_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/service_test.js b/ambari-web/test/models/service_test.js
index 8643f5d..6caf80a 100644
--- a/ambari-web/test/models/service_test.js
+++ b/ambari-web/test/models/service_test.js
@@ -25,32 +25,6 @@ var service,
   serviceData = {
     id: 'service'
   },
-  healthCases = [
-    {
-      status: 'STARTED',
-      health: 'green'
-    },
-    {
-      status: 'STARTING',
-      health: 'green-blinking'
-    },
-    {
-      status: 'INSTALLED',
-      health: 'red'
-    },
-    {
-      status: 'STOPPING',
-      health: 'red-blinking'
-    },
-    {
-      status: 'UNKNOWN',
-      health: 'yellow'
-    },
-    {
-      status: 'ANOTHER',
-      health: 'yellow'
-    }
-  ],
   statusPropertiesCases = [
     {
       status: 'INSTALLED',
@@ -104,6 +78,10 @@ var service,
     host0: ['service0', 'service1']
 };
 
+function getModel() {
+  return App.Service.createRecord(serviceData);
+}
+
 describe('App.Service', function () {
 
   beforeEach(function () {
@@ -125,14 +103,13 @@ describe('App.Service', function () {
     });
   });
 
-  describe('#healthStatus', function () {
-    healthCases.forEach(function (item) {
-      it('should be ' + item.health, function () {
-        service.set('workStatus', item.status);
-        expect(service.get('healthStatus')).to.equal(item.health);
-      });
-    });
-  });
+  App.TestAliases.testAsComputedGetByKey(getModel(), 'healthStatus', 'healthStatusMap', 'workStatus',
{defaultValue: 'yellow', map: {
+    STARTED: 'green',
+    STARTING: 'green-blinking',
+    INSTALLED: 'red',
+    STOPPING: 'red-blinking',
+    UNKNOWN: 'yellow'
+  }});
 
   statusPropertiesCases.forEach(function (item) {
     var status = item.status,

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ae91d25/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 410f445..fe5f890 100644
--- a/ambari-web/test/utils/ember_computed_test.js
+++ b/ambari-web/test/utils/ember_computed_test.js
@@ -1475,7 +1475,8 @@ describe('Ember.computed macros', function () {
         prop1: {a: 1, b: 2, c: 3},
         prop2: 'a',
         prop3: Em.computed.getByKey('prop1', 'prop2'),
-        prop4: Em.computed.getByKey('prop1', 'App.someRandomTestingKey')
+        prop4: Em.computed.getByKey('prop1', 'App.someRandomTestingKey'),
+        prop5: Em.computed.getByKey('prop1', 'prop2', 100500) // with default value
       });
       App.set('someAnotherKey', 'a');
     });
@@ -1488,6 +1489,10 @@ describe('Ember.computed macros', function () {
       expect(Em.meta(this.obj).descs.prop4._dependentKeys).to.eql(['prop1', 'App.someRandomTestingKey']);
     });
 
+    it('prop5 dependent keys are valid', function () {
+      expect(Em.meta(this.obj).descs.prop5._dependentKeys).to.eql(['prop1', 'prop2']);
+    });
+
     it('prop3 value is 1', function () {
       expect(this.obj.get('prop3')).to.be.equal(1);
     });
@@ -1522,6 +1527,11 @@ describe('Ember.computed macros', function () {
       expect(this.obj.get('prop4')).to.be.equal(3);
     });
 
+    it('prop5 value is set to the default value', function () {
+      this.obj.set('prop2', 'd');
+      expect(this.obj.get('prop5')).to.be.equal(100500);
+    });
+
   });
 
 });
\ No newline at end of file


Mime
View raw message