ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexantone...@apache.org
Subject git commit: AMBARI-5867. Add unit tests for views/*.js files (Max Shepel via alexantonenko)
Date Fri, 23 May 2014 11:58:11 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 88d72aab8 -> f04324e09


AMBARI-5867. Add unit tests for views/*.js files (Max Shepel via alexantonenko)


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

Branch: refs/heads/trunk
Commit: f04324e090d3e714b4413686018c346d0f56e682
Parents: 88d72aa
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Fri May 23 14:52:34 2014 +0300
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Fri May 23 14:52:34 2014 +0300

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js        |   4 +
 ambari-web/app/views/experimental.js       |   6 +-
 ambari-web/test/views/application_test.js  | 173 ++++++++++++++++++++++++
 ambari-web/test/views/experimental_test.js | 104 ++++++++++++++
 ambari-web/test/views/installer_test.js    |  54 ++++++++
 ambari-web/test/views/login_test.js        |  56 ++++++++
 6 files changed, 394 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f04324e0/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 2db199d..d9d61d7 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -172,6 +172,10 @@ require('test/views/wizard/step8_view_test');
 require('test/views/wizard/step9_view_test');
 require('test/views/wizard/step9/hostLogPopupBody_view_test');
 require('test/views/wizard/step10_view_test');
+require('test/views/application_test');
+require('test/views/experimental_test');
+require('test/views/installer_test');
+require('test/views/login_test');
 require('test/models/jobs/job_test');
 require('test/models/jobs/tez_dag_test');
 require('test/models/service/flume_test');

http://git-wip-us.apache.org/repos/asf/ambari/blob/f04324e0/ambari-web/app/views/experimental.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/experimental.js b/ambari-web/app/views/experimental.js
index 5d84c2c..b2c8b0c 100644
--- a/ambari-web/app/views/experimental.js
+++ b/ambari-web/app/views/experimental.js
@@ -21,12 +21,12 @@ App.ExperimentalView = Em.View.extend({
   templateName: require('templates/experimental'),
   supports: function () {
     var supports = [];
-    for ( var sup in App.supports) {
+    Em.keys(App.get('supports')).forEach(function (sup) {
       supports.push(Ember.Object.create({
         name: sup,
-        selected: App.supports[sup]
+        selected: App.get('supports')[sup]
       }));
-    }
+    });
     return supports;
   }.property('App.supports'),
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f04324e0/ambari-web/test/views/application_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/application_test.js b/ambari-web/test/views/application_test.js
new file mode 100644
index 0000000..0fb0911
--- /dev/null
+++ b/ambari-web/test/views/application_test.js
@@ -0,0 +1,173 @@
+/**
+ * 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/application');
+
+var view,
+  modals = [],
+  removed = false,
+  events = [
+    {
+      event: 'keydown',
+      which: 13,
+      key: 'Enter',
+      html: '<div id="modal"><div class="modal-footer"><span class="btn-success"></span></div></div>',
+      particle: '',
+      length: 0
+    },
+    {
+      event: 'keydown',
+      keyCode: 13,
+      key: 'Enter',
+      html: '<div id="modal"><div class="modal-footer"><span class="btn-success"></span></div></div>',
+      particle: '',
+      length: 0
+    },
+    {
+      event: 'keyup',
+      which: 27,
+      key: 'Esc',
+      html: '<div id="modal"><div class="modal-header"><span class="close"></span></div></div>',
+      particle: '',
+      length: 0
+    },
+    {
+      event: 'keyup',
+      keyCode: 27,
+      key: 'Esc',
+      html: '<div id="modal"><div class="modal-header"><span class="close"></span></div></div>',
+      particle: '',
+      length: 0
+    },
+    {
+      event: 'keydown',
+      which: 13,
+      key: 'Enter',
+      html: '<div id="modal"><div class="modal-footer"><span></span></div></div>',
+      particle: 'not ',
+      length: 1
+    },
+    {
+      event: 'keydown',
+      keyCode: 13,
+      key: 'Enter',
+      html: '<div id="modal"><div class="modal-footer"><span></span></div></div>',
+      particle: 'not ',
+      length: 1
+    },
+    {
+      event: 'keyup',
+      which: 27,
+      key: 'Esc',
+      html: '<div id="modal"><div class="modal-header"><span></span></div></div>',
+      particle: 'not ',
+      length: 1
+    },
+    {
+      event: 'keyup',
+      keyCode: 27,
+      key: 'Esc',
+      html: '<div id="modal"><div class="modal-header"><span></span></div></div>',
+      particle: 'not ',
+      length: 1
+    },
+    {
+      event: 'keydown',
+      which: 13,
+      key: 'Enter',
+      html: '<div id="modal"><div class="modal-footer"><span class="btn-success"
disabled="disabled"></span></div></div>',
+      particle: 'not ',
+      length: 1
+    },
+    {
+      event: 'keydown',
+      keyCode: 13,
+      key: 'Enter',
+      html: '<div id="modal"><div class="modal-footer"><span class="btn-success"
disabled="disabled"></span></div></div>',
+      particle: 'not ',
+      length: 1
+    },
+    {
+      event: 'keydown',
+      key: 'Enter',
+      html: '<div id="modal"><div class="modal-footer"><span class="btn-success"></span></div></div>',
+      particle: 'not ',
+      length: 1
+    },
+    {
+      event: 'keyup',
+      key: 'Esc',
+      html: '<div id="modal"><div class="modal-footer"><span class="close"></span></div></div>',
+      particle: 'not ',
+      length: 1
+    }
+  ];
+
+describe('App.ApplicationView', function () {
+
+  before(function () {
+    if($('#modal').length) {
+      removed = true;
+    }
+    while($('#modal').length) {
+      modals.push({
+        modal: $('#modal'),
+        parent: $('modal').parent()
+      });
+      $('#modal').remove();
+    }
+  });
+
+  beforeEach(function () {
+    view = App.ApplicationView.create({
+      template: null
+    });
+  });
+
+  afterEach(function () {
+    $('#modal').remove();
+  });
+
+  after(function () {
+    if (removed) {
+      modals.forEach(function (item) {
+        item.parent.append(item.modal);
+      });
+    }
+  });
+
+  describe('#didInsertElement', function () {
+    events.forEach(function (item) {
+      it('should ' + item.particle + 'close modal window on ' + item.key + ' press', function
() {
+        $('body').append(item.html);
+        $('span').click(function () {
+          $('#modal').remove();
+        });
+        view.didInsertElement();
+        var e = $.Event(item.event);
+        e.which = item.which;
+        e.keyCode = item.keyCode;
+        $(document).trigger(e);
+        expect($('#modal')).to.have.length(item.length);
+      });
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/f04324e0/ambari-web/test/views/experimental_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/experimental_test.js b/ambari-web/test/views/experimental_test.js
new file mode 100644
index 0000000..a2fd79c
--- /dev/null
+++ b/ambari-web/test/views/experimental_test.js
@@ -0,0 +1,104 @@
+/**
+ * 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/experimental');
+
+var view,
+  transition,
+  supports = {},
+  transitionStubbed = false,
+  viewSupports = [
+    Em.Object.create({
+      name: 'sup0',
+      selected: true
+    }),
+    Em.Object.create({
+      name: 'sup1',
+      selected: false
+    })
+  ],
+  saveObject = {};
+
+describe('App.ExperimentalView', function () {
+
+  before(function () {
+    viewSupports.forEach(function(item) {
+      supports[item.get('name')] = item.get('selected');
+    });
+    sinon.stub(App, 'get', function(k) {
+      if (k === 'supports') return supports;
+      return Em.get(App, k);
+    });
+  });
+
+  beforeEach(function () {
+    view = App.ExperimentalView.create();
+  });
+
+  after(function () {
+    App.get.restore();
+  });
+
+  describe('#supports', function () {
+    it('should take data from App.supports', function () {
+      expect(view.get('supports')).to.eql(viewSupports);
+    });
+  });
+
+  describe('#doSave', function () {
+
+    before(function () {
+      sinon.stub(Ember, 'set', function (p, v) {
+        if (p.indexOf('App.supports.' != -1)) {
+          p = p.replace('App.supports.', '');
+          saveObject[p] = v;
+          return;
+        }
+        return Ember.set(p, v);
+      });
+      if (App.router.get('transitionTo') === undefined) {
+        App.router.set('transitionTo', Em.K);
+      } else {
+        sinon.stub(App.router, 'transitionTo', function (k) {
+          if (k === 'root.index') return Em.K;
+          return App.router.transitionTo(k);
+        });
+        transitionStubbed = true;
+      }
+    });
+
+    after(function () {
+      Ember.set.restore();
+      if (transitionStubbed) {
+        App.router.transitionTo.restore();
+      } else {
+        App.router.set('transitionTo', undefined);
+      }
+    });
+
+    it('should pass data to App.supports', function () {
+      view.set('supports', viewSupports);
+      view.doSave();
+      expect(saveObject).to.eql(supports);
+    });
+
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/f04324e0/ambari-web/test/views/installer_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/installer_test.js b/ambari-web/test/views/installer_test.js
new file mode 100644
index 0000000..0450b69
--- /dev/null
+++ b/ambari-web/test/views/installer_test.js
@@ -0,0 +1,54 @@
+/**
+ * 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/installer');
+
+var view,
+  stepsCount = 11,
+  isStepDisabled = [],
+  properties = [];
+
+for (var i = 0; i < stepsCount; i++ ) {
+  isStepDisabled.push(Em.Object.create({
+    step: i,
+    value: Boolean(Math.floor(Math.random() * 2))
+  }));
+  properties.push('isStep' + i + 'Disabled');
+}
+
+describe('App.InstallerView', function () {
+
+  beforeEach(function () {
+    view = App.InstallerView.create({
+      controller: {
+        isStepDisabled: isStepDisabled
+      }
+    });
+  });
+
+  properties.forEach(function (item, index) {
+    describe(item, function () {
+      it('should take value from isStepDisabled', function () {
+        expect(view.get(item)).to.equal(isStepDisabled.findProperty('step', index).get('value'));
+      });
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/f04324e0/ambari-web/test/views/login_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/login_test.js b/ambari-web/test/views/login_test.js
new file mode 100644
index 0000000..844b0f6
--- /dev/null
+++ b/ambari-web/test/views/login_test.js
@@ -0,0 +1,56 @@
+/**
+ * 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/login');
+
+var view,
+  controller,
+  pass;
+
+describe('App.LoginView', function () {
+
+  before(function () {
+    sinon.stub(App, 'get', function(k) {
+      if (k === 'router') return {
+        login: Em.K
+      };
+      return Em.get(App, k);
+    });
+  });
+
+  beforeEach(function () {
+    view = App.LoginView.create();
+    pass = view.passTextField.create({
+      controller: App.LoginController.create()
+    });
+  });
+
+  after(function () {
+    App.get.restore();
+  });
+
+  describe('#passTextField', function () {
+    it('should change error message', function () {
+      pass.insertNewline();
+      expect(pass.get('controller.errorMessage')).to.be.empty;
+    });
+  });
+
+});


Mime
View raw message