Merge pull request #2793 from hiveww/AMBARI-25132-trunk

AMBARI-25132. Cover metric view
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index c20a839..760a27d 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -284,6 +284,7 @@
   'test/views/common/assign_master_components_view_test',
   'test/views/common/filter_combo_cleanable_test',
   'test/views/common/filter_view_test',
+  'test/views/common/metric_test',
   'test/views/common/pagination_view_test',
   'test/views/common/table_view_test',
   'test/views/common/quick_link_view_test',
diff --git a/ambari-web/test/views/common/metric_test.js b/ambari-web/test/views/common/metric_test.js
new file mode 100644
index 0000000..7267e7a
--- /dev/null
+++ b/ambari-web/test/views/common/metric_test.js
@@ -0,0 +1,77 @@
+/**
+ * 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');
+
+describe('App.MetricFilteringWidget', function () {
+  var view;
+  beforeEach(function () {
+    view = App.MetricFilteringWidget.create({
+      controller: Em.Object.create({})
+    });
+  });
+
+  describe('#chosenMetrics', function () {
+    it('should return array with chosenMetric if it is provided', function () {
+      var chosenMetric = Em.Object.create({ label:Em.I18n.t('metric.default'), value:null});
+      view.set('chosenMetric', chosenMetric);
+      expect(view.get('chosenMetrics')).to.be.eql([chosenMetric]);
+    });
+
+    it('should return array with metrics if bo chosen metric', function () {
+      expect(view.get('chosenMetrics')).to.be.eql(view.get('defaultMetrics'));
+    });
+  });
+
+  describe('#defaultMetrics', function () {
+    it('should return mapped not null metrics values', function () {
+      expect(view.get('defaultMetrics')).to.be.eql(["cpu", "memory", "network", "io"]);
+    });
+  });
+
+  describe('#bindToController', function () {
+    it('should set metricWidget property of controller to current context', function () {
+      view.bindToController();
+      expect(view.get('controller').get('metricWidget')).to.be.eql(view);
+    });
+  });
+
+  describe('#toggleMore', function () {
+    it('should toggle showMore property', function () {
+      view.set('showMore', 4);
+      view.toggleMore();
+      expect(view.get('showMore')).to.be.equal(-3);
+    });
+  });
+
+  describe('#init', function () {
+    it('should call bindToController method', function () {
+      sinon.stub(view, 'bindToController');
+      view.init();
+      expect(view.bindToController.calledOnce).to.be.true;
+      view.bindToController.restore();
+    });
+  });
+
+  describe('#activate', function () {
+    it('should set chosenMetric', function () {
+      view.activate({context: 5});
+      expect(view.get('chosenMetric')).to.be.equal(5);
+    });
+  });
+});
\ No newline at end of file