AMBARI-17918. Incorrect enhanced metrics graphs behaviour after switching to time range with no data (alexantonenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/fb1001ba Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/fb1001ba Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/fb1001ba Branch: refs/heads/branch-2.4 Commit: fb1001ba4228ee6f15bf4c0c641bae2f8184be00 Parents: bc5bbd7 Author: Alex Antonenko <[email protected]> Authored: Wed Jul 27 15:24:44 2016 +0300 Committer: Alex Antonenko <[email protected]> Committed: Wed Jul 27 16:00:46 2016 +0300 ---------------------------------------------------------------------- .../app/mixins/common/widgets/widget_mixin.js | 6 +- .../test/mixins/common/widget_mixin_test.js | 102 +++++++++++++------ 2 files changed, 76 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/fb1001ba/ambari-web/app/mixins/common/widgets/widget_mixin.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins/common/widgets/widget_mixin.js b/ambari-web/app/mixins/common/widgets/widget_mixin.js index 0ff7f29..5ec4dd6 100644 --- a/ambari-web/app/mixins/common/widgets/widget_mixin.js +++ b/ambari-web/app/mixins/common/widgets/widget_mixin.js @@ -334,11 +334,11 @@ App.WidgetMixin = Ember.Mixin.create({ graph.set('hasData', false); this.set('isExportButtonHidden', true); graph._showMessage('info', this.t('graphs.noData.title'), this.t('graphs.noDataAtTime.message')); - this.set('metrics', this.get('metrics').reject(function (item) { - return this.get('content.metrics').someProperty('name', item.name); - }, this)); } } + this.set('metrics', this.get('metrics').reject(function (item) { + return this.get('content.metrics').someProperty('name', item.name); + }, this)); }, /** http://git-wip-us.apache.org/repos/asf/ambari/blob/fb1001ba/ambari-web/test/mixins/common/widget_mixin_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/mixins/common/widget_mixin_test.js b/ambari-web/test/mixins/common/widget_mixin_test.js index b56863c..fe972f9 100644 --- a/ambari-web/test/mixins/common/widget_mixin_test.js +++ b/ambari-web/test/mixins/common/widget_mixin_test.js @@ -245,42 +245,86 @@ describe('App.WidgetMixin', function () { describe("#disableGraph", function () { var graph = Em.Object.create({ + hasData: true, _showMessage: Em.K - }); - - beforeEach(function() { - mixinObject.setProperties({ - childViews: [ - graph - ], - graphView: {}, - metrics: [{name: 'm1'}, {name: 'm2'}], - content: { - metrics: [{name: 'm2'}] + }), + cases = [ + { + graphView: null, + childViews: [], + hasData: true, + isExportButtonHidden: false, + showMessageCallCount: 0, + title: 'no graph' + }, + { + graphView: {}, + childViews: [{}], + hasData: true, + isExportButtonHidden: false, + showMessageCallCount: 0, + title: 'no graph view rendered' + }, + { + graphView: {}, + childViews: [ + {}, + graph + ], + hasData: false, + isExportButtonHidden: true, + showMessageCallCount: 1, + title: 'graph view rendered' } - }); - sinon.stub(graph, '_showMessage'); - mixinObject.disableGraph(); - }); + ]; - afterEach(function() { - graph._showMessage.restore(); - }); + cases.forEach(function (item) { + describe(item.title, function () { + beforeEach(function() { + mixinObject.setProperties({ + isExportButtonHidden: false, + childViews: item.childViews, + graphView: item.graphView, + metrics: [ + { + name: 'm1' + }, + { + name: 'm2' + } + ], + content: { + metrics: [ + { + name: 'm2' + } + ] + } + }); + sinon.stub(graph, '_showMessage'); + mixinObject.disableGraph(); + }); - it("hasData should be false", function() { - expect(graph.get('hasData')).to.be.false; - }); + afterEach(function() { + graph._showMessage.restore(); + }); - it("isExportButtonHidden should be true", function() { - expect(mixinObject.get('isExportButtonHidden')).to.be.true; - }); + it('hasData', function() { + expect(graph.get('hasData')).to.equal(item.hasData); + }); - it("_showMessage should be called", function() { - expect(graph._showMessage.calledWith('info', mixinObject.t('graphs.noData.title'), mixinObject.t('graphs.noDataAtTime.message'))).to.be.true; - }); + it('isExportButtonHidden', function() { + expect(mixinObject.get('isExportButtonHidden')).to.equal(item.isExportButtonHidden); + }); + + it('_showMessage call count', function() { + expect(graph._showMessage.callCount).to.equal(item.showMessageCallCount); + }); - it("metrics should be filtered", function() { - expect(mixinObject.get('metrics').mapProperty('name')).to.be.eql(['m1']); + it('metrics should be filtered', function() { + expect(mixinObject.get('metrics').mapProperty('name')).to.eql(['m1']); + }); + }); }); });
