Repository: ambari Updated Branches: refs/heads/trunk 3e4ac6e7a -> e7a8b35d6
AMBARI-11444-2. Number Widgets: Empty threshold for 'Critical' still shows the value as Critical.(XIWANG) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e7a8b35d Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e7a8b35d Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e7a8b35d Branch: refs/heads/trunk Commit: e7a8b35d647cb8b07d641325904b9041382f00c1 Parents: 3e4ac6e Author: Xi Wang <[email protected]> Authored: Mon Jun 15 15:25:48 2015 -0700 Committer: Xi Wang <[email protected]> Committed: Tue Jun 16 11:14:33 2015 -0700 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 2 + .../views/common/widget/gauge_widget_view.js | 4 +- .../views/common/widget/number_widget_view.js | 2 +- .../common/widget/gauge_widget_view_test.js | 166 ++++++++++++++++ .../common/widget/number_widget_view_test.js | 190 +++++++++++++++++++ 5 files changed, 361 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e7a8b35d/ambari-web/app/assets/test/tests.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index 7b894b7..f832a48 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -191,6 +191,8 @@ var files = ['test/init_model_test', 'test/views/common/custom_date_popup_test', 'test/views/common/progress_bar_view_test', 'test/views/common/widget/graph_widget_view_test', + 'test/views/common/widget/number_widget_view_test', + 'test/views/common/widget/gauge_widget_view_test', 'test/views/common/modal_popups/hosts_table_list_popup_test', 'test/views/main/admin_test', 'test/views/main/dashboard_test', http://git-wip-us.apache.org/repos/asf/ambari/blob/e7a8b35d/ambari-web/app/views/common/widget/gauge_widget_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/widget/gauge_widget_view.js b/ambari-web/app/views/common/widget/gauge_widget_view.js index 3d782cd..a1cd24b 100644 --- a/ambari-web/app/views/common/widget/gauge_widget_view.js +++ b/ambari-web/app/views/common/widget/gauge_widget_view.js @@ -91,12 +91,12 @@ App.GaugeWidgetView = Em.View.extend(App.WidgetMixin, { var color_green = App.healthStatusGreen; var color_red = App.healthStatusRed; var color_orange = App.healthStatusOrange; - if (isNaN(threshold1) || (isNaN(threshold2) && used <= threshold1) || (!isNaN(threshold2) && (threshold1 > threshold2) && (used > threshold1)) || (!isNaN(threshold2) && (threshold1 < threshold2) && (used <= threshold1))) { + if ((isNaN(threshold1) && isNaN(threshold2)) || (isNaN(threshold1) && used <= threshold2) || (isNaN(threshold2) && used <= threshold1) || (!isNaN(threshold2) && (threshold1 > threshold2) && (used > threshold1)) || (!isNaN(threshold2) && (threshold1 < threshold2) && (used <= threshold1))) { this.set('palette', new Rickshaw.Color.Palette({ scheme: [ '#FFFFFF', color_green ].reverse() })); return color_green; - } else if ((!isNaN(threshold2) && used.isInRange(threshold1, threshold2)) || (isNaN(threshold2) && used > threshold1) ) { + } else if ((!isNaN(threshold2) && used.isInRange(threshold1, threshold2)) || (isNaN(threshold2) && used > threshold1)) { this.set('palette', new Rickshaw.Color.Palette({ scheme: [ '#FFFFFF', color_orange ].reverse() })); http://git-wip-us.apache.org/repos/asf/ambari/blob/e7a8b35d/ambari-web/app/views/common/widget/number_widget_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/widget/number_widget_view.js b/ambari-web/app/views/common/widget/number_widget_view.js index 33bf34e..b962851 100644 --- a/ambari-web/app/views/common/widget/number_widget_view.js +++ b/ambari-web/app/views/common/widget/number_widget_view.js @@ -52,7 +52,7 @@ App.NumberWidgetView = Em.View.extend(App.WidgetMixin, { if (isNaN(value)) { return 'grey'; - } else if (isNaN(threshold1) || (isNaN(threshold2) && value <= threshold1) || (!isNaN(threshold2) && (threshold1 > threshold2) && (value > threshold1)) || (!isNaN(threshold2) && (threshold1 < threshold2) && (value <= threshold1))) { + } else if ((isNaN(threshold1) && isNaN(threshold2)) || (isNaN(threshold1) && value <= threshold2) || (isNaN(threshold2) && value <= threshold1) || (!isNaN(threshold2) && (threshold1 > threshold2) && (value > threshold1)) || (!isNaN(threshold2) && (threshold1 < threshold2) && (value <= threshold1))) { return 'green'; } else if ((!isNaN(threshold2) && value.isInRange(threshold1, threshold2)) || ((isNaN(threshold2) && value > threshold1))) { return 'orange'; http://git-wip-us.apache.org/repos/asf/ambari/blob/e7a8b35d/ambari-web/test/views/common/widget/gauge_widget_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/common/widget/gauge_widget_view_test.js b/ambari-web/test/views/common/widget/gauge_widget_view_test.js new file mode 100644 index 0000000..6ed4828 --- /dev/null +++ b/ambari-web/test/views/common/widget/gauge_widget_view_test.js @@ -0,0 +1,166 @@ +/** + * 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('views/common/widget/gauge_widget_view'); + +describe('App.GaugeWidgetView', function () { + var view = App.GaugeWidgetView.create({ + value: 0, + content: { + properties: { + warning_threshold: 0, + critical_threshold: 0 + } + } + }); + + describe("#chartView.contentColor()", function() { + var testCases = [ + { + title: 'both thresholds NOT existed', + data: { + value: 0.2, + warningThreshold: null, + criticalThreshold: null + }, + result: App.healthStatusGreen + }, + { + title: 'both thresholds existed 1', + data: { + value: 0.2, + warningThreshold: 0.1, + criticalThreshold: 0.3 + }, + result: App.healthStatusOrange + }, + { + title: 'both thresholds existed 2', + data: { + value: 0.2, + warningThreshold: 0.3, + criticalThreshold: 0.1 + }, + result: App.healthStatusOrange + }, + { + title: 'both thresholds existed 3', + data: { + value: 0.05, + warningThreshold: 0.1, + criticalThreshold: 0.3 + }, + result: App.healthStatusGreen + }, + { + title: 'both thresholds existed 4', + data: { + value: 0.35, + warningThreshold: 0.3, + criticalThreshold: 0.1 + }, + result: App.healthStatusGreen + }, + { + title: 'both thresholds existed 5', + data: { + value: 0.35, + warningThreshold: 0.1, + criticalThreshold: 0.3 + }, + result: App.healthStatusRed + }, + { + title: 'both thresholds existed 6', + data: { + value: 0.05, + warningThreshold: 0.3, + criticalThreshold: 0.1 + }, + result: App.healthStatusRed + }, + { + title: 'only warning threshold existed 1', + data: { + value: 0, + warningThreshold: 1, + criticalThreshold: null + }, + result: App.healthStatusGreen + }, + { + title: 'only warning threshold existed 2', + data: { + value: 2, + warningThreshold: 1, + criticalThreshold: null + }, + result: App.healthStatusOrange + }, + { + title: 'only critical threshold existed 1', + data: { + value: 0.5, + warningThreshold: null, + criticalThreshold: 1 + }, + result: App.healthStatusGreen + }, + { + title: 'only critical threshold existed 2', + data: { + value: 1.5, + warningThreshold: null, + criticalThreshold: 1 + }, + result: App.healthStatusRed + }, + { + title: 'invalid thresholds 1', + data: { + value: 1.5, + warningThreshold: '&*&%', + criticalThreshold: 1 + }, + result: App.healthStatusRed + }, + { + title: 'invalid thresholds 2', + data: { + value: 1.5, + warningThreshold: '&*&%', + criticalThreshold: '@#^^' + }, + result: App.healthStatusGreen + } + ]; + + testCases.forEach(function (test) { + it(test.title, function () { + view.set('value', test.data.value); + view.set('content.properties.warning_threshold', test.data.warningThreshold); + view.set('content.properties.error_threshold', test.data.criticalThreshold); + var chartView = view.chartView.create({ + parentView: view + }); + expect(chartView.get('contentColor')).to.eql(test.result); + }); + }); + }); +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/e7a8b35d/ambari-web/test/views/common/widget/number_widget_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/common/widget/number_widget_view_test.js b/ambari-web/test/views/common/widget/number_widget_view_test.js new file mode 100644 index 0000000..3a55314 --- /dev/null +++ b/ambari-web/test/views/common/widget/number_widget_view_test.js @@ -0,0 +1,190 @@ +/** + * 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('views/common/widget/number_widget_view'); + +describe('App.NumberWidgetView', function () { + var view = App.NumberWidgetView.create({ + value: 0, + content: { + properties: { + warning_threshold: 0, + critical_threshold: 0 + } + } + }); + + describe("#contentColor()", function() { + var testCases = [ + { + title: 'no value', + data: { + value: null, + warningThreshold: 1, + criticalThreshold: 3 + }, + result: 'grey' + }, + { + title: 'no value', + data: { + value: null, + warningThreshold: null, + criticalThreshold: null + }, + result: 'grey' + }, + { + title: 'no value', + data: { + value: null, + warningThreshold: null, + criticalThreshold: 3 + }, + result: 'grey' + }, + { + title: 'both thresholds NOT existed', + data: { + value: 2, + warningThreshold: null, + criticalThreshold: null + }, + result: 'green' + }, + { + title: 'both thresholds existed', + data: { + value: 2, + warningThreshold: 1, + criticalThreshold: 3 + }, + result: 'orange' + }, + { + title: 'both thresholds existed', + data: { + value: 2, + warningThreshold: 3, + criticalThreshold: 1 + }, + result: 'orange' + }, + { + title: 'both thresholds existed', + data: { + value: 0.5, + warningThreshold: 1, + criticalThreshold: 3 + }, + result: 'green' + }, + { + title: 'both thresholds existed', + data: { + value: 3.5, + warningThreshold: 3, + criticalThreshold: 1 + }, + result: 'green' + }, + { + title: 'both thresholds existed', + data: { + value: 3.5, + warningThreshold: 1, + criticalThreshold: 3 + }, + result: 'red' + }, + { + title: 'both thresholds existed', + data: { + value: 0.5, + warningThreshold: 3, + criticalThreshold: 1 + }, + result: 'red' + }, + { + title: 'only warning threshold existed', + data: { + value: 0, + warningThreshold: 1, + criticalThreshold: null + }, + result: 'green' + }, + { + title: 'only warning threshold existed', + data: { + value: 2, + warningThreshold: 1, + criticalThreshold: null + }, + result: 'orange' + }, + { + title: 'only critical threshold existed', + data: { + value: 0.5, + warningThreshold: null, + criticalThreshold: 1 + }, + result: 'green' + }, + { + title: 'only critical threshold existed', + data: { + value: 1.5, + warningThreshold: null, + criticalThreshold: 1 + }, + result: 'red' + }, + { + title: 'invalid thresholds', + data: { + value: 1.5, + warningThreshold: '&*&%', + criticalThreshold: 1 + }, + result: 'red' + }, + { + title: 'invalid thresholds', + data: { + value: 1.5, + warningThreshold: '&*&%', + criticalThreshold: '@#^^' + }, + result: 'green' + } + ]; + + testCases.forEach(function (test) { + it(test.title, function () { + view.set('value', test.data.value); + view.set('content.properties.warning_threshold', test.data.warningThreshold); + view.set('content.properties.error_threshold', test.data.criticalThreshold); + expect(view.get('contentColor')).to.eql(test.result); + }); + }); + }); +}); \ No newline at end of file
