Updated Branches:
  refs/heads/trunk d75875cf1 -> e81d705b7

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e81d705b/ambari-web/test/views/main/dashboard/widgets/pie_chart_widget_test.js
----------------------------------------------------------------------
diff --git 
a/ambari-web/test/views/main/dashboard/widgets/pie_chart_widget_test.js 
b/ambari-web/test/views/main/dashboard/widgets/pie_chart_widget_test.js
new file mode 100644
index 0000000..05ae6e6
--- /dev/null
+++ b/ambari-web/test/views/main/dashboard/widgets/pie_chart_widget_test.js
@@ -0,0 +1,169 @@
+/**
+ * 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/chart/pie');
+require('utils/helper');
+require('views/main/dashboard/widget');
+require('views/main/dashboard/widgets/pie_chart_widget');
+
+describe('App.PieChartDashboardWidgetView', function() {
+
+  var model = Em.Object.create({
+    used: null,
+    max: null
+  });
+  var pieChartDashboardWidgetView = App.PieChartDashboardWidgetView.create({
+    model_type: null,
+    model: model,
+    modelFieldUsed: 'used',
+    modelFieldMax: 'max',
+    widgetHtmlId: 'fake'
+  });
+
+  pieChartDashboardWidgetView.calc();
+
+  describe('#getUsed', function() {
+    var tests = [
+      {
+        model: Em.Object.create({
+          used: 1
+        }),
+        e: 1,
+        m: '"Used" is set'
+      },
+      {
+        model: Em.Object.create({
+          used: null
+        }),
+        e: 0,
+        m: '"Used" is not set'
+      },
+      {
+        model: Em.Object.create({}),
+        e: 0,
+        m: '"Used" is not defined'
+      }
+    ];
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        pieChartDashboardWidgetView.set('model', test.model);
+        expect(pieChartDashboardWidgetView.getUsed()).to.equal(test.e);
+      });
+    });
+  });
+
+  describe('#getMax', function() {
+    var tests = [
+      {
+        model: Em.Object.create({
+          max: 1
+        }),
+        e: 1,
+        m: '"Max" is set'
+      },
+      {
+        model: Em.Object.create({
+          max: null
+        }),
+        e: 0,
+        m: '"Max" is not set'
+      },
+      {
+        model: Em.Object.create({}),
+        e: 0,
+        m: '"Max" is not defined'
+      }
+    ];
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        pieChartDashboardWidgetView.set('model', test.model);
+        expect(pieChartDashboardWidgetView.getMax()).to.equal(test.e);
+      });
+    });
+  });
+
+  describe('#calcIsPieExists', function() {
+    var tests = [
+      {
+        model: Em.Object.create({
+          max: 1
+        }),
+        e: true,
+        m: 'Exists'
+      },
+      {
+        model: Em.Object.create({
+          max: 0
+        }),
+        e: false,
+        m: 'Not exists'
+      },
+      {
+        model: Em.Object.create({}),
+        e: false,
+        m: 'Not exists'
+      }
+    ];
+
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        pieChartDashboardWidgetView.set('model', test.model);
+        expect(pieChartDashboardWidgetView.calcIsPieExists()).to.equal(test.e);
+      });
+    });
+  });
+
+  describe('calcDataForPieChart', function() {
+    var tests = [
+      {
+        model: Em.Object.create({
+          max: 10,
+          used: 0
+        }),
+        e: ['0', 100],
+        m: 'Nothing is used'
+      },
+      {
+        model: Em.Object.create({
+          max: 10,
+          used: 10
+        }),
+        e: ['100', 0],
+        m: 'All is used'
+      },
+      {
+        model: Em.Object.create({
+          max: 10,
+          used: 5
+        }),
+        e: ['50', 50],
+        m: 'Half is used'
+      }
+    ];
+
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        pieChartDashboardWidgetView.set('model', test.model);
+        
expect(pieChartDashboardWidgetView.calcDataForPieChart()).to.eql(test.e);
+      });
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e81d705b/ambari-web/test/views/main/dashboard/widgets/resource_manager_uptime_test.js
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..bf4b637
--- /dev/null
+++ 
b/ambari-web/test/views/main/dashboard/widgets/resource_manager_uptime_test.js
@@ -0,0 +1,95 @@
+/**
+ * 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: {
+        isRed: false,
+        isOrange: false,
+        isGreen: true,
+        isNA: false,
+        content: '192.1 d',
+        data: 192.1
+      }
+    },
+    {
+      model:  Em.Object.create({
+        resourceManagerStartTime: 0
+      }),
+      e: {
+        isRed: false,
+        isOrange: false,
+        isGreen: false,
+        isNA: true,
+        content: Em.I18n.t('services.service.summary.notAvailable'),
+        data: null
+      }
+    },
+    {
+      model:  Em.Object.create({
+        resourceManagerStartTime: 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 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('isRed', function() {
+        expect(resourceManagerUptimeView.get('isRed')).to.equal(test.e.isRed);
+      });
+      it('isOrange', function() {
+        
expect(resourceManagerUptimeView.get('isOrange')).to.equal(test.e.isOrange);
+      });
+      it('isGreen', function() {
+        
expect(resourceManagerUptimeView.get('isGreen')).to.equal(test.e.isGreen);
+      });
+      it('isNA', function() {
+        expect(resourceManagerUptimeView.get('isNA')).to.equal(test.e.isNA);
+      });
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e81d705b/ambari-web/test/views/main/dashboard/widgets/tasktracker_live_test.js
----------------------------------------------------------------------
diff --git 
a/ambari-web/test/views/main/dashboard/widgets/tasktracker_live_test.js 
b/ambari-web/test/views/main/dashboard/widgets/tasktracker_live_test.js
new file mode 100644
index 0000000..50d0123
--- /dev/null
+++ b/ambari-web/test/views/main/dashboard/widgets/tasktracker_live_test.js
@@ -0,0 +1,69 @@
+/**
+ * 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/main/dashboard/widget');
+require('views/main/dashboard/widgets/text_widget');
+require('views/main/dashboard/widgets/tasktracker_live');
+
+describe('App.TaskTrackerUpView', function() {
+
+  var tests = [
+    {
+      data: 100,
+      e: {
+        isRed: false,
+        isOrange: false,
+        isGreen: true
+      }
+    },
+    {
+      data: 0,
+      e: {
+        isRed: true,
+        isOrange: false,
+        isGreen: false
+      }
+    },
+    {
+      data: 50,
+      e: {
+        isRed: false,
+        isOrange: true,
+        isGreen: false
+      }
+    }
+  ];
+
+  tests.forEach(function(test) {
+    describe('', function() {
+      var taskTrackerUpView = App.TaskTrackerUpView.create({model_type:null, 
data: test.data, content: test.data.toString()});
+      it('isRed', function() {
+        expect(taskTrackerUpView.get('isRed')).to.equal(test.e.isRed);
+      });
+      it('isOrange', function() {
+        expect(taskTrackerUpView.get('isOrange')).to.equal(test.e.isOrange);
+      });
+      it('isGreen', function() {
+        expect(taskTrackerUpView.get('isGreen')).to.equal(test.e.isGreen);
+      });
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e81d705b/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
new file mode 100644
index 0000000..b598f6b
--- /dev/null
+++ b/ambari-web/test/views/main/dashboard/widgets/text_widget_test.js
@@ -0,0 +1,84 @@
+/**
+ * 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/main/dashboard/widget');
+require('views/main/dashboard/widgets/text_widget');
+
+describe('App.TextDashboardWidgetView', function() {
+
+  var tests = [
+    {
+      data: 100,
+      e: {
+        isRed: false,
+        isOrange: false,
+        isGreen: true,
+        isNA: false
+      }
+    },
+    {
+      data: 1,
+      e: {
+        isRed: true,
+        isOrange: false,
+        isGreen: false,
+        isNA: false
+      }
+    },
+    {
+      data: 50,
+      e: {
+        isRed: false,
+        isOrange: true,
+        isGreen: false,
+        isNA: false
+      }
+    },
+    {
+      data: null,
+      e: {
+        isRed: true,
+        isOrange: false,
+        isGreen: false,
+        isNA: true
+      }
+    }
+  ];
+
+  tests.forEach(function(test) {
+    describe('data - ' + test.data + ' | thresh1 - 40 | thresh2 - 70', 
function() {
+      var textDashboardWidgetView = 
App.TextDashboardWidgetView.create({thresh1:40, thresh2:70});
+      textDashboardWidgetView.set('data', test.data);
+      it('isRed', function() {
+        expect(textDashboardWidgetView.get('isRed')).to.equal(test.e.isRed);
+      });
+      it('isOrange', function() {
+        
expect(textDashboardWidgetView.get('isOrange')).to.equal(test.e.isOrange);
+      });
+      it('isGreen', function() {
+        
expect(textDashboardWidgetView.get('isGreen')).to.equal(test.e.isGreen);
+      });
+      it('isNA', function() {
+        expect(textDashboardWidgetView.get('isNA')).to.equal(test.e.isNA);
+      });
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e81d705b/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
new file mode 100644
index 0000000..7baec59
--- /dev/null
+++ b/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js
@@ -0,0 +1,90 @@
+/**
+ * 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/main/dashboard/widget');
+require('views/main/dashboard/widgets/text_widget');
+require('views/main/dashboard/widgets/uptime_text_widget');
+
+describe('App.UptimeTextDashboardWidgetView', function() {
+
+  describe('#timeConverter', function() {
+    var timestamps = [
+      {
+        t: 1358245370553,
+        e: {
+          l: 2,
+          f: 'Tue Jan 15 2013'
+        }
+      },
+      {
+        t: 0,
+        e: {
+          l: 2,
+          f: 'Thu Jan 01 1970'
+        }
+      }
+    ];
+    timestamps.forEach(function(timestamp) {
+      var uptimeTextDashboardWidgetView = 
App.UptimeTextDashboardWidgetView.create({thresh1:40, thresh2:70});
+      it('timestamp ' + timestamp.t, function() {
+        var result = uptimeTextDashboardWidgetView.timeConverter(timestamp.t);
+        expect(result.length).to.equal(timestamp.e.l);
+        expect(result[0]).to.equal(timestamp.e.f);
+      });
+    });
+  });
+
+  describe('#uptimeProcessing', function() {
+    var timestamps = [
+      {
+        t: (new Date()).getTime() - 10*1000,
+        e: {
+          timeUnit: 's'
+        }
+      },
+      {
+        t: (new Date()).getTime() - 3600*1000,
+        e: {
+          timeUnit: 'hr'
+        }
+      },
+      {
+        t: (new Date()).getTime() - 24*3600*1000,
+        e: {
+          timeUnit: 'd'
+        }
+      },
+      {
+        t: (new Date()).getTime() - 1800*1000,
+        e: {
+          timeUnit: 'min'
+        }
+      }
+    ];
+    timestamps.forEach(function(timestamp) {
+      var uptimeTextDashboardWidgetView = 
App.UptimeTextDashboardWidgetView.create({thresh1:40, thresh2:70});
+      it('timestamp ' + timestamp.t + '. timeUnit should be ' + '"' + 
timestamp.e.timeUnit + '"', function() {
+        var result = 
uptimeTextDashboardWidgetView.uptimeProcessing(timestamp.t);
+        
expect(uptimeTextDashboardWidgetView.get('timeUnit')).to.equal(timestamp.e.timeUnit);
+      });
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e81d705b/ambari-web/test/views/main/dashboard_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/dashboard_test.js 
b/ambari-web/test/views/main/dashboard_test.js
new file mode 100644
index 0000000..18acf67
--- /dev/null
+++ b/ambari-web/test/views/main/dashboard_test.js
@@ -0,0 +1,122 @@
+/**
+ * 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');
+var filters = require('views/common/filter_view');
+require('views/main/dashboard');
+
+describe('App.MainDashboardView', function() {
+
+  var mainDashboardView = App.MainDashboardView.create();
+
+  describe('#setInitPrefObject', function() {
+    var hdfs_widgets_count = 7;
+    var mapreduce_widgets_count = 7;
+    var hbase_widgets_count = 4;
+    var yarn_widgets_count = 4;
+    var total_widgets_count = 27;
+    var tests = [
+      {
+        models: {
+          hdfs_model: null,
+          mapreduce_model: null,
+          hbase_model: null,
+          yarn_model: null
+        },
+        e: {
+          visibleL: total_widgets_count - hdfs_widgets_count - 
mapreduce_widgets_count - hbase_widgets_count - yarn_widgets_count - 1,
+          hiddenL: 0
+        },
+        m: 'All models are null'
+      },
+      {
+        models: {
+          hdfs_model: {},
+          mapreduce_model: null,
+          hbase_model: null,
+          yarn_model: null
+        },
+        e: {
+          visibleL: total_widgets_count  - mapreduce_widgets_count - 
hbase_widgets_count - yarn_widgets_count - 1,
+          hiddenL: 0
+        },
+        m: 'mapreduce_model, hbase_model, yarn_model are null'
+      },
+      {
+        models: {
+          hdfs_model: {},
+          mapreduce_model: {},
+          hbase_model: null,
+          yarn_model: null
+        },
+        e: {
+          visibleL: total_widgets_count - hbase_widgets_count - 
yarn_widgets_count - 1,
+          hiddenL: 0
+        },
+        m: 'hbase_model and yarn_model are null'
+      },
+      {
+        models: {
+          hdfs_model: {},
+          mapreduce_model: {},
+          hbase_model: {},
+          yarn_model: null
+        },
+        e: {
+          visibleL: total_widgets_count - yarn_widgets_count - 1,
+          hiddenL: 1
+        },
+        m: 'yarn_model is null'
+      },
+      {
+        models: {
+          hdfs_model: {},
+          mapreduce_model: {},
+          hbase_model: {},
+          yarn_model: {}
+        },
+        e: {
+          visibleL: total_widgets_count - 1,
+          hiddenL: 1
+        },
+        m: 'All models are not null'
+      }
+    ];
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        mainDashboardView.set('hdfs_model', test.models.hdfs_model);
+        mainDashboardView.set('mapreduce_model', test.models.mapreduce_model);
+        mainDashboardView.set('hbase_model', test.models.hbase_model);
+        mainDashboardView.set('yarn_model', test.models.yarn_model);
+        mainDashboardView.setInitPrefObject();
+        
expect(mainDashboardView.get('initPrefObject.visible.length')).to.equal(test.e.visibleL);
+        
expect(mainDashboardView.get('initPrefObject.hidden.length')).to.equal(test.e.hiddenL);
+      });
+    });
+  });
+
+  describe('#persistKey', function() {
+    App.router.set('loginName', 'tdk');
+    it('Check it', function() {
+      
expect(mainDashboardView.get('persistKey')).to.equal('user-pref-tdk-dashboard');
+    });
+  });
+
+});

Reply via email to