Repository: ambari Updated Branches: refs/heads/trunk 7eb2eaa73 -> 9348725b1
http://git-wip-us.apache.org/repos/asf/ambari/blob/9348725b/ambari-web/test/views/main/dashboard/widget_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widget_test.js b/ambari-web/test/views/main/dashboard/widget_test.js index 0544ff6..63da712 100644 --- a/ambari-web/test/views/main/dashboard/widget_test.js +++ b/ambari-web/test/views/main/dashboard/widget_test.js @@ -21,178 +21,84 @@ require('views/main/dashboard/widget'); describe('App.DashboardWidgetView', function () { - var dashboardWidgetView = App.DashboardWidgetView.create({ + var dashboardWidgetView; + + dashboardWidgetView = App.DashboardWidgetView.create({ parentView: Em.Object.create({ widgetsMapper: Em.K, - getUserPref: function () {return {complete: Em.K}}, + getUserPref: function () { + return {complete: Em.K} + }, postUserPref: Em.K, translateToReal: Em.K, visibleWidgets: [], hiddenWidgets: [] + }), + widget: Em.Object.create({ + id: 5, + sourceName: 'HDFS', + title: 'Widget' }) }); describe('#viewID', function () { it('viewID is computed with id', function () { - dashboardWidgetView.set('id', 5); expect(dashboardWidgetView.get('viewID')).to.equal('widget-5'); }); }); describe('#model', function () { - it('model_type is null', function () { - dashboardWidgetView.set('model_type', null); + + beforeEach(function() { + sinon.stub(dashboardWidgetView, 'findModelBySource').returns(Em.Object.create({serviceName: 'HDFS'})); + }); + + afterEach(function() { + dashboardWidgetView.findModelBySource.restore(); + }); + + it('sourceName is null', function () { + dashboardWidgetView.set('widget.sourceName', null); dashboardWidgetView.propertyDidChange('model'); - expect(dashboardWidgetView.get('model')).to.eql({}); + expect(dashboardWidgetView.get('model')).to.be.an.object; }); - it('model_type is valid', function () { - dashboardWidgetView.set('model_type', 's'); + it('sourceName is valid', function () { + dashboardWidgetView.set('widget.sourceName', 'HDFS'); dashboardWidgetView.propertyDidChange('model'); - dashboardWidgetView.set('parentView.s_model', {'s': {}}); - expect(dashboardWidgetView.get('model')).to.eql({'s': {}}); + expect(dashboardWidgetView.get('model')).to.eql(Em.Object.create({serviceName: 'HDFS'})); }); }); describe("#didInsertElement()", function () { - before(function () { + + beforeEach(function () { sinon.stub(App, 'tooltip', Em.K); }); - after(function () { + afterEach(function () { App.tooltip.restore(); }); + it("call App.tooltip", function () { dashboardWidgetView.didInsertElement(); expect(App.tooltip.calledOnce).to.be.true; }); }); - describe("#deleteWidget()", function () { - beforeEach(function () { - sinon.stub(dashboardWidgetView.get('parentView'), 'widgetsMapper').returns({}); - sinon.stub(dashboardWidgetView.get('parentView'), 'getUserPref').returns({ - complete: Em.K - }); - }); - - afterEach(function () { - dashboardWidgetView.get('parentView').widgetsMapper.restore(); - dashboardWidgetView.get('parentView').getUserPref.restore(); - }); - - it("testMode is off", function () { - dashboardWidgetView.set('parentView.persistKey', 'key'); - dashboardWidgetView.deleteWidget(); - expect(dashboardWidgetView.get('parentView').getUserPref.calledWith('key')).to.be.true; - }); - }); + describe("#editWidget()", function () { - describe("#deleteWidgetComplete()", function () { beforeEach(function () { - sinon.spy(dashboardWidgetView.get('parentView'), 'postUserPref'); - sinon.spy(dashboardWidgetView.get('parentView'), 'translateToReal'); - dashboardWidgetView.set('parentView.currentPrefObject', { - dashboardVersion: 'new', - visible: ['1', '2'], - hidden: [], - threshold: 'threshold' - }); - dashboardWidgetView.set('parentView.persistKey', 'key'); - dashboardWidgetView.deleteWidgetComplete(); - }); - afterEach(function () { - dashboardWidgetView.get('parentView').postUserPref.restore(); - dashboardWidgetView.get('parentView').translateToReal.restore(); - }); - it("postUserPref is called with correct data", function () { - var arg = JSON.parse(JSON.stringify(dashboardWidgetView.get('parentView').postUserPref.args[0][1])); - expect(arg).to.be.eql({ - dashboardVersion: 'new', - visible: ['1', '2'], - hidden: [[5, null]], - threshold: 'threshold' - }); - }); - it("translateToReal is called with valid data", function () { - var arg = JSON.parse(JSON.stringify(dashboardWidgetView.get('parentView').translateToReal.args[0][0])); - expect(arg).to.be.eql({ - dashboardVersion: 'new', - visible: ['1', '2'], - hidden: [[5, null]], - threshold: 'threshold' - }); - }); - }); - - describe("#editWidget()", function () { - before(function () { sinon.stub(dashboardWidgetView, 'showEditDialog', Em.K); }); - after(function () { + afterEach(function () { dashboardWidgetView.showEditDialog.restore(); }); + it("call showEditDialog", function () { dashboardWidgetView.editWidget(); expect(dashboardWidgetView.showEditDialog.calledOnce).to.be.true; }); }); - describe("#showEditDialog()", function () { - var obj = Em.Object.create({ - observeThresh1Value: Em.K, - observeThresh2Value: Em.K, - thresh1: '1', - thresh2: '2' - }); - beforeEach(function () { - sinon.spy(obj, 'observeThresh1Value'); - sinon.spy(obj, 'observeThresh2Value'); - sinon.stub(dashboardWidgetView.get('parentView'), 'getUserPref').returns({ - complete: Em.K - }); - var popup = dashboardWidgetView.showEditDialog(obj); - popup.onPrimary(); - }); - afterEach(function () { - obj.observeThresh1Value.restore(); - obj.observeThresh2Value.restore(); - dashboardWidgetView.get('parentView').getUserPref.restore(); - }); - - it("observeThresh1Value is called once", function () { - expect(obj.observeThresh1Value.calledOnce).to.be.true; - }); - - it("observeThresh2Value is called once", function () { - expect(obj.observeThresh2Value.calledOnce).to.be.true; - }); - - it("thresh1 = 1", function () { - expect(dashboardWidgetView.get('thresh1')).to.equal(1); - }); - - it("thresh2 = 2", function () { - expect(dashboardWidgetView.get('thresh2')).to.equal(2); - }); - - it("getUserPref is called once", function () { - expect(dashboardWidgetView.get('parentView').getUserPref.calledOnce).to.be.true; - }); - }); - - describe('#model', function () { - it('model_type is null', function () { - dashboardWidgetView.set('model_type', null); - dashboardWidgetView.propertyDidChange('model'); - expect(dashboardWidgetView.get('model')).to.eql({}); - }); - it('model_type is valid', function () { - dashboardWidgetView.set('model_type', 's'); - dashboardWidgetView.propertyDidChange('model'); - dashboardWidgetView.set('parentView.s_model', {'s': {}}); - expect(dashboardWidgetView.get('model')).to.eql({'s': {}}); - }); - }); - describe('#hoverContentTopClass', function () { var tests = [ { @@ -258,7 +164,7 @@ describe('App.DashboardWidgetView', function () { var testCases = [ { data: { - thresh1: '', + thresholdMin: '', maxValue: 0 }, result: { @@ -268,7 +174,7 @@ describe('App.DashboardWidgetView', function () { }, { data: { - thresh1: 'NaN', + thresholdMin: 'NaN', maxValue: 0 }, result: { @@ -278,7 +184,7 @@ describe('App.DashboardWidgetView', function () { }, { data: { - thresh1: '-1', + thresholdMin: '-1', maxValue: 0 }, result: { @@ -288,7 +194,7 @@ describe('App.DashboardWidgetView', function () { }, { data: { - thresh1: '2', + thresholdMin: '2', maxValue: 1 }, result: { @@ -298,8 +204,8 @@ describe('App.DashboardWidgetView', function () { }, { data: { - thresh1: '1', - thresh2: '1', + thresholdMin: '1', + thresholdMax: '1', maxValue: 2 }, result: { @@ -309,8 +215,8 @@ describe('App.DashboardWidgetView', function () { }, { data: { - thresh1: '1', - thresh2: '0', + thresholdMin: '1', + thresholdMax: '0', maxValue: 2 }, result: { @@ -320,8 +226,8 @@ describe('App.DashboardWidgetView', function () { }, { data: { - thresh1: '1', - thresh2: '2', + thresholdMin: '1', + thresholdMax: '2', maxValue: 2 }, result: { @@ -331,12 +237,12 @@ describe('App.DashboardWidgetView', function () { } ]; testCases.forEach(function (test) { - describe("thresh1 - " + test.data.thresh1 + ', maxValue - ' + test.data.maxValue, function () { + describe("thresholdMin - " + test.data.thresholdMin + ', maxValue - ' + test.data.maxValue, function () { beforeEach(function () { widget.set('isThresh2Error', false); - widget.set('thresh2', test.data.thresh2 || ""); - widget.set('thresh1', test.data.thresh1); + widget.set('thresholdMax', test.data.thresholdMax || ""); + widget.set('thresholdMin', test.data.thresholdMin); widget.set('maxValue', test.data.maxValue); widget.observeThresh1Value(); }); @@ -367,7 +273,7 @@ describe('App.DashboardWidgetView', function () { var testCases = [ { data: { - thresh2: '', + thresholdMax: '', maxValue: 0 }, result: { @@ -377,7 +283,7 @@ describe('App.DashboardWidgetView', function () { }, { data: { - thresh2: 'NaN', + thresholdMax: 'NaN', maxValue: 0 }, result: { @@ -387,7 +293,7 @@ describe('App.DashboardWidgetView', function () { }, { data: { - thresh2: '-1', + thresholdMax: '-1', maxValue: 0 }, result: { @@ -397,7 +303,7 @@ describe('App.DashboardWidgetView', function () { }, { data: { - thresh2: '2', + thresholdMax: '2', maxValue: 1 }, result: { @@ -407,7 +313,7 @@ describe('App.DashboardWidgetView', function () { }, { data: { - thresh2: '2', + thresholdMax: '2', maxValue: 2 }, result: { @@ -417,10 +323,10 @@ describe('App.DashboardWidgetView', function () { } ]; testCases.forEach(function (test) { - describe("thresh2 - " + test.data.thresh2 + ', maxValue - ' + test.data.maxValue, function () { + describe("thresholdMax - " + test.data.thresholdMax + ', maxValue - ' + test.data.maxValue, function () { beforeEach(function () { - widget.set('thresh2', test.data.thresh2 || ""); + widget.set('thresholdMax', test.data.thresholdMax || ""); widget.set('maxValue', test.data.maxValue); widget.observeThresh2Value(); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/9348725b/ambari-web/test/views/main/dashboard/widgets/hbase_average_load_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widgets/hbase_average_load_test.js b/ambari-web/test/views/main/dashboard/widgets/hbase_average_load_test.js index e3a08c9..8cb3246 100644 --- a/ambari-web/test/views/main/dashboard/widgets/hbase_average_load_test.js +++ b/ambari-web/test/views/main/dashboard/widgets/hbase_average_load_test.js @@ -82,8 +82,8 @@ describe('App.HBaseAverageLoadView', function() { App.TestAliases.testAsComputedAlias(getView(), 'data', 'model.averageLoad', 'number'); - App.TestAliases.testAsComputedGtProperties(getView(), 'isRed', 'data', 'thresh2'); + App.TestAliases.testAsComputedGtProperties(getView(), 'isRed', 'data', 'thresholdMax'); - App.TestAliases.testAsComputedLteProperties(getView(), 'isGreen', 'data', 'thresh1'); + App.TestAliases.testAsComputedLteProperties(getView(), 'isGreen', 'data', 'thresholdMin'); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/9348725b/ambari-web/test/views/main/dashboard/widgets/hbase_regions_in_transition_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widgets/hbase_regions_in_transition_test.js b/ambari-web/test/views/main/dashboard/widgets/hbase_regions_in_transition_test.js index 8ad1531..4366ab6 100644 --- a/ambari-web/test/views/main/dashboard/widgets/hbase_regions_in_transition_test.js +++ b/ambari-web/test/views/main/dashboard/widgets/hbase_regions_in_transition_test.js @@ -23,7 +23,7 @@ require('views/main/dashboard/widgets/text_widget'); require('views/main/dashboard/widget'); function getView() { - return App.HBaseRegionsInTransitionView.create({model_type:null}); + return App.HBaseRegionsInTransitionView.create({}); } describe('App.HBaseRegionsInTransitionView', function() { @@ -81,9 +81,9 @@ describe('App.HBaseRegionsInTransitionView', function() { App.TestAliases.testAsComputedAlias(getView(), 'data', 'model.regionsInTransition', 'number'); - App.TestAliases.testAsComputedGtProperties(getView(), 'isRed', 'data', 'thresh2'); + App.TestAliases.testAsComputedGtProperties(getView(), 'isRed', 'data', 'thresholdMax'); - App.TestAliases.testAsComputedLteProperties(getView(), 'isGreen', 'data', 'thresh1'); + App.TestAliases.testAsComputedLteProperties(getView(), 'isGreen', 'data', 'thresholdMin'); App.TestAliases.testAsComputedAnd(getView(), 'isOrange', ['!isGreen', '!isRed']); http://git-wip-us.apache.org/repos/asf/ambari/blob/9348725b/ambari-web/test/views/main/dashboard/widgets/namenode_rpc_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widgets/namenode_rpc_test.js b/ambari-web/test/views/main/dashboard/widgets/namenode_rpc_test.js index 474d099..15b7503 100644 --- a/ambari-web/test/views/main/dashboard/widgets/namenode_rpc_test.js +++ b/ambari-web/test/views/main/dashboard/widgets/namenode_rpc_test.js @@ -35,7 +35,6 @@ describe('App.NameNodeRpcView', function() { nameNodeRpc: 1 }, e: { - isOrange: true, isNA: false, content: '1.00 ms', data: '1.00' @@ -46,7 +45,6 @@ describe('App.NameNodeRpcView', function() { nameNodeRpc: 10 }, e: { - isOrange: false, isNA: false, content: '10.00 ms', data: '10.00' @@ -57,7 +55,6 @@ describe('App.NameNodeRpcView', function() { nameNodeRpc: 0 }, e: { - isOrange: false, isNA: false, content: '0 ms', data: 0 @@ -68,7 +65,6 @@ describe('App.NameNodeRpcView', function() { nameNodeRpc: null }, e: { - isOrange: false, isNA: true, content: Em.I18n.t('services.service.summary.notAvailable'), data: null @@ -78,24 +74,21 @@ describe('App.NameNodeRpcView', function() { tests.forEach(function(test) { describe('nameNodeRpc - ' + test.model.nameNodeRpc, function() { - var jobTrackerRpcView = App.NameNodeRpcView.create({model_type:null, model: test.model}); + var jobTrackerRpcView = App.NameNodeRpcView.create({model: test.model}); it('content', function() { expect(jobTrackerRpcView.get('content')).to.equal(test.e.content); }); it('data', function() { expect(jobTrackerRpcView.get('data')).to.equal(test.e.data); }); - it('isOrange', function() { - expect(jobTrackerRpcView.get('isOrange')).to.equal(test.e.isOrange); - }); it('isNA', function() { expect(jobTrackerRpcView.get('isNA')).to.equal(test.e.isNA); }); }); }); - App.TestAliases.testAsComputedGtProperties(getView(), 'isRed', 'data', 'thresh2'); + App.TestAliases.testAsComputedGtProperties(getView(), 'isRed', 'data', 'thresholdMax'); - App.TestAliases.testAsComputedLteProperties(getView(), 'isGreen', 'data', 'thresh1'); + App.TestAliases.testAsComputedLteProperties(getView(), 'isGreen', 'data', 'thresholdMin'); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/9348725b/ambari-web/test/views/main/dashboard/widgets/text_widget_single_threshold_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widgets/text_widget_single_threshold_test.js b/ambari-web/test/views/main/dashboard/widgets/text_widget_single_threshold_test.js index e564922..3136c35 100644 --- a/ambari-web/test/views/main/dashboard/widgets/text_widget_single_threshold_test.js +++ b/ambari-web/test/views/main/dashboard/widgets/text_widget_single_threshold_test.js @@ -22,7 +22,7 @@ require('views/main/dashboard/widget'); require('views/main/dashboard/widgets/text_widget_single_threshold'); function getView() { - return App.TextDashboardSingleThresholdWidgetView.create({thresh1:0}); + return App.TextDashboardSingleThresholdWidgetView.create({thresholdMin:0}); } describe('App.TextDashboardSingleThresholdWidgetView', function() { @@ -43,8 +43,8 @@ describe('App.TextDashboardSingleThresholdWidgetView', function() { ]; tests.forEach(function(test) { - describe('data - ' + test.data + ' | thresh1 - 0', function() { - var textDashboardWidgetSingleThresholdView = App.TextDashboardSingleThresholdWidgetView.create({thresh1:0}); + describe('data - ' + test.data + ' | thresholdMin - 0', function() { + var textDashboardWidgetSingleThresholdView = App.TextDashboardSingleThresholdWidgetView.create({thresholdMin:0}); textDashboardWidgetSingleThresholdView.set('data', test.data); it('isNA', function() { expect(textDashboardWidgetSingleThresholdView.get('isNA')).to.equal(test.e.isNA); @@ -52,6 +52,6 @@ describe('App.TextDashboardSingleThresholdWidgetView', function() { }); }); - App.TestAliases.testAsComputedGtProperties(getView(), 'isRed', 'data', 'thresh1'); - App.TestAliases.testAsComputedLteProperties(getView(), 'isGreen', 'data', 'thresh1'); + App.TestAliases.testAsComputedGtProperties(getView(), 'isRed', 'data', 'thresholdMin'); + App.TestAliases.testAsComputedLteProperties(getView(), 'isGreen', 'data', 'thresholdMin'); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/9348725b/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js b/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js index 730e209..096d782 100644 --- a/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js +++ b/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js @@ -22,7 +22,7 @@ require('views/main/dashboard/widget'); require('views/main/dashboard/widgets/text_widget'); function getView() { - return App.TextDashboardWidgetView.create({thresh1:40, thresh2:70}); + return App.TextDashboardWidgetView.create({thresholdMin:40, thresholdMax:70}); } describe('App.TextDashboardWidgetView', function() { @@ -43,8 +43,8 @@ describe('App.TextDashboardWidgetView', function() { ]; tests.forEach(function(test) { - describe('data - ' + test.data + ' | thresh1 - 40 | thresh2 - 70', function() { - var textDashboardWidgetView = App.TextDashboardWidgetView.create({thresh1:40, thresh2:70}); + describe('data - ' + test.data + ' | thresholdMin - 40 | thresholdMax - 70', function() { + var textDashboardWidgetView = App.TextDashboardWidgetView.create({thresholdMin:40, thresholdMax:70}); textDashboardWidgetView.set('data', test.data); it('isNA', function() { expect(textDashboardWidgetView.get('isNA')).to.equal(test.e.isNA); @@ -52,9 +52,9 @@ describe('App.TextDashboardWidgetView', function() { }); }); - App.TestAliases.testAsComputedGtProperties(getView(), 'isGreen', 'data', 'thresh2'); + App.TestAliases.testAsComputedGtProperties(getView(), 'isGreen', 'data', 'thresholdMax'); - App.TestAliases.testAsComputedLteProperties(getView(), 'isRed', 'data', 'thresh1'); + App.TestAliases.testAsComputedLteProperties(getView(), 'isRed', 'data', 'thresholdMin'); App.TestAliases.testAsComputedAnd(getView(), 'isOrange', ['!isGreen', '!isRed']); http://git-wip-us.apache.org/repos/asf/ambari/blob/9348725b/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js ---------------------------------------------------------------------- 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 fbe2694..fa20593 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 @@ -25,7 +25,7 @@ var uptimeTextDashboardWidgetView; describe('App.UptimeTextDashboardWidgetView', function() { beforeEach(function () { - uptimeTextDashboardWidgetView = App.UptimeTextDashboardWidgetView.create({thresh1:40, thresh2:70}); + uptimeTextDashboardWidgetView = App.UptimeTextDashboardWidgetView.create({thresholdMin:40, thresholdMax:70}); }); describe('#timeConverter', function() { http://git-wip-us.apache.org/repos/asf/ambari/blob/9348725b/ambari-web/test/views/main/dashboard/widgets_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widgets_test.js b/ambari-web/test/views/main/dashboard/widgets_test.js index 0781c79..707087a 100644 --- a/ambari-web/test/views/main/dashboard/widgets_test.js +++ b/ambari-web/test/views/main/dashboard/widgets_test.js @@ -25,526 +25,325 @@ require('views/main/dashboard/widgets'); describe('App.MainDashboardWidgetsView', function () { - var view = App.MainDashboardWidgetsView.create(); - - describe('#setInitPrefObject', function () { - var hostMetricsWidgetsCount = 4; - var hdfsWidgetsCount = 7; - var hbaseWidgetsCount = 4; - var yarnWidgetsCount = 4; - var totalWidgetsCount = 20; - var tests = Em.A([ - { - models: { - host_metrics_model: null, - hdfs_model: null, - hbase_model: null, - yarn_model: null - }, - e: { - visibleL: totalWidgetsCount - hostMetricsWidgetsCount - hdfsWidgetsCount - hbaseWidgetsCount - yarnWidgetsCount - 1, - hiddenL: 0 - }, - m: 'All models are null' - }, - { - models: { - host_metrics_model: {}, - hdfs_model: null, - hbase_model: null, - yarn_model: null - }, - e: { - visibleL: totalWidgetsCount - hdfsWidgetsCount - hbaseWidgetsCount - yarnWidgetsCount - 1, - hiddenL: 0 - }, - m: 'hdfs_model, hbase_model, yarn_model are null' - }, - { - models: { - host_metrics_model: {}, - hdfs_model: {}, - hbase_model: null, - yarn_model: null - }, - e: { - visibleL: totalWidgetsCount - hbaseWidgetsCount - yarnWidgetsCount - 1, - hiddenL: 0 - }, - m: 'hbase_model, yarn_model are null' - }, - { - models: { - host_metrics_model: {}, - hdfs_model: {}, - hbase_model: null, - yarn_model: null - }, - e: { - visibleL: totalWidgetsCount - hbaseWidgetsCount - yarnWidgetsCount - 1, - hiddenL: 0 - }, - m: 'hbase_model and yarn_model are null' - }, - { - models: { - host_metrics_model: {}, - hdfs_model: {}, - hbase_model: {}, - yarn_model: null - }, - e: { - visibleL: totalWidgetsCount - yarnWidgetsCount - 1, - hiddenL: 1 - }, - m: 'yarn_model is null' - }, - { - models: { - host_metrics_model: {}, - hdfs_model: {}, - hbase_model: {}, - yarn_model: {} - }, - e: { - visibleL: totalWidgetsCount - 1, - hiddenL: 1 - }, - m: 'All models are not null' - } - ]); + var view; + + beforeEach(function() { + view = App.MainDashboardWidgetsView.create({ + getUserPref: Em.K, + postUserPref: Em.K, + setDBProperty: Em.K, + persistKey: 'key' + }); + }); + + describe('#didInsertElement()', function() { beforeEach(function() { - sinon.stub(view, 'resolveConfigDependencies'); + sinon.stub(view, 'loadWidgetsSettings').returns({ + complete: Em.clb + }); + sinon.stub(view, 'checkServicesChange'); + sinon.stub(view, 'renderWidgets'); + sinon.stub(Em.run, 'next'); + view.didInsertElement(); }); afterEach(function() { - view.resolveConfigDependencies.restore(); + view.loadWidgetsSettings.restore(); + view.checkServicesChange.restore(); + view.renderWidgets.restore(); + Em.run.next.restore(); }); - tests.forEach(function (test) { - describe(test.m, function () { - - beforeEach(function () { - view.set('host_metrics_model', test.models.host_metrics_model); - view.set('hdfs_model', test.models.hdfs_model); - view.set('hbase_model', test.models.hbase_model); - view.set('yarn_model', test.models.yarn_model); - view.setInitPrefObject(); - }); - - it('visible.length is ' + test.e.visibleL, function () { - expect(view.get('initPrefObject.visible.length')).to.equal(test.e.visibleL); - }); - - it('hidden.length is ' + test.e.hiddenL, function () { - expect(view.get('initPrefObject.hidden.length')).to.equal(test.e.hiddenL); - }); - - }); + it('checkServicesChange should be called', function() { + expect(view.checkServicesChange).to.be.calledOnce; }); - }); - describe('#persistKey', function () { - beforeEach(function () { - sinon.stub(App, 'get').withArgs('router.loginName').returns('tdk'); + it('renderWidgets should be called', function() { + expect(view.renderWidgets).to.be.calledOnce; }); - afterEach(function () { - App.get.restore(); + + it('isDataLoaded should be true', function() { + expect(view.get('isDataLoaded')).to.be.true; }); - it('Check it', function () { - expect(view.get('persistKey')).to.equal('user-pref-tdk-dashboard'); + + it('Em.run.next should be called', function() { + expect(Em.run.next.calledWith(view, 'makeSortable')).to.be.true; }); }); - describe("#didInsertElement()", function () { - beforeEach(function () { - sinon.stub(view, 'setWidgetsDataModel', Em.K); - sinon.stub(view, 'setInitPrefObject', Em.K); - sinon.stub(view, 'setOnLoadVisibleWidgets', Em.K); - sinon.stub(Em.run, 'next', Em.K); - view.didInsertElement(); - }); - afterEach(function () { - view.setWidgetsDataModel.restore(); - view.setInitPrefObject.restore(); - view.setOnLoadVisibleWidgets.restore(); - Em.run.next.restore(); - }); - it("setWidgetsDataModel is called once", function () { - expect(view.setWidgetsDataModel.calledOnce).to.be.true; - }); - it("setInitPrefObject is called once", function () { - expect(view.setInitPrefObject.calledOnce).to.be.true; - }); - it("setOnLoadVisibleWidgets is called once", function () { - expect(view.setOnLoadVisibleWidgets.calledOnce).to.be.true; + describe('#loadWidgetsSettings()', function() { + + beforeEach(function() { + sinon.spy(view, 'getUserPref'); }); - it("makeSortable is called in the next loop", function () { - expect(Em.run.next.calledWith(view, 'makeSortable')).to.be.true; + + afterEach(function() { + view.getUserPref.restore(); }); - it("isDataLoaded is true", function () { - expect(view.get('isDataLoaded')).to.be.true + + it('getUserPref should be called', function() { + view.loadWidgetsSettings(); + expect(view.getUserPref.calledWith('key')).to.be.true; }); }); - describe("#setWidgetsDataModel()", function () { - beforeEach(function () { - this.model = sinon.stub(App.Service, 'find'); - this.get = sinon.stub(App, 'get'); - }); - afterEach(function () { - this.model.restore(); - this.get.restore(); + describe('#saveWidgetsSettings()', function() { + + beforeEach(function() { + sinon.stub(view, 'setDBProperty'); + sinon.stub(view, 'postUserPref'); + view.saveWidgetsSettings({settings:{}}); }); - it("No host_metrics_model", function () { - this.get.returns([]); - this.model.returns([Em.Object.create({ - serviceName: 'S1', - id: 'S1' - })]); - view.set('host_metrics_model', null); - view.setWidgetsDataModel(); - expect(view.get('host_metrics_model')).to.be.null; - expect(view.get('s1_model')).to.eql(Em.Object.create({ - serviceName: 'S1', - id: 'S1' - })); + + afterEach(function() { + view.setDBProperty.restore(); + view.postUserPref.restore(); }); - it("host_metrics_model is present", function () { - this.get.returns([1]); - this.model.returns([Em.Object.create({ - serviceName: 'HDFS', - id: 'HDFS' - })]); - view.set('host_metrics_model', null); - view.setWidgetsDataModel(); - expect(view.get('host_metrics_model')).to.eql([1]); - expect(view.get('hdfs_model.id')).to.equal('HDFS'); + + it('setDBProperty should be called', function() { + expect(view.setDBProperty.calledWith('key', {settings:{}})).to.be.true; }); - }); - describe("#plusButtonFilterView", function () { - var plusButtonFilterView = view.get('plusButtonFilterView').create({ - parentView: view + it('postUserPref should be called', function() { + expect(view.postUserPref.calledWith('key', {settings:{}})).to.be.true; }); - plusButtonFilterView.reopen({ - visibleWidgets: [], - hiddenWidgets: [] + + it('userPreferences should be set', function() { + expect(view.get('userPreferences')).to.be.eql({settings:{}}); }); + }); - describe("#applyFilter()", function () { - var widget = {checked: true}; - beforeEach(function () { - sinon.stub(view, 'getUserPref').returns({ - complete: Em.K - }); - sinon.stub(view, 'widgetsMapper').returns(widget); - }); + describe('#getUserPrefSuccessCallback()', function() { - afterEach(function () { - view.getUserPref.restore(); - view.widgetsMapper.restore(); - }); + beforeEach(function() { + sinon.stub(view, 'getUserPrefErrorCallback'); + }); - it("testMode is off", function () { - plusButtonFilterView.applyFilter(); - expect(view.getUserPref.calledOnce).to.be.true; - }); + afterEach(function() { + view.getUserPrefErrorCallback.restore(); }); - describe("#applyFilterComplete()", function () { - beforeEach(function () { - sinon.stub(view, 'postUserPref'); - sinon.stub(view, 'translateToReal'); - sinon.stub(App.router, 'get', function (k) { - if ('loginName' === k) return 'tdk'; - return Em.get(App.router, k); - }); - plusButtonFilterView.set('hiddenWidgets', [ - Em.Object.create({ - checked: true, - id: 1, - displayName: 'i1' - }), - Em.Object.create({ - checked: false, - id: 2, - displayName: 'i2' - }) - ]); - view.set('currentPrefObject', Em.Object.create({ - dashboardVersion: 'new', - visible: [], - hidden: [], - threshold: 'threshold' - })); - view.set('persistKey', 'key'); - plusButtonFilterView.applyFilterComplete(); - }); - afterEach(function () { - view.postUserPref.restore(); - view.translateToReal.restore(); - App.router.get.restore(); - }); - it("postUserPref is called once", function () { - expect(view.postUserPref.calledOnce).to.be.true; - }); - it("translateToReal is called with correct data", function () { - expect(view.translateToReal.getCall(0).args[0]).to.eql(Em.Object.create({ - dashboardVersion: 'new', - visible: [1], - hidden: [ - [2, 'i2'] - ], - threshold: 'threshold' - })); - }); - it("1 hidden widget", function () { - expect(plusButtonFilterView.get('hiddenWidgets.length')).to.equal(1); - }); + it('getUserPrefErrorCallback should be called', function() { + view.getUserPrefSuccessCallback(null); + expect(view.getUserPrefErrorCallback).to.be.calledOnce; }); - }); - describe("#translateToReal()", function () { - beforeEach(function () { - sinon.stub(view, 'widgetsMapper').returns(Em.Object.create()); - view.set('visibleWidgets', []); - view.set('hiddenWidgets', []); - }); - afterEach(function () { - view.widgetsMapper.restore(); - }); - it("version is not new", function () { - var data = { - dashboardVersion: null, - visible: [], - hidden: [], - threshold: [] - }; - view.translateToReal(data); - expect(view.get('visibleWidgets')).to.be.empty; - expect(view.get('hiddenWidgets')).to.be.empty; - }); - it("version is new", function () { - var data = { - dashboardVersion: 'new', - visible: [1], - hidden: [ - ['id', 'title'] - ], - threshold: [ - [], - [ - ['tresh1'], - ['tresh2'] - ] - ] - }; - view.translateToReal(data); - expect(view.get('visibleWidgets')).to.not.be.empty; - expect(view.get('hiddenWidgets')).to.not.be.empty; + it('userPreferences should be set', function() { + view.getUserPrefSuccessCallback({settings:{}}); + expect(view.get('userPreferences')).to.be.eql({settings:{}}); }); }); - describe("#setOnLoadVisibleWidgets()", function () { - beforeEach(function () { - sinon.stub(view, 'translateToReal', Em.K); - sinon.stub(view, 'getUserPref').returns({complete: Em.K}); - }); + describe('#getUserPrefErrorCallback()', function() { - afterEach(function () { - view.translateToReal.restore(); - view.getUserPref.restore(); + beforeEach(function() { + sinon.stub(view, 'generateDefaultUserPreferences').returns({settings:{}}); + sinon.stub(view, 'saveWidgetsSettings'); }); - it("testMode is false", function () { - view.setOnLoadVisibleWidgets(); - expect(view.getUserPref.calledOnce).to.be.true; + afterEach(function() { + view.generateDefaultUserPreferences.restore(); + view.saveWidgetsSettings.restore(); }); - }); - describe("#removeWidget()", function () { - var widget; - var value; - beforeEach(function () { - widget = {}; - value = { - visible: [widget], - hidden: [ - [widget] - ] - }; - value = view.removeWidget(value, widget); - }); - it("value.visible is empty", function () { - expect(value.visible).to.be.empty; - }); - it("value.hidden is empty", function () { - expect(value.hidden).to.be.empty; + it('saveWidgetsSettings should be called', function() { + view.getUserPrefErrorCallback(); + expect(view.saveWidgetsSettings.calledWith({settings:{}})).to.be.true; }); }); - describe("#containsWidget()", function () { - it("widget visible", function () { - var widget = {}; - var value = { - visible: [widget], - hidden: [ - [widget] - ] - }; - expect(view.containsWidget(value, widget)).to.be.true; - }); - it("widget absent", function () { - var widget = {}; - var value = { - visible: [], - hidden: [] - }; - expect(view.containsWidget(value, widget)).to.be.false; - }); - it("widget hidden", function () { - var widget = {}; - var value = { - visible: [], - hidden: [ - [widget] - ] - }; - expect(view.containsWidget(value, widget)).to.be.true; + describe('#resolveConfigDependencies()', function() { + + beforeEach(function() { + this.mock = sinon.stub(App.router, 'get'); }); - }); - describe("#persistKey", function () { - before(function () { - sinon.stub(App, 'get').withArgs('router.loginName').returns('user'); + afterEach(function() { + App.router.get.restore(); }); - after(function () { - App.get.restore(); + + it('isHiddenByDefault should be undefined', function() { + var widgets = [{id: 20}]; + this.mock.returns({properties: {'hide_yarn_memory_widget': 'false'}}); + view.resolveConfigDependencies(widgets); + expect(widgets[0].isHiddenByDefault).to.be.undefined; }); - it("depends on router.loginName", function () { - view.propertyDidChange('persistKey'); - expect(view.get('persistKey')).to.equal('user-pref-user-dashboard'); + + it('isHiddenByDefault should be true', function() { + var widgets = [{id: 20}]; + this.mock.returns({properties: {'hide_yarn_memory_widget': 'true'}}); + view.resolveConfigDependencies(widgets); + expect(widgets[0].isHiddenByDefault).to.be.true; }); }); - describe("#getUserPrefSuccessCallback()", function () { + describe('#generateDefaultUserPreferences', function() { - it("response is null", function () { - view.set('currentPrefObject', null); - view.getUserPrefSuccessCallback(null, {}, {}); - expect(view.get('currentPrefObject')).to.be.null; + beforeEach(function() { + sinon.stub(view, 'resolveConfigDependencies'); + sinon.stub(App.Service, 'find').returns(Em.Object.create()); + view.set('widgetsDefinition', [ + Em.Object.create({sourceName: 'S1', id: 1}), + Em.Object.create({sourceName: 'HOST_METRICS', id: 2, isHiddenByDefault: true, threshold: []}), + Em.Object.create({sourceName: 'HOST_METRICS', id: 3, threshold: [1, 2]}) + ]); }); - it("response is correct", function () { - view.set('currentPrefObject', null); - view.getUserPrefSuccessCallback({}, {}, {}); - expect(view.get('currentPrefObject')).to.eql({}); + afterEach(function() { + view.resolveConfigDependencies.restore(); + App.Service.find.restore(); }); - it('should update missing thresholds', function () { + it('should generate default preferences', function() { + expect(JSON.stringify(view.generateDefaultUserPreferences())).to.be.eql(JSON.stringify({ + "visible": [3], + "hidden": [2], + "threshold": { + "2": [], + "3": [1,2] + } + })); + expect(view.resolveConfigDependencies).to.be.calledOnce; + }); + }); + + describe('#renderWidgets()', function() { - view.set('currentPrefObject', null); - view.getUserPrefSuccessCallback({ + it('should set visibleWidgets and hiddenWidgets', function() { + view.set('userPreferences', { + visible: [1], + hidden: [2], threshold: { - 17: [] + 1: [], + 2: [1,2] } - }, {}, {}); - expect(view.get('currentPrefObject.threshold')['17']).to.eql([70, 90]); + }); + view.renderWidgets(); + expect(view.get('visibleWidgets')).to.be.eql([Em.Object.create({ + id: 1, + threshold: [], + viewClass: App['NameNodeHeapPieChartView'], + sourceName: 'HDFS', + title: Em.I18n.t('dashboard.widgets.NameNodeHeap') + })]); + expect(view.get('hiddenWidgets')).to.be.eql([ + Em.Object.create({ + id: 2, + title: Em.I18n.t('dashboard.widgets.HDFSDiskUsage'), + checked: false + }) + ]); + }); + }); + + describe('#checkServicesChange()', function() { + + beforeEach(function() { + sinon.stub(view, 'generateDefaultUserPreferences').returns({ + visible: [1, 2], + hidden: [3, 4] + }); + sinon.stub(view, 'saveWidgetsSettings'); + }); + afterEach(function() { + view.generateDefaultUserPreferences.restore(); + view.saveWidgetsSettings.restore(); }); + it('userPreferences should be updated', function() { + view.set('userPreferences', { + visible: [3], + hidden: [1], + threshold: {} + }); + view.checkServicesChange(); + expect(view.saveWidgetsSettings.getCall(0).args[0]).to.be.eql({ + visible: [3, 2], + hidden: [1, 4], + threshold: {} + }); + }); }); - describe("#resetAllWidgets()", function () { + describe('#resetAllWidgets()', function() { - beforeEach(function () { + beforeEach(function() { sinon.stub(App, 'showConfirmationPopup', Em.clb); - sinon.stub(view, 'postUserPref', Em.K); - sinon.stub(view, 'setDBProperty', Em.K); - sinon.stub(view, 'translateToReal', Em.K); - view.setProperties({ - currentTimeRangeIndex: 1, - customStartTime: 1000, - customEndTime: 2000 - }); + sinon.stub(view, 'generateDefaultUserPreferences').returns({settings: {}}); + sinon.stub(view, 'saveWidgetsSettings'); + sinon.stub(view, 'renderWidgets'); view.resetAllWidgets(); }); - afterEach(function () { + afterEach(function() { App.showConfirmationPopup.restore(); - view.postUserPref.restore(); - view.setDBProperty.restore(); - view.translateToReal.restore(); + view.generateDefaultUserPreferences.restore(); + view.saveWidgetsSettings.restore(); + view.renderWidgets.restore(); }); - it('persist reset', function () { - expect(view.postUserPref.calledOnce).to.be.true; - }); - it('local storage reset', function () { - expect(view.setDBProperty.calledOnce).to.be.true; + it('saveWidgetsSettings should be called', function() { + expect(view.saveWidgetsSettings.calledWith({settings: {}})).to.be.true; }); - it('time range reset', function () { - expect(view.get('currentTimeRangeIndex')).to.equal(0); + + it('renderWidgets should be called', function() { + expect(view.renderWidgets).to.be.calledOnce; }); - it('custom start time reset', function () { + + it('properties should be reset', function() { + expect(view.get('currentTimeRangeIndex')).to.be.equal(0); expect(view.get('customStartTime')).to.be.null; - }); - it('custom end time reset', function () { expect(view.get('customEndTime')).to.be.null; }); - it('default settings application', function () { - expect(view.translateToReal.calledOnce).to.be.true; - }); - }); - describe('#checkServicesChange', function () { + describe('#plusButtonFilterView', function() { + var plusButtonFilterView; - var emptyCurrentPref = { - visible: [], - hidden: [], - threshold: {} - }, - widgetsMap = { - hdfs_model: ['1', '2', '3', '4', '5', '10', '11'], - host_metrics_model: ['6', '7', '8', '9'], - hbase_model: ['12', '13', '14', '15', '16'], - yarn_model: ['17', '18', '19', '20', '23'], - storm_model: ['21'], - flume_model: ['22'] - }, - emptyModelTitle = '{0} absent', - notEmptyModelTitle = '{0} present'; - - Em.keys(widgetsMap).forEach(function (item, index, array) { - it(notEmptyModelTitle.format(item), function () { - array.forEach(function (modelName) { - view.set(modelName, modelName === item ? {} : null); - }); - expect(view.checkServicesChange(emptyCurrentPref).visible).to.eql(widgetsMap[item]); + beforeEach(function() { + plusButtonFilterView = view.get('plusButtonFilterView').create({ + parentView: Em.Object.create({ + saveWidgetsSettings: Em.K, + renderWidgets: Em.K + }) }); }); - Em.keys(widgetsMap).forEach(function (item, index, array) { - it(emptyModelTitle.format(item), function () { - var expected = []; - array.forEach(function (modelName) { - if (modelName === item) { - view.set(modelName, null); - } else { - view.set(modelName, {}); - expected = expected.concat(widgetsMap[modelName]); - } + describe('#applyFilter()', function() { + + beforeEach(function() { + sinon.spy(plusButtonFilterView.get('parentView'), 'renderWidgets'); + sinon.spy(plusButtonFilterView.get('parentView'), 'saveWidgetsSettings'); + plusButtonFilterView.set('parentView.userPreferences', { + visible: [2], + hidden: [1, 3], + threshold: {} }); - expect(view.checkServicesChange({ - visible: widgetsMap[item], - hidden: [], + plusButtonFilterView.set('hiddenWidgets', [ + Em.Object.create({checked: true, id: 1}) + ]); + plusButtonFilterView.applyFilter(); + }); + + afterEach(function() { + plusButtonFilterView.get('parentView').renderWidgets.restore(); + plusButtonFilterView.get('parentView').saveWidgetsSettings.restore(); + }); + + it('saveWidgetsSettings should be called', function() { + expect(plusButtonFilterView.get('parentView').saveWidgetsSettings.getCall(0).args[0]).to.be.eql({ + visible: [2, 1], + hidden: [3], threshold: {} - }).visible).to.eql(expected); + }); }); - }); + it('renderWidgets should be called', function() { + expect(plusButtonFilterView.get('parentView').renderWidgets).to.be.calledOnce; + }); + }); }); + });