This is an automated email from the ASF dual-hosted git repository.

ncole pushed a commit to branch branch-feature-AMBARI-21674
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit c8fd5494f366473748fa547afe872b81e0b8f758
Author: Andrii Tkach <[email protected]>
AuthorDate: Thu Jan 25 14:58:06 2018 +0200

    AMBARI-22840 Standardize precision when expressing durations
---
 ambari-web/app/assets/test/tests.js                |  3 -
 .../main/charts/heatmap_metrics/heatmap_metric.js  |  2 +-
 ambari-web/app/utils/date/date.js                  | 86 ++++++++++----------
 .../main/dashboard/widgets/hbase_master_uptime.js  |  7 +-
 .../main/dashboard/widgets/namenode_uptime.js      |  7 +-
 .../dashboard/widgets/resource_manager_uptime.js   |  7 +-
 .../main/dashboard/widgets/uptime_text_widget.js   | 70 ++++------------
 .../charts/heatmap_metrics/heatmap_metric_test.js  |  4 +-
 .../manage_config_groups_controller_test.js        |  5 +-
 ambari-web/test/mappers/service_mapper_test.js     |  5 +-
 ambari-web/test/utils/date/date_test.js            | 52 +++++-------
 .../common/host_progress_popup_body_view_test.js   | 33 ++++----
 .../stack_upgrade/upgrade_history_view_test.js     |  4 +-
 .../dashboard/widgets/hbase_master_uptime_test.js  | 91 ---------------------
 .../main/dashboard/widgets/namenode_uptime_test.js | 95 ----------------------
 .../widgets/resource_manager_uptime_test.js        | 83 -------------------
 .../dashboard/widgets/uptime_text_widget_test.js   | 70 ++++++++--------
 17 files changed, 151 insertions(+), 473 deletions(-)

diff --git a/ambari-web/app/assets/test/tests.js 
b/ambari-web/app/assets/test/tests.js
index d20f531..dbc4d55 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -308,9 +308,6 @@ var files = [
   'test/views/main/dashboard/widgets/hbase_average_load_test',
   'test/views/main/dashboard/widgets/hbase_regions_in_transition_test',
   'test/views/main/dashboard/widgets/namenode_rpc_test',
-  'test/views/main/dashboard/widgets/hbase_master_uptime_test',
-  'test/views/main/dashboard/widgets/namenode_uptime_test',
-  'test/views/main/dashboard/widgets/resource_manager_uptime_test',
   'test/views/main/dashboard/widgets/links_widget_test',
   'test/views/main/dashboard/widgets/pie_chart_widget_test',
   'test/views/main/dashboard/widgets/namenode_cpu_test',
diff --git 
a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js 
b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js
index 630c5c2..9cae1df 100644
--- a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js
+++ b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js
@@ -156,7 +156,7 @@ App.MainChartHeatmapMetric = Em.Object.extend({
     var to = this.formatLegendNumber(max);
     var label;
     if ($.trim(labelSuffix) == 'ms') {
-      label = date.timingFormat(from, 'zeroValid') + " - " + 
date.timingFormat(to, 'zeroValid');
+      label = date.timingFormat(from) + " - " + date.timingFormat(to);
     } else {
       label = from + labelSuffix + " - " + to + labelSuffix;
     }
diff --git a/ambari-web/app/utils/date/date.js 
b/ambari-web/app/utils/date/date.js
index d461d21..f3cb205 100644
--- a/ambari-web/app/utils/date/date.js
+++ b/ambari-web/app/utils/date/date.js
@@ -138,65 +138,69 @@ module.exports = {
       return Em.I18n.t('common.na');
     }
     if (endDate.getFullYear() != 1969 && endTimestamp > 0) {
-      durationSummary = '' + this.timingFormat(endTimestamp - startTimestamp, 
1);
+      durationSummary = '' + this.timingFormat(endTimestamp - startTimestamp);
       return durationSummary.contains('-') ? Em.I18n.t('common.na') : 
durationSummary; //lasted for xx secs
     } else {
       // still running, duration till now
       var time = (App.dateTimeWithTimeZone() - startTimestamp) < 0 ? 0 : 
(App.dateTimeWithTimeZone() - startTimestamp);
-      durationSummary = '' + this.timingFormat(time, 1);
+      durationSummary = '' + this.timingFormat(time);
     }
     return durationSummary.contains('-') ? Em.I18n.t('common.na') : 
durationSummary;
   },
 
   /**
-   * Convert time in mseconds to
-   * 30 ms = 30 ms
-   * 300 ms = 300 ms
-   * 999 ms = 999 ms
-   * 1000 ms = 1.00 secs
-   * 3000 ms = 3.00 secs
-   * 35000 ms = 35.00 secs
-   * 350000 ms = 350.00 secs
-   * 999999 ms = 999.99 secs
-   * 1000000 ms = 16.66 mins
-   * 3500000 secs = 58.33 mins
+   * Format: "{#days}d {#hours}h {#minutes}m {#seconds}s {#milliseconds}ms"
+   * Example: "1d 3h 46m"
    *
-   * @param {number} time
-   * @param {bool} [zeroValid] for the case to show 0 when time is 0, not null
+   * Display optimization rules:
+   *   if time more than a day then hide time lower than minute
+   *   if time more than a minute and less than an hour then hide time lower 
than second
+   * @param {number|string} time
    * @return {string|null} formatted date
    * @method timingFormat
    */
-  timingFormat: function (time, /* optional */ zeroValid) {
-    var intTime = parseInt(time);
-    if (zeroValid && intTime == 0) {
-      return 0 + ' secs';
-    }
-    if (!intTime) {
+  timingFormat: function (time) {
+    if (Em.isNone(time)) {
       return null;
     }
-    var timeStr = intTime.toString();
-    var lengthOfNumber = timeStr.length;
-    var oneMinMs = 60000;
-    var oneHourMs = 3600000;
-    var oneDayMs = 86400000;
-
-    if (lengthOfNumber < 4) {
-      return time + ' ms';
-    }
-    if (lengthOfNumber < 7) {
-      time = (time / 1000).toFixed(2);
-      return time + ' secs';
+
+    time = parseInt(time);
+    const fullTime = time;
+    let duration = '';
+
+    if (time === 0) {
+      return '0s';
     }
-    if (time < oneHourMs) {
-      time = (time / oneMinMs).toFixed(2);
-      return time + ' mins';
+
+    const oneSecMs = 1000;
+    const oneMinMs = 60000;
+    const oneHourMs = 3600000;
+    const oneDayMs = 86400000;
+    let days, hours, minutes, seconds, milliseconds;
+
+    [days, time] = this.extractTimeUnit(time, oneDayMs, 'd');
+    [hours, time] = this.extractTimeUnit(time, oneHourMs, 'h');
+    [minutes, time] = this.extractTimeUnit(time, oneMinMs, 'm');
+    duration += days + hours + minutes;
+    if (fullTime < oneDayMs) {
+      [seconds, time] = this.extractTimeUnit(time, oneSecMs, 's');
+      duration += seconds;
+      if (fullTime < oneMinMs) {
+        [milliseconds, time] = this.extractTimeUnit(time, 1, 'ms');
+        duration += milliseconds;
+      }
     }
-    if (time < oneDayMs) {
-      time = (time / oneHourMs).toFixed(2);
-      return time + ' hours';
+
+    return duration.trim();
+  },
+
+  extractTimeUnit: function (time, unitValue, unitSuffix) {
+    let result = '';
+    if (time >= unitValue) {
+      result = Math.floor(time / unitValue) + `${unitSuffix} `;
+      time -= Math.floor(time / unitValue) * unitValue;
     }
-    time = (time / oneDayMs).toFixed(2);
-    return time + ' days';
+    return [result, time];
   },
 
   /**
diff --git a/ambari-web/app/views/main/dashboard/widgets/hbase_master_uptime.js 
b/ambari-web/app/views/main/dashboard/widgets/hbase_master_uptime.js
index ea338dd..8ca3671 100644
--- a/ambari-web/app/views/main/dashboard/widgets/hbase_master_uptime.js
+++ b/ambari-web/app/views/main/dashboard/widgets/hbase_master_uptime.js
@@ -21,11 +21,6 @@ var App = require('app');
 App.HBaseMasterUptimeView = App.UptimeTextDashboardWidgetView.extend({
 
   component: 'Hbase Master',
-  modelField: 'masterStartTime',
-
-  didInsertElement: function() {
-    this._super();
-    this.calc();
-  }
+  modelField: 'masterStartTime'
 
 });
\ No newline at end of file
diff --git a/ambari-web/app/views/main/dashboard/widgets/namenode_uptime.js 
b/ambari-web/app/views/main/dashboard/widgets/namenode_uptime.js
index 30ae592..3f4876f 100644
--- a/ambari-web/app/views/main/dashboard/widgets/namenode_uptime.js
+++ b/ambari-web/app/views/main/dashboard/widgets/namenode_uptime.js
@@ -21,11 +21,6 @@ var App = require('app');
 App.NameNodeUptimeView = App.UptimeTextDashboardWidgetView.extend({
 
   component: 'NameNode',
-  modelField: 'nameNodeStartTime',
-
-  didInsertElement: function() {
-    this._super();
-    this.calc();
-  }
+  modelField: 'nameNodeStartTime'
 
 });
\ No newline at end of file
diff --git 
a/ambari-web/app/views/main/dashboard/widgets/resource_manager_uptime.js 
b/ambari-web/app/views/main/dashboard/widgets/resource_manager_uptime.js
index 72f2ca3..a9da7a8 100644
--- a/ambari-web/app/views/main/dashboard/widgets/resource_manager_uptime.js
+++ b/ambari-web/app/views/main/dashboard/widgets/resource_manager_uptime.js
@@ -21,11 +21,6 @@ var App = require('app');
 App.ResourceManagerUptimeView = App.UptimeTextDashboardWidgetView.extend({
 
   component: 'ResourceManager',
-  modelField: 'resourceManagerStartTime',
-
-  didInsertElement: function() {
-    this._super();
-    this.calc();
-  }
+  modelField: 'resourceManagerStartTime'
 
 });
diff --git a/ambari-web/app/views/main/dashboard/widgets/uptime_text_widget.js 
b/ambari-web/app/views/main/dashboard/widgets/uptime_text_widget.js
index 74d59f1..76982c1 100644
--- a/ambari-web/app/views/main/dashboard/widgets/uptime_text_widget.js
+++ b/ambari-web/app/views/main/dashboard/widgets/uptime_text_widget.js
@@ -38,7 +38,7 @@ App.UptimeTextDashboardWidgetView = 
App.TextDashboardWidgetView.extend({
 
   data: null,
 
-  content: null,
+  content: Em.computed.alias('data'),
 
   isGreen: function () {
     return !Em.isNone(this.get('data'));
@@ -64,65 +64,27 @@ App.UptimeTextDashboardWidgetView = 
App.TextDashboardWidgetView.extend({
    */
   didInsertElement: function () {
     this._super();
-    this.addObserver('model.' + this.get('modelField'), this, this.calc);
+    this.calculate();
+    this.addObserver('model.' + this.get('modelField'), this, this.calculate);
   },
 
-  calc: function () {
-    // don't do this.setProperties!
-    this.set('data', this.calcData());
-    this.set('content', this.calcContent());
-  },
+  calculate: function () {
+    const uptime = this.get('model').get(this.get('modelField'));
+    if (uptime) {
+      let diff = App.dateTimeWithTimeZone() - App.dateTimeWithTimeZone(uptime);
+      diff = diff < 0 ? 0 : diff;
+      const formatted = date.timingFormat(diff);
+      const uptimeString = this.timeConverter(uptime);
 
-  uptimeProcessing: function (uptime) {
-    var uptimeString = this.timeConverter(uptime);
-    var diff = App.dateTimeWithTimeZone() - uptime;
-    if (diff < 0) {
-      diff = 0;
-    }
-    var formatted = date.timingFormat(diff); //17.67 days
-    var timeUnit = null;
-    if (formatted) {
-      switch (formatted.split(" ")[1]) {
-        case 'secs':
-          timeUnit = 's';
-          break;
-        case 'hours':
-          timeUnit = 'hr';
-          break;
-        case 'days':
-          timeUnit = 'd';
-          break;
-        case 'mins':
-          timeUnit = 'min';
-          break;
-        default:
-          timeUnit = formatted.split(" ")[1];
-      }
       this.setProperties({
-        timeUnit: timeUnit,
+        data: formatted,
         hiddenInfo: [formatted, uptimeString[0], uptimeString[1]]
       });
+    } else {
+      this.setProperties({
+        data: null,
+        hiddenInfo: [this.get('component'), 
Em.I18n.t('services.service.summary.notRunning')]
+      });
     }
-    return formatted;
-  },
-
-  calcData: function () {
-    var field = this.get('modelField');
-    var uptime = this.get('model').get(field);
-    if (uptime) {
-      var formatted = this.uptimeProcessing(App.dateTimeWithTimeZone(uptime));
-      if (!Em.isNone(formatted)) {
-        return parseFloat(formatted.split(" ")[0]);
-      }
-    }
-    this.set('hiddenInfo', [this.get('component'), 'Not Running']);
-    return null;
-  },
-
-  calcContent: function () {
-    var data = this.get('data');
-    return data ?
-      data.toFixed(1) + ' ' + this.get('timeUnit') :
-      Em.I18n.t('services.service.summary.notAvailable');
   }
 });
diff --git 
a/ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_test.js
 
b/ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_test.js
index 660e767..0375a53 100644
--- 
a/ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_test.js
+++ 
b/ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_test.js
@@ -155,10 +155,10 @@ describe('MainChartHeatmapMetric', function () {
         
expect(mainChartHeatmapMetric.formatLegendNumber.getCall(1).args).to.eql([1]);
       });
       it('timingFormat 1st call with valid arguments', function () {
-        expect(date.timingFormat.getCall(0).args).to.eql(['val', 'zeroValid']);
+        expect(date.timingFormat.getCall(0).args).to.eql(['val']);
       });
       it('timingFormat 2nd call with valid arguments', function () {
-        expect(date.timingFormat.getCall(1).args).to.eql(['val', 'zeroValid']);
+        expect(date.timingFormat.getCall(1).args).to.eql(['val']);
       });
 
     });
diff --git 
a/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
 
b/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
index 19d0a49..db3151e 100644
--- 
a/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
+++ 
b/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
@@ -199,10 +199,9 @@ describe('App.ManageConfigGroupsController', function() {
     var service = Em.Object.create({});
     manageConfigGroupsController.set('hostsModifiedConfigGroups', {});
     describe("#controller passed", function () {
-      controller = Em.Object.create({
+      var popup = 
manageConfigGroupsController.manageConfigurationGroups(Em.Object.create({
         content: Em.Object.create()
-      });
-      var popup = 
manageConfigGroupsController.manageConfigurationGroups(controller, service);
+      }), service);
 
       describe("#onPrimary()", function () {
         beforeEach(function () {
diff --git a/ambari-web/test/mappers/service_mapper_test.js 
b/ambari-web/test/mappers/service_mapper_test.js
index 4a8d49d..2b5e7d1 100644
--- a/ambari-web/test/mappers/service_mapper_test.js
+++ b/ambari-web/test/mappers/service_mapper_test.js
@@ -21,6 +21,7 @@ var App = require('app');
 require('utils/helper');
 require('mappers/server_data_mapper');
 require('mappers/service_metrics_mapper');
+var dateUtils = require('utils/date/date');
 
 describe('App.serviceMetricsMapper', function () {
 
@@ -220,7 +221,7 @@ describe('App.serviceMetricsMapper', function () {
         message: 'Storm mapper, stack version 2.1',
         expectedValues: {
           total_executors: 2,
-          nimbus_uptime: "3.96 hours",
+          nimbus_uptime: 14250000,
           free_slots: 2,
           used_slots: 0,
           total_slots: 2,
@@ -256,10 +257,12 @@ describe('App.serviceMetricsMapper', function () {
 
     beforeEach(function () {
       this.stub = sinon.stub(App, 'get');
+      sinon.stub(dateUtils, 'timingFormat', function(arg) {return arg;});
     });
 
     afterEach(function () {
       App.get.restore();
+      dateUtils.timingFormat.restore();
     });
 
     tests.forEach(function(test) {
diff --git a/ambari-web/test/utils/date/date_test.js 
b/ambari-web/test/utils/date/date_test.js
index 5289fdd..1168f3b 100644
--- a/ambari-web/test/utils/date/date_test.js
+++ b/ambari-web/test/utils/date/date_test.js
@@ -87,38 +87,30 @@ describe('date', function () {
 
   describe('#timingFormat', function() {
     var tests = Em.A([
-      {i: '30', e:'30 ms'},
-      {i: '300', e:'300 ms'},
-      {i: '999', e:'999 ms'},
-      {i: '1000', e:'1.00 secs'},
-      {i: '3000', e:'3.00 secs'},
-      {i: '35000', e:'35.00 secs'},
-      {i: '350000', e:'350.00 secs'},
-      {i: '999999', e:'1000.00 secs'},
-      {i: '1000000', e:'16.67 mins'},
-      {i: '3500000', e:'58.33 mins'},
-      {i: '35000000', e:'9.72 hours'},
-      {i: '350000000', e:'4.05 days'},
-      {i: '3500000000', e:'40.51 days'},
-      {i: '35000000000', e:'405.09 days'}
+      {i: '0', e:'0s'},
+      {i: '1', e:'1ms'},
+      {i: '999', e:'999ms'},
+      {i: '1000', e:'1s'},
+      {i: '59999', e:'59s 999ms'},
+      {i: '60000', e:'1m'},
+      {i: '61001', e:'1m 1s'},
+      {i: '3599999', e:'59m 59s'},
+      {i: '3600000', e:'1h'},
+      {i: '86399999', e:'23h 59m 59s'},
+      {i: '86400000', e:'1d'},
+      {i: '86494321', e:'1d 1m'},
+      {i: '96494321', e:'1d 2h 48m'}
     ]);
 
-    describe('Correct data', function(){
-      tests.forEach(function(test) {
-        it(test.i, function() {
-          expect(date.timingFormat(test.i)).to.equal(test.e);
-        });
-      });
+    it('Corrupted data', function() {
+      expect(date.timingFormat(null)).to.be.null;
     });
 
-    describe('Incorrect data', function(){
-      incorrectTests.forEach(function(test) {
-        it(test.m, function() {
-          expect(date.timingFormat(test.t)).to.equal(null);
-        });
+    tests.forEach(function(test) {
+      it(test.i, function() {
+        expect(date.timingFormat(test.i)).to.equal(test.e);
       });
     });
-
   });
 
   describe('#duration', function() {
@@ -148,12 +140,12 @@ describe('date', function () {
       {
         startTimestamp: 1349752195000,
         endTimestamp: 1349752199000,
-        e: '4.00 secs'
+        e: '4s'
       },
       {
         startTimestamp: 1349752195000,
         endTimestamp: 1367752195000,
-        e: '208.33 days'
+        e: '208d 8h'
       },
       {
         startTimestamp: -10000000,
@@ -164,13 +156,13 @@ describe('date', function () {
         startTimestamp: 1349752195000,
         endTimestamp: -1,
         stubbed: true,
-        e: '0 secs'
+        e: '0s'
       },
       {
         startTimestamp: 100000000,
         endTimestamp: -1,
         stubbed: true,
-        e: '19.00 secs'
+        e: '19s'
       }
     ];
 
diff --git a/ambari-web/test/views/common/host_progress_popup_body_view_test.js 
b/ambari-web/test/views/common/host_progress_popup_body_view_test.js
index 19af580..1e89378 100644
--- a/ambari-web/test/views/common/host_progress_popup_body_view_test.js
+++ b/ambari-web/test/views/common/host_progress_popup_body_view_test.js
@@ -22,26 +22,27 @@ require("utils/host_progress_popup");
 require("views/common/modal_popup");
 
 describe('App.HostProgressPopupBodyView', function () {
-  var view;
+  var view, controller;
 
   beforeEach(function () {
+    controller = Em.Object.create({
+      setSelectCount: Em.K,
+      dataSourceController: Em.Object.create({
+        levelInfo: {},
+        requestMostRecent: Em.K
+      }),
+      refreshRequestScheduleInfo: Em.K,
+      setBackgroundOperationHeader: Em.K,
+      onHostUpdate: Em.K,
+      hosts: [],
+      breadcrumbs: null,
+      rootBreadcrumb: { label: "rootBreadcrumb" },
+      serviceName: "serviceName",
+      currentHostName: "currentHostName"
+    });
     view = App.HostProgressPopupBodyView.create({
       updateSelectView: sinon.spy(),
-      controller: Em.Object.create({
-        setSelectCount: Em.K,
-        dataSourceController: Em.Object.create({
-          levelInfo: {},
-          requestMostRecent: Em.K
-        }),
-        refreshRequestScheduleInfo: Em.K,
-        setBackgroundOperationHeader: Em.K,
-        onHostUpdate: Em.K,
-        hosts: [],
-        breadcrumbs: null,
-        rootBreadcrumb: { label: "rootBreadcrumb" },
-        serviceName: "serviceName",
-        currentHostName: "currentHostName"
-      }),
+      controller: controller,
       parentView: App.HostPopup.initPopup("serviceName", controller, false, 1)
     });
   });
diff --git 
a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_history_view_test.js 
b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_history_view_test.js
index 7fd7130..65d5f49 100644
--- 
a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_history_view_test.js
+++ 
b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_history_view_test.js
@@ -205,7 +205,7 @@ describe('App.MainAdminStackUpgradeHistoryView', function 
() {
         services: [],
         directionLabel: Em.I18n.t('common.upgrade'),
         upgradeTypeLabel: Em.I18n.t('common.rolling'),
-        duration: '1.00 hours'
+        duration: '1h'
       }),
       Em.Object.create({
         idHref: '#2',
@@ -215,7 +215,7 @@ describe('App.MainAdminStackUpgradeHistoryView', function 
() {
         services: [],
         directionLabel: Em.I18n.t('common.downgrade'),
         upgradeTypeLabel: Em.I18n.t('common.hostOrdered'),
-        duration: '2.00 hours'
+        duration: '2h'
       })
     ];
 
diff --git 
a/ambari-web/test/views/main/dashboard/widgets/hbase_master_uptime_test.js 
b/ambari-web/test/views/main/dashboard/widgets/hbase_master_uptime_test.js
deleted file mode 100644
index 4f19a35..0000000
--- a/ambari-web/test/views/main/dashboard/widgets/hbase_master_uptime_test.js
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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 App = require('app');
-
-require('messages');
-require('views/main/dashboard/widgets/hbase_master_uptime');
-require('views/main/dashboard/widgets/text_widget');
-require('views/main/dashboard/widget');
-
-describe('App.HBaseMasterUptimeView', function () {
-
-  var tests = [
-    {
-      model: Em.Object.create({
-        masterStartTime: new Date().getTime() - 192.1 * 24 * 3600 * 1000
-      }),
-      e: {
-        isGreen: true,
-        isNA: false,
-        content: '192.1 d',
-        data: 192.1
-      }
-    },
-    {
-      model: Em.Object.create({
-        masterStartTime: 0
-      }),
-      e: {
-        isGreen: false,
-        isNA: true,
-        content: Em.I18n.t('services.service.summary.notAvailable'),
-        data: null
-      }
-    },
-    {
-      model: Em.Object.create({
-        masterStartTime: null
-      }),
-      e: {
-        isGreen: false,
-        isNA: true,
-        content: Em.I18n.t('services.service.summary.notAvailable'),
-        data: null
-      }
-    }
-  ];
-
-  beforeEach(function () {
-    sinon.stub(App.router, 
'get').withArgs('userSettingsController.userSettings.timezone').returns('');
-  });
-
-  afterEach(function () {
-    App.router.get.restore();
-  });
-
-  tests.forEach(function (test) {
-    var hBaseMasterUptimeView = App.HBaseMasterUptimeView.create({model_type: 
null, model: test.model});
-    hBaseMasterUptimeView.calc();
-    describe('#masterStartTime - ' + test.model.masterStartTime, function () {
-      it('content', function () {
-        expect(hBaseMasterUptimeView.get('content')).to.equal(test.e.content);
-      });
-      it('data', function () {
-        expect(hBaseMasterUptimeView.get('data')).to.equal(test.e.data);
-      });
-      it('isGreen', function () {
-        expect(hBaseMasterUptimeView.get('isGreen')).to.equal(test.e.isGreen);
-      });
-      it('isNA', function () {
-        expect(hBaseMasterUptimeView.get('isNA')).to.equal(test.e.isNA);
-      });
-    });
-  });
-
-});
diff --git 
a/ambari-web/test/views/main/dashboard/widgets/namenode_uptime_test.js 
b/ambari-web/test/views/main/dashboard/widgets/namenode_uptime_test.js
deleted file mode 100644
index bfd101c..0000000
--- a/ambari-web/test/views/main/dashboard/widgets/namenode_uptime_test.js
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * 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 App = require('app');
-
-require('messages');
-require('views/main/dashboard/widgets/namenode_uptime');
-require('views/main/dashboard/widgets/text_widget');
-require('views/main/dashboard/widget');
-
-describe('App.NameNodeUptimeView', function() {
-
-  var tests = [
-    {
-      model: Em.Object.create({
-        nameNodeStartTime: new Date().getTime() - 192.1*24*3600*1000
-      }),
-      e: {
-        isRed: false,
-        isOrange: false,
-        isGreen: true,
-        isNA: false,
-        content: '192.1 d',
-        data: 192.1
-      }
-    },
-    {
-      model:  Em.Object.create({
-        nameNodeStartTime: 0
-      }),
-      e: {
-        isRed: false,
-        isOrange: false,
-        isGreen: false,
-        isNA: true,
-        content: Em.I18n.t('services.service.summary.notAvailable'),
-        data: null
-      }
-    },
-    {
-      model:  Em.Object.create({
-        nameNodeStartTime: null
-      }),
-      e: {
-        isRed: false,
-        isOrange: false,
-        isGreen: false,
-        isNA: true,
-        content: Em.I18n.t('services.service.summary.notAvailable'),
-        data: null
-      }
-    }
-  ];
-
-  tests.forEach(function(test) {
-    var nameNodeUptimeView = App.NameNodeUptimeView.create({model_type:null, 
model: test.model});
-    nameNodeUptimeView.calc();
-    describe('nameNodeStartTime - ' + test.model.nameNodeStartTime, function() 
{
-      it('content', function() {
-        expect(nameNodeUptimeView.get('content')).to.equal(test.e.content);
-      });
-      it('data', function() {
-        expect(nameNodeUptimeView.get('data')).to.equal(test.e.data);
-      });
-      it('isRed', function() {
-        expect(nameNodeUptimeView.get('isRed')).to.equal(test.e.isRed);
-      });
-      it('isOrange', function() {
-        expect(nameNodeUptimeView.get('isOrange')).to.equal(test.e.isOrange);
-      });
-      it('isGreen', function() {
-        expect(nameNodeUptimeView.get('isGreen')).to.equal(test.e.isGreen);
-      });
-      it('isNA', function() {
-        expect(nameNodeUptimeView.get('isNA')).to.equal(test.e.isNA);
-      });
-    });
-  });
-
-});
diff --git 
a/ambari-web/test/views/main/dashboard/widgets/resource_manager_uptime_test.js 
b/ambari-web/test/views/main/dashboard/widgets/resource_manager_uptime_test.js
deleted file mode 100644
index d4a9b34..0000000
--- 
a/ambari-web/test/views/main/dashboard/widgets/resource_manager_uptime_test.js
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * 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 App = require('app');
-
-require('messages');
-require('views/main/dashboard/widget');
-require('views/main/dashboard/widgets/text_widget');
-require('views/main/dashboard/widgets/resource_manager_uptime');
-
-describe('App.ResourceManagerUptimeView', function() {
-
-  var tests = [
-    {
-      model: Em.Object.create({
-        resourceManagerStartTime: (new Date()).getTime() - 192.1*24*3600*1000
-      }),
-      e: {
-        isGreen: true,
-        isNA: false,
-        content: '192.1 d',
-        data: 192.1
-      }
-    },
-    {
-      model:  Em.Object.create({
-        resourceManagerStartTime: 0
-      }),
-      e: {
-        isGreen: false,
-        isNA: true,
-        content: Em.I18n.t('services.service.summary.notAvailable'),
-        data: null
-      }
-    },
-    {
-      model:  Em.Object.create({
-        resourceManagerStartTime: null
-      }),
-      e: {
-        isGreen: false,
-        isNA: true,
-        content: Em.I18n.t('services.service.summary.notAvailable'),
-        data: null
-      }
-    }
-  ];
-
-  tests.forEach(function(test) {
-    var resourceManagerUptimeView = 
App.ResourceManagerUptimeView.create({model_type:null, model: test.model});
-    resourceManagerUptimeView.calc();
-    describe('resourceManagerStartTime - ' + 
test.model.resourceManagerStartTime, function() {
-      it('content', function() {
-        
expect(resourceManagerUptimeView.get('content')).to.equal(test.e.content);
-      });
-      it('data', function() {
-        expect(resourceManagerUptimeView.get('data')).to.equal(test.e.data);
-      });
-      it('isGreen', function() {
-        
expect(resourceManagerUptimeView.get('isGreen')).to.equal(test.e.isGreen);
-      });
-      it('isNA', function() {
-        expect(resourceManagerUptimeView.get('isNA')).to.equal(test.e.isNA);
-      });
-    });
-  });
-
-});
diff --git 
a/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js 
b/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js
index fa20593..2c7f540 100644
--- a/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js
+++ b/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js
@@ -21,11 +21,17 @@ require('views/main/dashboard/widget');
 require('views/main/dashboard/widgets/text_widget');
 require('views/main/dashboard/widgets/uptime_text_widget');
 
+var date = require('utils/date/date');
 var uptimeTextDashboardWidgetView;
 describe('App.UptimeTextDashboardWidgetView', function() {
 
   beforeEach(function () {
-    uptimeTextDashboardWidgetView = 
App.UptimeTextDashboardWidgetView.create({thresholdMin:40, thresholdMax:70});
+    uptimeTextDashboardWidgetView = App.UptimeTextDashboardWidgetView.create({
+      thresholdMin:40,
+      thresholdMax:70,
+      modelField: 'field',
+      model: Em.Object.create({})
+    });
   });
 
   describe('#timeConverter', function() {
@@ -55,38 +61,36 @@ describe('App.UptimeTextDashboardWidgetView', function() {
     });
   });
 
-  describe('#uptimeProcessing', function() {
-    var timestamps = [
-      {
-        diff: 10*1000,
-        e: {
-          timeUnit: 's'
-        }
-      },
-      {
-        diff: 3600*1000,
-        e: {
-          timeUnit: 'hr'
-        }
-      },
-      {
-        diff: 24*3600*1000,
-        e: {
-          timeUnit: 'd'
-        }
-      },
-      {
-        diff: 1800*1000,
-        e: {
-          timeUnit: 'min'
-        }
-      }
-    ];
-    timestamps.forEach(function(timestamp) {
-      it('timestamp {0}. timeUnit should be "{1}"'.format(timestamp.t, 
timestamp.e.timeUnit), function() {
-        uptimeTextDashboardWidgetView.uptimeProcessing(new Date().getTime() - 
timestamp.diff);
-        
expect(uptimeTextDashboardWidgetView.get('timeUnit')).to.equal(timestamp.e.timeUnit);
-      });
+  describe('#calculate', function() {
+    beforeEach(function() {
+      sinon.stub(App, 'dateTimeWithTimeZone', function(arg) {return arg ? arg 
: 100000});
+      sinon.stub(date, 'timingFormat', function(arg) {return String(arg);});
+      sinon.stub(uptimeTextDashboardWidgetView, 'timeConverter').returns([1, 
2]);
+    });
+    afterEach(function() {
+      App.dateTimeWithTimeZone.restore();
+      date.timingFormat.restore();
+      uptimeTextDashboardWidgetView.timeConverter.restore();
+    });
+
+    it("should be 'n/a' when uptime is null", function() {
+      uptimeTextDashboardWidgetView.get('model').set('field', null);
+
+      uptimeTextDashboardWidgetView.calculate();
+
+      expect(uptimeTextDashboardWidgetView.get('data')).to.be.null;
+      expect(uptimeTextDashboardWidgetView.get('hiddenInfo')).to.be.eql([
+        null, Em.I18n.t('services.service.summary.notRunning')
+      ]);
+    });
+
+    it("should display formatted duration when uptime is number", function() {
+      uptimeTextDashboardWidgetView.get('model').set('field', 10000);
+
+      uptimeTextDashboardWidgetView.calculate();
+
+      expect(uptimeTextDashboardWidgetView.get('data')).to.be.equal('90000');
+      
expect(uptimeTextDashboardWidgetView.get('hiddenInfo')).to.be.eql(['90000', 1, 
2]);
     });
   });
 

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to