ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexantone...@apache.org
Subject ambari git commit: AMBARI-17977. Issue while creating a widget of type'Template' (alexantonenko)
Date Mon, 01 Aug 2016 15:19:00 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk c5d32b81b -> 1744a9cc0


AMBARI-17977. Issue while creating a widget of type'Template' (alexantonenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1744a9cc
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1744a9cc
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1744a9cc

Branch: refs/heads/trunk
Commit: 1744a9cc03f5182c93c382e8543f67ef403a0e1e
Parents: c5d32b8
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Mon Aug 1 18:07:45 2016 +0300
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Mon Aug 1 18:18:55 2016 +0300

----------------------------------------------------------------------
 .../service/widgets/create/step2_controller.js  |  26 ++-
 .../widgets/create/step2_controller_test.js     | 210 +++++++++++++------
 2 files changed, 163 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1744a9cc/ambari-web/app/controllers/main/service/widgets/create/step2_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/widgets/create/step2_controller.js b/ambari-web/app/controllers/main/service/widgets/create/step2_controller.js
index 29a3408..4e3ab91 100644
--- a/ambari-web/app/controllers/main/service/widgets/create/step2_controller.js
+++ b/ambari-web/app/controllers/main/service/widgets/create/step2_controller.js
@@ -105,7 +105,8 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
     switch (this.get('content.widgetType')) {
       case "NUMBER":
       case "GAUGE":
-        return !this.isExpressionComplete(this.get('expressions')[0]);
+        var expression = this.get('expressions')[0];
+        return !(this.isExpressionComplete(expression) && this.isExpressionWithMetrics(expression));
       case "GRAPH":
         return !this.isGraphDataComplete(this.get('dataSets'));
       case "TEMPLATE":
@@ -124,8 +125,16 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
    * @returns {boolean}
    */
   isExpressionComplete: function (expression) {
-    return Boolean(expression && !expression.get('isInvalid') && !expression.get('isEmpty')
-      && expression.get('data')&& expression.get('data').someProperty('isMetric'));
+    return Boolean(expression && !expression.get('isInvalid') && !expression.get('isEmpty'));
+  },
+
+  /**
+   * check whether data of expression contains metrics
+   * @param {Em.Object} expression
+   * @returns {boolean}
+   */
+  isExpressionWithMetrics: function (expression) {
+    return Boolean(expression && expression.get('data') && expression.get('data').someProperty('isMetric'));
   },
 
   /**
@@ -134,7 +143,9 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
    * @returns {boolean} isComplete
    */
   isGraphDataComplete: function (dataSets) {
-    var isComplete = Boolean(dataSets.length);
+    var isComplete = Boolean(dataSets.length),
+      expressions = dataSets.mapProperty('expression'),
+      isMetricsIncluded = expressions.some(this.isExpressionWithMetrics);
 
     for (var i = 0; i < dataSets.length; i++) {
       if (dataSets[i].get('label').trim() === '' || !this.isExpressionComplete(dataSets[i].get('expression')))
{
@@ -142,7 +153,7 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
         break;
       }
     }
-    return isComplete;
+    return isComplete && isMetricsIncluded;
   },
 
   /**
@@ -152,7 +163,8 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
    * @returns {boolean} isComplete
    */
   isTemplateDataComplete: function (expressions, templateValue) {
-    var isComplete = Boolean(expressions.length > 0 && templateValue.trim() !==
'');
+    var isComplete = Boolean(expressions.length > 0 && templateValue.trim() !==
''),
+      isMetricsIncluded = expressions.some(this.isExpressionWithMetrics);
 
     if (isComplete) {
       for (var i = 0; i < expressions.length; i++) {
@@ -162,7 +174,7 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({
         }
       }
     }
-    return isComplete;
+    return isComplete && isMetricsIncluded;
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/1744a9cc/ambari-web/test/controllers/main/service/widgets/create/step2_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/service/widgets/create/step2_controller_test.js
b/ambari-web/test/controllers/main/service/widgets/create/step2_controller_test.js
index 57b64af..1b00279 100644
--- a/ambari-web/test/controllers/main/service/widgets/create/step2_controller_test.js
+++ b/ambari-web/test/controllers/main/service/widgets/create/step2_controller_test.js
@@ -83,12 +83,14 @@ describe('App.WidgetWizardStep2Controller', function () {
   describe("#isSubmitDisabled", function () {
     beforeEach(function () {
       this.expressionFunc = sinon.stub(controller, 'isExpressionComplete');
+      this.metricsFunc = sinon.stub(controller, 'isExpressionWithMetrics');
       this.graphFunc = sinon.stub(controller, 'isGraphDataComplete');
       this.templateFunc = sinon.stub(controller, 'isTemplateDataComplete');
       controller.set('expressions', ['']);
     });
     afterEach(function () {
       this.expressionFunc.restore();
+      this.metricsFunc.restore();
       this.graphFunc.restore();
       this.templateFunc.restore();
       controller.get('expressions').clear();
@@ -102,13 +104,31 @@ describe('App.WidgetWizardStep2Controller', function () {
       controller.set('widgetPropertiesViews', []);
       controller.set('content.widgetType', 'NUMBER');
       this.expressionFunc.returns(true);
+      this.metricsFunc.returns(true);
       controller.propertyDidChange('isSubmitDisabled');
       expect(controller.get('isSubmitDisabled')).to.be.false;
     });
-    it("invalid number widget", function () {
+    it("invalid number widget with metrics", function () {
       controller.set('widgetPropertiesViews', []);
       controller.set('content.widgetType', 'NUMBER');
       this.expressionFunc.returns(false);
+      this.metricsFunc.returns(true);
+      controller.propertyDidChange('isSubmitDisabled');
+      expect(controller.get('isSubmitDisabled')).to.be.true;
+    });
+    it("number widget w/o metrics", function () {
+      controller.set('widgetPropertiesViews', []);
+      controller.set('content.widgetType', 'NUMBER');
+      this.expressionFunc.returns(true);
+      this.metricsFunc.returns(false);
+      controller.propertyDidChange('isSubmitDisabled');
+      expect(controller.get('isSubmitDisabled')).to.be.true;
+    });
+    it("invalid number widget w/o metrics", function () {
+      controller.set('widgetPropertiesViews', []);
+      controller.set('content.widgetType', 'NUMBER');
+      this.expressionFunc.returns(false);
+      this.metricsFunc.returns(false);
       controller.propertyDidChange('isSubmitDisabled');
       expect(controller.get('isSubmitDisabled')).to.be.true;
     });
@@ -158,12 +178,7 @@ describe('App.WidgetWizardStep2Controller', function () {
       {
         expression: Em.Object.create({isInvalid: true}),
         result: false,
-        title: 'invalid expression, no data array'
-      },
-      {
-        expression: Em.Object.create({isInvalid: false, isEmpty: false}),
-        result: false,
-        title: 'no data array'
+        title: 'invalid expression'
       },
       {
         expression: Em.Object.create({isInvalid: false, isEmpty: true}),
@@ -171,101 +186,164 @@ describe('App.WidgetWizardStep2Controller', function () {
         title: 'empty expression'
       },
       {
-        expression: Em.Object.create({isInvalid: true, data: []}),
-        result: false,
-        title: 'invalid expression, empty data array'
-      },
+        expression: Em.Object.create({isInvalid: false, isEmpty: false}),
+        result: true,
+        title: 'complete expression'
+      }
+    ];
+    testCases.forEach(function (test) {
+      it(test.title, function () {
+        expect(controller.isExpressionComplete(test.expression)).to.equal(test.result);
+      });
+    });
+  });
+
+  describe("#isExpressionWithMetrics()", function () {
+    var testCases = [
       {
-        expression: Em.Object.create({isInvalid: false, isEmpty: false, data: []}),
+        expression: null,
         result: false,
-        title: 'empty data array'
+        title: 'no expression'
       },
       {
-        expression: Em.Object.create({isInvalid: false, isEmpty: true, data: []}),
+        expression: Em.Object.create(),
         result: false,
-        title: 'empty expression and data array'
+        title: 'no data array'
       },
       {
-        expression: Em.Object.create({isInvalid: true, data: [{isMetric: false}]}),
+        expression: Em.Object.create({data: []}),
         result: false,
-        title: 'invalid expression, no metrics'
+        title: 'empty data array'
       },
       {
-        expression: Em.Object.create({isInvalid: false, isEmpty: false, data: [{isMetric:
false}]}),
+        expression: Em.Object.create({data: [{isMetric: false}]}),
         result: false,
         title: 'no metrics'
       },
       {
-        expression: Em.Object.create({isInvalid: false, isEmpty: true, data: [{isMetric:
false}]}),
-        result: false,
-        title: 'empty expression, no metrics'
-      },
-      {
-        expression: Em.Object.create({isInvalid: true, data: [{isMetric: false}, {isMetric:
true}]}),
-        result: false,
-        title: 'invalid expression'
-      },
-      {
-        expression: Em.Object.create({isInvalid: false, isEmpty: false, data: [{isMetric:
false}, {isMetric: true}]}),
+        expression: Em.Object.create({data: [{isMetric: false}, {isMetric: true}]}),
         result: true,
-        title: 'valid expression'
-      },
-      {
-        expression: Em.Object.create({isInvalid: false, isEmpty: true, data: [{isMetric:
false}, {isMetric: true}]}),
-        result: false,
-        title: 'empty expression, valid data array'
+        title: 'metrics included'
       }
     ];
     testCases.forEach(function (test) {
       it(test.title, function () {
-        expect(controller.isExpressionComplete(test.expression)).to.equal(test.result);
+        expect(controller.isExpressionWithMetrics(test.expression)).to.equal(test.result);
       });
     });
   });
 
   describe("#isGraphDataComplete()", function () {
+    var mock,
+      cases = [
+        {
+          dataSets: [],
+          isGraphDataComplete: false,
+          title: 'dataSets is empty'
+        },
+        {
+          dataSets: [Em.Object.create({label: ''})],
+          isGraphDataComplete: false,
+          title: 'label is empty'
+        },
+        {
+          dataSets: [Em.Object.create({label: 'abc'})],
+          isExpressionComplete: false,
+          isGraphDataComplete: false,
+          title: 'expression is not complete'
+        },
+        {
+          dataSets: [Em.Object.create({label: 'abc'})],
+          isExpressionComplete: true,
+          isExpressionWithMetrics: false,
+          isGraphDataComplete: false,
+          title: 'no metrics in expression'
+        },
+        {
+          dataSets: [Em.Object.create({label: 'abc', expression: {data: [{isMetric: true}]}})],
+          isExpressionComplete: true,
+          isExpressionWithMetrics: true,
+          isGraphDataComplete: true,
+          title: 'expression is complete and contains metrics'
+        }
+      ];
+
     beforeEach(function () {
-      this.mock = sinon.stub(controller, 'isExpressionComplete');
+      mock = {
+        isExpressionComplete: sinon.stub(controller, 'isExpressionComplete'),
+        isExpressionWithMetrics: sinon.stub(controller, 'isExpressionWithMetrics')
+      };
     });
     afterEach(function () {
-      this.mock.restore();
-    });
-    it("dataSets is empty", function () {
-      expect(controller.isGraphDataComplete([])).to.be.false;
-    });
-    it("label is empty", function () {
-      expect(controller.isGraphDataComplete([Em.Object.create({label: ''})])).to.be.false;
+      mock.isExpressionComplete.restore();
+      mock.isExpressionWithMetrics.restore();
     });
-    it("expression is not complete", function () {
-      this.mock.returns(false);
-      expect(controller.isGraphDataComplete([Em.Object.create({label: 'abc'})])).to.be.false;
-    });
-    it("expression is complete", function () {
-      this.mock.returns(true);
-      expect(controller.isGraphDataComplete([Em.Object.create({label: 'abc'})])).to.be.true;
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        mock.isExpressionComplete.returns(item.isExpressionComplete);
+        mock.isExpressionWithMetrics.returns(item.isExpressionWithMetrics);
+        expect(controller.isGraphDataComplete(item.dataSets)).to.equal(item.isGraphDataComplete);
+      });
     });
   });
 
   describe("#isTemplateDataComplete()", function () {
+    var mock,
+      cases = [
+        {
+          expressions: [],
+          isTemplateDataComplete: false,
+          title: 'expressions is empty'
+        },
+        {
+          expressions: [{}],
+          templateValue: '',
+          isTemplateDataComplete: false,
+          title: 'templateValue is empty'
+        },
+        {
+          expressions: [{}],
+          templateValue: 'abc',
+          isExpressionComplete: false,
+          isTemplateDataComplete: false,
+          title: 'expression is not complete'
+        },
+        {
+          expressions: [{}],
+          templateValue: 'abc',
+          isExpressionComplete: true,
+          isExpressionWithMetrics: false,
+          isTemplateDataComplete: false,
+          title: 'no metrics in expression'
+        },
+        {
+          expressions: [{data: [{isMetric: true}]}],
+          templateValue: 'abc',
+          isExpressionComplete: true,
+          isExpressionWithMetrics: true,
+          isTemplateDataComplete: true,
+          title: 'expression is complete and contains metrics'
+        }
+      ];
+
     beforeEach(function () {
-      this.mock = sinon.stub(controller, 'isExpressionComplete');
+      mock = {
+        isExpressionComplete: sinon.stub(controller, 'isExpressionComplete'),
+        isExpressionWithMetrics: sinon.stub(controller, 'isExpressionWithMetrics')
+      };
     });
     afterEach(function () {
-      this.mock.restore();
+      mock.isExpressionComplete.restore();
+      mock.isExpressionWithMetrics.restore();
     });
-    it("expressions is empty", function () {
-      expect(controller.isTemplateDataComplete([])).to.be.false;
-    });
-    it("templateValue is empty", function () {
-      expect(controller.isTemplateDataComplete([{}], '')).to.be.false;
-    });
-    it("expression is not complete", function () {
-      this.mock.returns(false);
-      expect(controller.isTemplateDataComplete([{}], 'abc')).to.be.false;
-    });
-    it("expression is complete", function () {
-      this.mock.returns(true);
-      expect(controller.isTemplateDataComplete([{}], 'abc')).to.be.true;
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        mock.isExpressionComplete.returns(item.isExpressionComplete);
+        mock.isExpressionWithMetrics.returns(item.isExpressionWithMetrics);
+        expect(controller.isTemplateDataComplete(item.expressions, item.templateValue)).to.equal(item.isTemplateDataComplete);
+      });
     });
   });
 


Mime
View raw message