You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2015/10/19 15:54:06 UTC

[20/50] [abbrv] ambari git commit: AMBARI-13448. CSV export: downloaded data does not reflect what's shown in the chart

AMBARI-13448. CSV export: downloaded data does not reflect what's shown in the chart


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 4a954283e96a1e598e436b9c264939398793c59d
Parents: a509510
Author: Alex Antonenko <hi...@gmail.com>
Authored: Fri Oct 16 13:08:00 2015 +0300
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Fri Oct 16 13:38:21 2015 +0300

----------------------------------------------------------------------
 .../views/common/widget/graph_widget_view.js    |   2 +-
 .../common/widget/graph_widget_view_test.js     | 112 +++++++++++++++++++
 2 files changed, 113 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4a954283/ambari-web/app/views/common/widget/graph_widget_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/widget/graph_widget_view.js b/ambari-web/app/views/common/widget/graph_widget_view.js
index fb8e754..1ed20d2 100644
--- a/ambari-web/app/views/common/widget/graph_widget_view.js
+++ b/ambari-web/app/views/common/widget/graph_widget_view.js
@@ -313,7 +313,7 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, App.ExportMetricsMixin, {
       isCSV = !!event.context,
       fileType = isCSV ? 'csv' : 'json',
       fileName = 'data.' + fileType,
-      metrics = this.get('content.metrics'),
+      metrics = this.get('data'),
       hasData = Em.isArray(metrics) && metrics.some(function (item) {
         return Em.isArray(item.data);
       });

http://git-wip-us.apache.org/repos/asf/ambari/blob/4a954283/ambari-web/test/views/common/widget/graph_widget_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/widget/graph_widget_view_test.js b/ambari-web/test/views/common/widget/graph_widget_view_test.js
index deccce5..7215128 100644
--- a/ambari-web/test/views/common/widget/graph_widget_view_test.js
+++ b/ambari-web/test/views/common/widget/graph_widget_view_test.js
@@ -18,6 +18,7 @@
 
 var App = require('app');
 require('views/common/widget/graph_widget_view');
+var fileUtils = require('utils/file_utils');
 
 describe('App.GraphWidgetView', function () {
   var view = App.GraphWidgetView.create();
@@ -126,4 +127,115 @@ describe('App.GraphWidgetView', function () {
     });
   });
 
+  describe('#exportGraphData', function () {
+
+    var cases = [
+      {
+        data: null,
+        prepareCSVCallCount: 0,
+        prepareJSONCallCount: 0,
+        downloadTextFileCallCount: 0,
+        showAlertPopupCallCount: 1,
+        title: 'no data'
+      },
+      {
+        data: {},
+        prepareCSVCallCount: 0,
+        prepareJSONCallCount: 0,
+        downloadTextFileCallCount: 0,
+        showAlertPopupCallCount: 1,
+        title: 'invalid data'
+      },
+      {
+        data: [
+          {
+            data: null
+          }
+        ],
+        prepareCSVCallCount: 0,
+        prepareJSONCallCount: 0,
+        downloadTextFileCallCount: 0,
+        showAlertPopupCallCount: 1,
+        title: 'empty data'
+      },
+      {
+        data: [
+          {
+            data: {}
+          }
+        ],
+        prepareCSVCallCount: 0,
+        prepareJSONCallCount: 0,
+        downloadTextFileCallCount: 0,
+        showAlertPopupCallCount: 1,
+        title: 'malformed data'
+      },
+      {
+        data: [
+          {
+            data: [
+              {
+                key: 'value'
+              }
+            ]
+          }
+        ],
+        prepareCSVCallCount: 0,
+        prepareJSONCallCount: 1,
+        downloadTextFileCallCount: 1,
+        showAlertPopupCallCount: 0,
+        title: 'JSON export'
+      },
+      {
+        data: [
+          {
+            data: [
+              {
+                key: 'value'
+              }
+            ]
+          }
+        ],
+        event: {
+          context: true
+        },
+        prepareCSVCallCount: 1,
+        prepareJSONCallCount: 0,
+        downloadTextFileCallCount: 1,
+        showAlertPopupCallCount: 0,
+        title: 'CSV export'
+      }
+    ];
+
+    beforeEach(function () {
+      sinon.stub(view, 'prepareCSV').returns([]);
+      sinon.stub(view, 'prepareJSON').returns([]);
+      sinon.stub(fileUtils, 'downloadTextFile', Em.K);
+      sinon.stub(App, 'showAlertPopup', Em.K);
+    });
+
+    afterEach(function () {
+      view.prepareCSV.restore();
+      view.prepareJSON.restore();
+      fileUtils.downloadTextFile.restore();
+      App.showAlertPopup.restore();
+    });
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        view.set('data', item.data);
+        view.exportGraphData(item.event || {});
+        expect(view.prepareCSV.callCount).to.equal(item.prepareCSVCallCount);
+        expect(view.prepareJSON.callCount).to.equal(item.prepareJSONCallCount);
+        expect(fileUtils.downloadTextFile.callCount).to.equal(item.downloadTextFileCallCount);
+        expect(App.showAlertPopup.callCount).to.equal(item.showAlertPopupCallCount);
+        if (item.downloadTextFileCallCount) {
+          var fileType = item.event && item.event.context ? 'csv' : 'json';
+          expect(fileUtils.downloadTextFile.calledWith([], fileType, 'data.' + fileType)).to.be.true;
+        }
+      });
+    });
+
+  });
+
 });
\ No newline at end of file