Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 61b2ebb54 -> 4b074fe9f


AMBARI-12003. Enhanced configs: it is possible to set fractional values to 
spinner widget (onechiporenko)


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

Branch: refs/heads/branch-2.1
Commit: 4b074fe9fca2b6f196946ea341687cf2144eca4c
Parents: 61b2ebb
Author: Oleg Nechiporenko <onechipore...@apache.org>
Authored: Thu Jun 18 19:42:52 2015 +0300
Committer: Oleg Nechiporenko <onechipore...@apache.org>
Committed: Thu Jun 18 19:46:38 2015 +0300

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |   1 +
 .../app/views/common/form/spinner_input_view.js |   4 +-
 .../common/form/spinner_input_view_test.js      | 184 +++++++++++++++++++
 3 files changed, 187 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4b074fe9/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 f832a48..52cd712 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -258,6 +258,7 @@ var files = ['test/init_model_test',
   
'test/views/common/configs/custom_category_views/notification_configs_view_test',
   'test/views/common/controls_view_test',
   'test/views/common/configs/widgets/time_interval_spinner_view_test',
+  'test/views/common/form/spinner_input_view_test',
   'test/views/wizard/step3/hostLogPopupBody_view_test',
   'test/views/wizard/step3/hostWarningPopupBody_view_test',
   'test/views/wizard/step3/hostWarningPopupFooter_view_test',

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b074fe9/ambari-web/app/views/common/form/spinner_input_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/form/spinner_input_view.js 
b/ambari-web/app/views/common/form/spinner_input_view.js
index 0cacc80..d7620a0 100644
--- a/ambari-web/app/views/common/form/spinner_input_view.js
+++ b/ambari-web/app/views/common/form/spinner_input_view.js
@@ -127,14 +127,14 @@ App.SpinnerInputView = Em.View.extend({
    */
   keyDown: function (e) {
     var charCode = (e.charCode) ? e.charCode : e.which;
-    if ([46, 8, 9, 27, 13, 110, 190].contains(charCode) ||
+    if ([46, 8, 9, 27, 13, 110].contains(charCode) ||
       (charCode == 65 && e.ctrlKey === true) ||
       (charCode == 67 && e.ctrlKey === true) ||
       (charCode == 88 && e.ctrlKey === true) ||
       (charCode >= 35 && charCode <= 39)) {
       return;
     }
-    if ((e.shiftKey || (charCode < 48 || charCode > 57)) && (charCode < 96 || 
charCode > 105)) {
+    if (charCode == 190 || (e.shiftKey || (charCode < 48 || charCode > 57)) && 
(charCode < 96 || charCode > 105)) {
       e.preventDefault();
     }
   },

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b074fe9/ambari-web/test/views/common/form/spinner_input_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/form/spinner_input_view_test.js 
b/ambari-web/test/views/common/form/spinner_input_view_test.js
new file mode 100644
index 0000000..075ca88
--- /dev/null
+++ b/ambari-web/test/views/common/form/spinner_input_view_test.js
@@ -0,0 +1,184 @@
+/**
+ * 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');
+
+var view;
+var e;
+describe('App.SpinnerInputView', function () {
+
+  beforeEach(function () {
+    view = App.SpinnerInputView.create({});
+    e = {
+      preventDefault: Em.K
+    };
+    sinon.spy(e, 'preventDefault');
+  });
+
+  afterEach(function () {
+    e.preventDefault.restore();
+  });
+
+  describe('#keyDown', function () {
+
+    Em.A([
+      {
+        charCode: 46,
+        ctrlKey: true,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 8,
+        ctrlKey: true,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 9,
+        ctrlKey: true,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 27,
+        ctrlKey: true,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 13,
+        ctrlKey: true,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 110,
+        ctrlKey: true,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 65,
+        ctrlKey: true,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 67,
+        ctrlKey: true,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 88,
+        ctrlKey: true,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 35,
+        ctrlKey: true,
+        e: {
+          preventDefault: false
+        }
+      }
+    ]).forEach(function (test) {
+      it('charCode: ' + test.charCode + ', ctrlKey: ' + test.ctrlKey, function 
() {
+        e.charCode = test.charCode;
+        e.ctrlKey = test.ctrlKey;
+        view.keyDown(e);
+        expect(e.preventDefault.called).to.equal(test.e.preventDefault);
+      });
+    });
+
+    Em.A([
+      {
+        charCode: 35,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 36,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 37,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 38,
+        e: {
+          preventDefault: false
+        }
+      },
+      {
+        charCode: 39,
+        e: {
+          preventDefault: false
+        }
+      }
+    ]).forEach(function (test) {
+      it('charCode: ' + test.charCode, function () {
+        e.charCode = test.charCode;
+        view.keyDown(e);
+        expect(e.preventDefault.called).to.equal(test.e.preventDefault);
+      });
+    });
+
+    Em.A([
+      {
+        charCode: 190,
+        shiftKey: false,
+        e: {
+          preventDefault: true
+        }
+      },
+      {
+        charCode: 190,
+        shiftKey: true,
+        e: {
+          preventDefault: true
+        }
+      }
+    ]).forEach(function (test) {
+      it('charCode: ' + test.charCode + ', shiftKey: ' + test.shiftKey, 
function () {
+        e.charCode = test.charCode;
+        e.shiftKey = test.shiftKey;
+        view.keyDown(e);
+        expect(e.preventDefault.calledOnce).to.equal(test.e.preventDefault);
+      });
+    });
+
+  });
+
+});

Reply via email to