浏览代码

AMBARI-14488. Improve Ambari UI UT (p.1) (onechiporenko)

Oleg Nechiporenko 9 年之前
父节点
当前提交
8acfcd8921
共有 53 个文件被更改,包括 2081 次插入975 次删除
  1. 42 22
      ambari-web/test/mixins/common/kdc_credentials_controller_mixin_test.js
  2. 27 12
      ambari-web/test/mixins/common/reload_popup_test.js
  3. 85 39
      ambari-web/test/mixins/common/table_server_view_mixin_test.js
  4. 1 1
      ambari-web/test/mixins/common/widget_mixin_test.js
  5. 41 16
      ambari-web/test/mixins/common/widgets/export_metrics_mixin_test.js
  6. 5 1
      ambari-web/test/mixins/common/widgets/widget_section_test.js
  7. 46 23
      ambari-web/test/mixins/wizard/wizardProgressPageController_test.js
  8. 1 12
      ambari-web/test/models/cluster_states_test.js
  9. 19 9
      ambari-web/test/models/configs/config_group_test.js
  10. 1 1
      ambari-web/test/models/configs/service_config_version_test.js
  11. 19 8
      ambari-web/test/router_test.js
  12. 6 14
      ambari-web/test/utils/ajax/ajax_test.js
  13. 14 8
      ambari-web/test/utils/blueprint_test.js
  14. 211 96
      ambari-web/test/utils/config_test.js
  15. 26 15
      ambari-web/test/utils/configs/config_initializer_test.js
  16. 3 2
      ambari-web/test/utils/host_progress_popup_test.js
  17. 8 3
      ambari-web/test/utils/ui_effects_test.js
  18. 1 1
      ambari-web/test/views/common/chart/linear_time_test.js
  19. 101 46
      ambari-web/test/views/common/configs/config_history_flow_test.js
  20. 46 18
      ambari-web/test/views/common/configs/custom_category_views/notification_configs_view_test.js
  21. 15 6
      ambari-web/test/views/common/configs/service_configs_by_category_view_test.js
  22. 19 8
      ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js
  23. 169 59
      ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
  24. 17 26
      ambari-web/test/views/common/configs/widgets/toggle_config_widget_view_test.js
  25. 103 65
      ambari-web/test/views/common/controls_view_test.js
  26. 50 19
      ambari-web/test/views/common/custom_date_popup_test.js
  27. 8 2
      ambari-web/test/views/common/filter_combo_cleanable_test.js
  28. 66 21
      ambari-web/test/views/common/form/manage_kdc_credentials_form_test.js
  29. 9 2
      ambari-web/test/views/common/modal_popup_test.js
  30. 38 15
      ambari-web/test/views/common/modal_popups/cluster_check_popup_test.js
  31. 24 6
      ambari-web/test/views/common/modal_popups/hosts_table_list_popup_test.js
  32. 37 22
      ambari-web/test/views/common/widget/graph_widget_view_test.js
  33. 5 2
      ambari-web/test/views/main/admin/stack_upgrade/menu_view_test.js
  34. 10 4
      ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js
  35. 5 1
      ambari-web/test/views/main/admin_test.js
  36. 144 67
      ambari-web/test/views/main/charts/heatmap/heatmap_host_test.js
  37. 18 5
      ambari-web/test/views/main/dashboard/widget_test.js
  38. 8 2
      ambari-web/test/views/main/dashboard/widgets/datanode_live_test.js
  39. 6 0
      ambari-web/test/views/main/host/details/host_component_views/datanode_view_test.js
  40. 6 3
      ambari-web/test/views/main/host/menu_test.js
  41. 6 2
      ambari-web/test/views/main/menu_test.js
  42. 42 21
      ambari-web/test/views/main/service/info/metrics/ambari_metrics/regionserver_base_test.js
  43. 175 103
      ambari-web/test/views/main/service/info/summary_test.js
  44. 10 2
      ambari-web/test/views/wizard/step0_view_test.js
  45. 9 2
      ambari-web/test/views/wizard/step10_view_test.js
  46. 55 18
      ambari-web/test/views/wizard/step1_view_test.js
  47. 91 40
      ambari-web/test/views/wizard/step3/hostWarningPopupBody_view_test.js
  48. 18 5
      ambari-web/test/views/wizard/step3_view_test.js
  49. 17 4
      ambari-web/test/views/wizard/step5_view_test.js
  50. 10 4
      ambari-web/test/views/wizard/step6_view_test.js
  51. 18 4
      ambari-web/test/views/wizard/step8_view_test.js
  52. 136 74
      ambari-web/test/views/wizard/step9/hostLogPopupBody_view_test.js
  53. 34 14
      ambari-web/test/views/wizard/step9_view_test.js

+ 42 - 22
ambari-web/test/mixins/common/kdc_credentials_controller_mixin_test.js

@@ -70,6 +70,26 @@ describe('App.KDCCredentialsControllerMixin', function() {
   });
 
   describe('#createKDCCredentials', function() {
+
+    beforeEach(function () {
+      sinon.stub(App, 'get').withArgs('clusterName').returns('testName');
+      sinon.stub(credentialsUtils, 'createCredentials', function() {
+        return resolveWith();
+      });
+      sinon.stub(credentialsUtils, 'updateCredentials', function() {
+        return resolveWith();
+      });
+      mixedObject.reopen({
+        isStorePersisted: true
+      });
+    });
+
+    afterEach(function () {
+      App.get.restore();
+      credentialsUtils.createCredentials.restore();
+      credentialsUtils.updateCredentials.restore();
+    });
+
     var createConfig = function(name, value) {
       return App.ServiceConfigProperty.create({
         name: name,
@@ -164,36 +184,36 @@ describe('App.KDCCredentialsControllerMixin', function() {
         message: 'Save Admin credentials checkbox unchecked, credentials already stored and should be updated as `temporary`'
       }
     ].forEach(function(test) {
-      it(test.message, function() {
-        sinon.stub(App, 'get').withArgs('clusterName').returns('testName');
-        sinon.stub(credentialsUtils, 'getCredential', function(clusterName, alias) {
-          return test.credentialsExists ? resolveWith() : rejectWith();
+      describe(test.message, function() {
+        beforeEach(function () {
+          sinon.stub(credentialsUtils, 'getCredential', function() {
+            return test.credentialsExists ? resolveWith() : rejectWith();
+          });
+          mixedObject.createKDCCredentials(test.configs);
         });
-        sinon.stub(credentialsUtils, 'createCredentials', function() {
-          return resolveWith();
-        });
-        sinon.stub(credentialsUtils, 'updateCredentials', function() {
-          return resolveWith();
+
+        afterEach(function () {
+          credentialsUtils.getCredential.restore();
         });
 
-        mixedObject.reopen({
-          isStorePersisted: function() {
-            return true;
-          }.property()
+        it('credentialsUtils#createCredentials called', function () {
+          expect(credentialsUtils.createCredentials.calledOnce).to.equal(test.createCredentialFnCalled);
         });
-        mixedObject.createKDCCredentials(test.configs);
-        assert.equal(credentialsUtils.createCredentials.calledOnce, test.createCredentialFnCalled,  'credentialsUtils#createCredentials called');
+
         if (test.createCredentialFnCalled) {
-          assert.deepEqual(credentialsUtils.createCredentials.args[0], test.e, 'credentialsUtils#createCredentials called with correct arguments');
+          it('credentialsUtils#createCredentials called with correct arguments', function () {
+            expect(credentialsUtils.createCredentials.args[0]).to.eql(test.e);
+          });
         }
-        credentialsUtils.createCredentials.restore();
-        assert.equal(credentialsUtils.updateCredentials.calledOnce, test.updateCredentialFnCalled, 'credentialUtils#updateCredentials called');
+        it('credentialUtils#updateCredentials called', function () {
+          expect(credentialsUtils.updateCredentials.calledOnce).to.equal(test.updateCredentialFnCalled);
+        });
+
         if (test.updateCredentialFnCalled) {
-          assert.deepEqual(credentialsUtils.updateCredentials.args[0], test.e, 'credentialUtils#updateCredentials called with correct arguments');
+          it('credentialUtils#updateCredentials called with correct arguments', function () {
+            expect(credentialsUtils.updateCredentials.args[0]).to.eql(test.e);
+          });
         }
-        credentialsUtils.updateCredentials.restore();
-        credentialsUtils.getCredential.restore();
-        App.get.restore();
       });
     });
   });

+ 27 - 12
ambari-web/test/mixins/common/reload_popup_test.js

@@ -159,18 +159,33 @@ describe('App.ReloadPopupMixin', function () {
     });
 
     cases.forEach(function (item) {
-      it(item.title, function () {
-        if (!Em.isNone(item.retryCount)) {
-          obj.set('retryCount', item.retryCount);
-        }
-        obj.reloadErrorCallback.apply(obj, item.args);
-        expect(obj.closeReloadPopup.callCount).to.equal(item.closeReloadPopupCallCount);
-        expect(App.ajax.defaultErrorHandler.callCount).to.equal(item.defaultErrorHandlerCallCount);
-        expect(obj.showReloadPopup.callCount).to.equal(item.showReloadPopupCallCount);
-        expect(window.setTimeout.callCount).to.equal(item.setTimeoutCount);
-        if (!Em.isNone(item.retryCountResult)) {
-          obj.set('retryCount', item.retryCountResult);
-        }
+      describe(item.title, function () {
+
+        beforeEach(function () {
+          if (!Em.isNone(item.retryCount)) {
+            obj.set('retryCount', item.retryCount);
+          }
+          obj.reloadErrorCallback.apply(obj, item.args);
+        });
+
+        afterEach(function () {
+          if (!Em.isNone(item.retryCountResult)) {
+            obj.set('retryCount', item.retryCountResult);
+          }
+        });
+
+        it('closeReloadPopup is called needed number of times', function () {
+          expect(obj.closeReloadPopup.callCount).to.equal(item.closeReloadPopupCallCount);
+        });
+        it('defaultErrorHandler is called needed number of times', function () {
+          expect(App.ajax.defaultErrorHandler.callCount).to.equal(item.defaultErrorHandlerCallCount);
+        });
+        it('showReloadPopup is called needed number of times', function () {
+          expect(obj.showReloadPopup.callCount).to.equal(item.showReloadPopupCallCount);
+        });
+        it('setTimeout is called needed number of times', function () {
+          expect(window.setTimeout.callCount).to.equal(item.setTimeoutCount);
+        });
       });
     });
 

+ 85 - 39
ambari-web/test/mixins/common/table_server_view_mixin_test.js

@@ -82,53 +82,99 @@ describe('App.MainConfigHistoryView', function() {
       App.db.setDisplayLength.restore();
     });
 
-    it('displayLength is correct', function() {
-      view.set('displayLength', '50');
-      view.set('startIndex', null);
+    describe('displayLength is correct', function() {
+      beforeEach(function () {
+        view.set('displayLength', '50');
+        view.set('startIndex', null);
+        view.updatePagination();
+      });
 
-      view.updatePagination();
-
-      expect(view.refresh.calledOnce).to.be.true;
-      expect(App.db.setStartIndex.called).to.be.false;
-      expect(App.db.setDisplayLength.calledWith('mainConfigHistoryController', '50')).to.be.true;
-      expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(0);
-      expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('50');
+      it('refresh is called once', function () {
+        expect(view.refresh.calledOnce).to.be.true;
+      });
+      it('setStartIndex is called once', function () {
+        expect(App.db.setStartIndex.called).to.be.false;
+      });
+      it('setDisplayLength is called with correct arguments', function () {
+        expect(App.db.setDisplayLength.calledWith('mainConfigHistoryController', '50')).to.be.true;
+      });
+      it('paginationProps.startIndex = 0', function () {
+        expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(0);
+      });
+      it('paginationProps.displayLength = 50', function () {
+        expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('50');
+      });
     });
-    it('startIndex is correct', function() {
-      view.set('displayLength', null);
-      view.set('startIndex', 10);
 
-      view.updatePagination();
+    describe('startIndex is correct', function() {
 
-      expect(view.refresh.calledOnce).to.be.true;
-      expect(App.db.setStartIndex.calledWith('mainConfigHistoryController', 10)).to.be.true;
-      expect(App.db.setDisplayLength.called).to.be.false;
-      expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(10);
-      expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('50');
+      beforeEach(function () {
+        view.set('displayLength', null);
+        view.set('startIndex', 10);
+        view.updatePagination();
+      });
+      it('refresh is called once', function () {
+        expect(view.refresh.calledOnce).to.be.true;
+      });
+      it('setStartIndex is called with valid arguments', function () {
+        expect(App.db.setStartIndex.calledWith('mainConfigHistoryController', 10)).to.be.true;
+      });
+      it('setDisplayLength is not called', function () {
+        expect(App.db.setDisplayLength.called).to.be.false;
+      });
+      it('paginationProps.startIndex = 10', function () {
+        expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(10);
+      });
+      it('paginationProps.displayLength = 50', function () {
+        expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('50');
+      });
     });
-    it('displayLength and startIndex are correct', function() {
-      view.set('displayLength', '100');
-      view.set('startIndex', 20);
 
-      view.updatePagination();
+    describe('displayLength and startIndex are correct', function() {
+      beforeEach(function () {
+        view.set('displayLength', '100');
+        view.set('startIndex', 20);
+        view.updatePagination();
+      });
 
-      expect(view.refresh.calledOnce).to.be.true;
-      expect(App.db.setStartIndex.calledWith('mainConfigHistoryController', 20)).to.be.true;
-      expect(App.db.setDisplayLength.calledWith('mainConfigHistoryController', '100')).to.be.true;
-      expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(20);
-      expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('100');
+      it('refresh is called once', function () {
+        expect(view.refresh.calledOnce).to.be.true;
+      });
+      it('setStartIndex is called with valid arguments', function () {
+        expect(App.db.setStartIndex.calledWith('mainConfigHistoryController', 20)).to.be.true;
+      });
+      it('setDisplayLength is called with valid arguments', function () {
+        expect(App.db.setDisplayLength.calledWith('mainConfigHistoryController', '100')).to.be.true;
+      });
+      it('paginationProps.startIndex = 20', function () {
+        expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(20);
+      });
+      it('paginationProps.displayLength = 100', function () {
+        expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('100');
+      });
     });
-    it('displayLength and startIndex are null', function() {
-      view.set('displayLength', null);
-      view.set('startIndex', null);
 
-      view.updatePagination();
-
-      expect(view.refresh.calledOnce).to.be.true;
+    describe('displayLength and startIndex are null', function() {
+      beforeEach(function () {
+        view.set('displayLength', null);
+        view.set('startIndex', null);
+        view.updatePagination();
+      });
+      it('refresh is called once', function () {
+        expect(view.refresh.calledOnce).to.be.true;
+      });
+      it('setStartIndex is not called', function () {
       expect(App.db.setStartIndex.called).to.be.false;
+      });
+      it('setDisplayLength is not called', function () {
       expect(App.db.setDisplayLength.called).to.be.false;
+      });
+      it('paginationProps.startIndex = 20', function () {
       expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(20);
-      expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('100');
+      });
+      it('paginationProps.displayLength = 100', function () {
+        expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('100');
+      });
     });
   });
 
@@ -137,14 +183,16 @@ describe('App.MainConfigHistoryView', function() {
       sinon.stub(view, 'saveFilterConditions', Em.K);
       sinon.stub(view, 'refresh', Em.K);
       sinon.spy(view, 'updateFilter');
+      this.clock = sinon.useFakeTimers();
     });
     afterEach(function () {
       view.saveFilterConditions.restore();
       view.updateFilter.restore();
       view.refresh.restore();
+      this.clock.restore();
     });
     it('filteringComplete is false', function() {
-      this.clock = sinon.useFakeTimers();
+
 
       view.set('filteringComplete', false);
       view.updateFilter(1, '1', 'string');
@@ -153,7 +201,7 @@ describe('App.MainConfigHistoryView', function() {
       view.set('filteringComplete', true);
       this.clock.tick(view.get('filterWaitingTime'));
       expect(view.updateFilter.calledWith(1, '1', 'string')).to.be.true;
-      this.clock.restore();
+
     });
     it('filteringComplete is true', function() {
       view.set('filteringComplete', true);
@@ -165,7 +213,6 @@ describe('App.MainConfigHistoryView', function() {
     });
 
     it('clear filters - refresh() clears timer', function () {
-      this.clock = sinon.useFakeTimers();
 
       //clear filters simulation
       view.set('filteringComplete', false);
@@ -179,7 +226,6 @@ describe('App.MainConfigHistoryView', function() {
 
       //should not call update filter again
       expect(view.updateFilter.calledOnce).to.be.true;
-      this.clock.restore();
     })
   });
 

+ 1 - 1
ambari-web/test/mixins/common/widget_mixin_test.js

@@ -417,7 +417,7 @@ describe('App.WidgetLoadAggregator', function () {
       expect(aggregator.get('requests')).to.not.be.empty;
       expect(window.setTimeout.called).to.be.false;
     });
-    it("timeout started", function () {
+    it("timeout started (2)", function () {
       aggregator.set('timeoutId', null);
       aggregator.get('requests').clear();
       aggregator.add({});

+ 41 - 16
ambari-web/test/mixins/common/widgets/export_metrics_mixin_test.js

@@ -90,16 +90,28 @@ describe('App.ExportMetricsMixin', function () {
     });
 
     cases.forEach(function (item) {
-      it(item.title, function () {
-        obj.set('isExportMenuHidden', item.isExportMenuHidden);
-        obj.exportGraphData(item.event);
-        var ajaxParams = App.ajax.send.firstCall.args[0];
-        expect(obj.get('isExportMenuHidden')).to.be.true;
-        expect(App.ajax.send.calledOnce).to.be.true;
-        expect(ajaxParams.name).to.equal('index');
-        expect(ajaxParams.data).to.eql({
-          p: 'v',
-          isCSV: item.isCSV
+      describe(item.title, function () {
+
+        beforeEach(function () {
+          obj.set('isExportMenuHidden', item.isExportMenuHidden);
+          obj.exportGraphData(item.event);
+          this.ajaxParams = App.ajax.send.firstCall.args[0];
+        });
+
+        it('isExportMenuHidden is true', function () {
+          expect(obj.get('isExportMenuHidden')).to.be.true;
+        });
+        it('one request was done', function () {
+          expect(App.ajax.send.calledOnce).to.be.true;
+        });
+        it('request to the valid end-point', function () {
+          expect(this.ajaxParams.name).to.equal('index');
+        });
+        it('ajax-request with correct data', function () {
+          expect(this.ajaxParams.data).to.eql({
+            p: 'v',
+            isCSV: item.isCSV
+          });
         });
       });
     });
@@ -197,13 +209,26 @@ describe('App.ExportMetricsMixin', function () {
     });
 
     cases.forEach(function (item) {
-      it(item.title, function () {
-        obj.exportGraphDataSuccessCallback(item.response, null, item.params);
-        expect(fileUtils.downloadTextFile.callCount).to.equal(item.downloadTextFileCallCount);
+      describe(item.title, function () {
+
+        beforeEach(function () {
+          obj.exportGraphDataSuccessCallback(item.response, null, item.params);
+        });
+
+        it('downloadTextFile was called needed number of times', function () {
+          expect(fileUtils.downloadTextFile.callCount).to.equal(item.downloadTextFileCallCount);
+        });
+
         if (item.downloadTextFileCallCount) {
-          expect(fileUtils.downloadTextFile.firstCall.args[0].replace(/\s/g, '')).to.equal(item.data);
-          expect(fileUtils.downloadTextFile.firstCall.args[1]).to.equal(item.fileType);
-          expect(fileUtils.downloadTextFile.firstCall.args[2]).to.equal(item.fileName);
+          it('data is valid', function () {
+            expect(fileUtils.downloadTextFile.firstCall.args[0].replace(/\s/g, '')).to.equal(item.data);
+          });
+          it('fileType is valid', function () {
+            expect(fileUtils.downloadTextFile.firstCall.args[1]).to.equal(item.fileType);
+          });
+          it('fileName is valid', function () {
+            expect(fileUtils.downloadTextFile.firstCall.args[2]).to.equal(item.fileName);
+          });
         }
       });
     });

+ 5 - 1
ambari-web/test/mixins/common/widgets/widget_section_test.js

@@ -47,13 +47,17 @@ describe('App.WidgetSectionMixin', function () {
       }
     ];
 
+    beforeEach(function () {
+      this.stub = sinon.stub(App.Service, 'find');
+    });
+
     afterEach(function () {
       App.Service.find.restore();
     });
 
     cases.forEach(function (item) {
       it(item.title, function () {
-        sinon.stub(App.Service, 'find').returns(item.services);
+        this.stub.returns(item.services);
         expect(obj.get('isAmbariMetricsInstalled')).to.equal(item.isAmbariMetricsInstalled);
       });
     });

+ 46 - 23
ambari-web/test/mixins/wizard/wizardProgressPageController_test.js

@@ -86,31 +86,54 @@ describe('App.wizardProgressPageControllerMixin', function() {
       expect(mixedObjectInstance.checkInstalledComponents.calledWith('ZOOKEEPER_SERVER', ['host1'])).to.be.true;
     });
 
-    it('no ZooKeeper Servers installed. install on host1, host2. ajax request should be called with appropriate params', function() {
-      mixedObjectInstance.createComponent('ZOOKEEPER_SERVER', ['host1', 'host2'], 'ZOOKEEPER');
-      var args = App.ajax.send.args[0][0];
-
-      var queryObject = JSON.parse(args.data.data);
-      expect(args.data.hostName).to.be.eql(['host1', 'host2']);
-      expect(queryObject.RequestInfo.query).to.be.eql('Hosts/host_name=host1|Hosts/host_name=host2');
-      expect(queryObject.Body.host_components[0].HostRoles.component_name).to.be.eql('ZOOKEEPER_SERVER');
-      expect(args.data.taskNum).to.be.eql(1);
-      // invoke callback
-      args.sender[args.success].apply(args.sender, [null, null, args.data]);
-      expect(mixedObjectInstance.updateComponent.called).to.be.true;
+    describe('no ZooKeeper Servers installed. install on host1, host2. ajax request should be called with appropriate params', function() {
+      beforeEach(function () {
+        mixedObjectInstance.createComponent('ZOOKEEPER_SERVER', ['host1', 'host2'], 'ZOOKEEPER');
+        this.args = App.ajax.send.args[0][0];
+        this.queryObject = JSON.parse(this.args.data.data);
+      });
+      it('hostName is valid array', function () {
+        expect(this.args.data.hostName).to.be.eql(['host1', 'host2']);
+      });
+      it('RequestInfo.query is valid', function () {
+        expect(this.queryObject.RequestInfo.query).to.be.eql('Hosts/host_name=host1|Hosts/host_name=host2');
+      });
+      it('affected component is valid', function () {
+        expect(this.queryObject.Body.host_components[0].HostRoles.component_name).to.be.eql('ZOOKEEPER_SERVER');
+      });
+      it('taskNum = 1', function () {
+        expect(this.args.data.taskNum).to.be.eql(1);
+      });
+      it('updateComponent is called', function () {
+        // invoke callback
+        this.args.sender[this.args.success].apply(this.args.sender, [null, null, this.args.data]);
+        expect(mixedObjectInstance.updateComponent.called).to.be.true;
+      });
     });
 
-    it('ZooKeeper Client installed on host1. install on host1, host2. ajax request should be called with appropriate params', function() {
-      mixedObjectInstance.createComponent('ZOOKEEPER_CLIENT', ['host1', 'host2'], 'ZOOKEEPER');
-      var args = App.ajax.send.args[0][0];
-      var queryObject = JSON.parse(args.data.data);
-      expect(args.data.hostName).to.be.eql(['host1', 'host2']);
-      expect(queryObject.RequestInfo.query).to.be.eql('Hosts/host_name=host2');
-      expect(queryObject.Body.host_components[0].HostRoles.component_name).to.be.eql('ZOOKEEPER_CLIENT');
-      expect(mixedObjectInstance.onCreateComponent.called).to.be.false;
-      // invoke callback
-      args.sender[args.success].apply(args.sender, [null, null, args.data]);
-      expect(mixedObjectInstance.updateComponent.called).to.be.true;
+    describe('ZooKeeper Client installed on host1. install on host1, host2. ajax request should be called with appropriate params', function() {
+      beforeEach(function () {
+        mixedObjectInstance.createComponent('ZOOKEEPER_CLIENT', ['host1', 'host2'], 'ZOOKEEPER');
+        this.args = App.ajax.send.args[0][0];
+        this.queryObject = JSON.parse(this.args.data.data);
+      });
+      it('hostName is valid array', function () {
+        expect(this.args.data.hostName).to.be.eql(['host1', 'host2']);
+      });
+      it('RequestInfo.query is valid', function () {
+        expect(this.queryObject.RequestInfo.query).to.be.eql('Hosts/host_name=host2');
+      });
+      it('affected component is valid', function () {
+        expect(this.queryObject.Body.host_components[0].HostRoles.component_name).to.be.eql('ZOOKEEPER_CLIENT');
+      });
+      it('onCreateComponent is not called', function () {
+        expect(mixedObjectInstance.onCreateComponent.called).to.be.false;
+      });
+      it('updateComponent is called', function () {
+        // invoke callback
+        this.args.sender[this.args.success].apply(this.args.sender, [null, null, this.args.data]);
+        expect(mixedObjectInstance.updateComponent.called).to.be.true;
+      });
     });
   });
 

+ 1 - 12
ambari-web/test/models/cluster_states_test.js

@@ -72,6 +72,7 @@ describe('App.clusterStatus', function () {
   describe('#setClusterStatus', function () {
 
     beforeEach(function() {
+      sinon.stub(App, 'get').withArgs('testMode').returns(false);
       sinon.stub(status, 'postUserPref', function() {
         return $.ajax();
       });
@@ -82,19 +83,7 @@ describe('App.clusterStatus', function () {
       App.get.restore();
     });
 
-    it('should return false in test mode', function () {
-      sinon.stub(App, 'get', function(k) {
-        if (k === 'testMode') return true;
-        return Em.get(App, k);
-      });
-      expect(status.setClusterStatus()).to.be.false;
-    });
-
     it('should set cluster status in non-test mode', function () {
-      sinon.stub(App, 'get', function(k) {
-        if (k === 'testMode') return false;
-        return Em.get(App, k);
-      });
       var clusterStatus = status.setClusterStatus(newValue);
       expect(clusterStatus).to.eql(newValue);
     });

+ 19 - 9
ambari-web/test/models/configs/config_group_test.js

@@ -78,21 +78,31 @@ describe('App.ServiceConfigGroup', function () {
       expect(model.get('availableHosts')).to.be.empty;
     });
 
-    it("cluster hosts not used", function() {
+    describe("cluster hosts not used", function() {
       var host = Em.Object.create({
         id: 'g1',
         hostComponents: [{componentName: 'c1'}]
       });
 
-      model.reopen({
-        isDefault: false,
-        clusterHosts: [host]
+      beforeEach(function () {
+        model.reopen({
+          isDefault: false,
+          clusterHosts: [host]
+        });
+        model.set('parentConfigGroup.hosts', ['g1']);
+      });
+      it('availableHosts is not empty', function () {
+        expect(model.get('availableHosts')).to.be.not.empty;
+      });
+      it('1st host is selected', function () {
+        expect(model.get('availableHosts')[0].get('selected')).to.be.false;
+      });
+      it('1st host components are correct', function () {
+        expect(model.get('availableHosts')[0].get('hostComponentNames')).to.eql(['c1']);
+      });
+      it('1st host `host` is correct', function () {
+        expect(model.get('availableHosts')[0].get('host')).to.eql(host);
       });
-      model.set('parentConfigGroup.hosts', ['g1']);
-      expect(model.get('availableHosts')).to.not.be.empty;
-      expect(model.get('availableHosts')[0].get('selected')).to.be.false;
-      expect(model.get('availableHosts')[0].get('hostComponentNames')).to.eql(['c1']);
-      expect(model.get('availableHosts')[0].get('host')).to.eql(host);
     });
   });
 

+ 1 - 1
ambari-web/test/models/configs/service_config_version_test.js

@@ -59,7 +59,7 @@ describe('App.ServiceConfigVersion', function () {
 
   describe("#configGroupName", function() {
 
-    it("default group", function() {
+    it("not default group", function() {
       model.reopen({
         groupName: 'g1',
         isDefault: false

+ 19 - 8
ambari-web/test/router_test.js

@@ -83,6 +83,7 @@ describe('App.Router', function () {
     ];
 
     beforeEach(function () {
+      this.getUser = sinon.stub(App.db, 'getUser');
       App.setProperties({
         isAdmin: false,
         isOperator: false,
@@ -91,12 +92,12 @@ describe('App.Router', function () {
     });
 
     afterEach(function () {
-      App.db.getUser.restore();
+      this.getUser.restore();
     });
 
     cases.forEach(function (item) {
       it(item.title, function () {
-        sinon.stub(App.db, 'getUser').returns(item.user);
+        this.getUser.returns(item.user);
         router.initAdmin();
         expect(App.get('isAdmin')).to.equal(item.isAdmin);
         expect(App.get('isOperator')).to.equal(item.isOperator);
@@ -258,6 +259,7 @@ describe('App.Router', function () {
       expect(App.get('isPermissionDataLoaded')).to.be.true;
       expect(mock.dataLoading.calledOnce).to.be.true;
     });
+
     it("cluster exists, READ privileges", function () {
       var clusterData = {
         items: [{
@@ -448,6 +450,20 @@ describe('App.Router', function () {
   });
 
   describe("#getAuthenticated", function() {
+    var router;
+    beforeEach(function () {
+      router = App.Router.create();
+      this.mockGetCurrentLocationUrl = sinon.stub(router, 'getCurrentLocationUrl');
+      sinon.stub(router, 'redirectByURL', Em.K);
+    });
+
+    afterEach(function () {
+      App.ajax.send.restore();
+      router.getCurrentLocationUrl.restore();
+      router.redirectByURL.restore();
+      this.mockGetCurrentLocationUrl.restore();
+    });
+
     [
       {
         lastSetURL: '/login/local',
@@ -481,7 +497,6 @@ describe('App.Router', function () {
       }
     ].forEach(function(test) {
       it(test.m, function() {
-        var router = App.Router.create();
         var mockCurrentUrl = 'http://localhost:3333/#/some/hash';
         router.set('location.lastSetURL', test.lastSetURL);
         sinon.stub(App.ajax, 'send', function() {
@@ -492,16 +507,12 @@ describe('App.Router', function () {
             complete: function() {}
           };
         });
-        sinon.stub(router, 'getCurrentLocationUrl').returns(mockCurrentUrl);
-        sinon.stub(router, 'redirectByURL', Em.K);
+        this.mockGetCurrentLocationUrl.returns(mockCurrentUrl);
         router.getAuthenticated();
         expect(router.redirectByURL.calledOnce).to.be.eql(test.redirectCalled);
         if (test.redirectCalled) {
           expect(router.redirectByURL.args[0][0]).to.be.eql(JSON.parse(test.responseData.responseText).jwtProviderUrl + encodeURIComponent(mockCurrentUrl));
         }
-        App.ajax.send.restore();
-        router.getCurrentLocationUrl.restore();
-        router.redirectByURL.restore();
       });
     });
 

+ 6 - 14
ambari-web/test/utils/ajax/ajax_test.js

@@ -110,17 +110,14 @@ describe('App.ajax', function() {
 
   describe('#formatRequest', function() {
 
-    it('App.testMode = true', function() {
-      sinon.stub(App, 'get', function(k) {
-        if ('testMode' === k) return true;
-        return Em.get(App, k);
-      });
-      var r = App.ajax.fakeFormatRequest({real:'/', mock: '/some_url'}, {});
-      expect(r.type).to.equal('GET');
-      expect(r.url).to.equal('/some_url');
-      expect(r.dataType).to.equal('json');
+    beforeEach(function () {
+      sinon.stub(App, 'get').withArgs('testMode').returns(false);
+    });
+
+    afterEach(function () {
       App.get.restore();
     });
+
     var tests = [
       {
         urlObj: {
@@ -138,14 +135,9 @@ describe('App.ajax', function() {
     ];
     tests.forEach(function(test) {
       it(test.m, function() {
-        sinon.stub(App, 'get', function(k) {
-          if ('testMode' === k) return false;
-          return Em.get(App, k);
-        });
         var r = App.ajax.fakeFormatRequest(test.urlObj, test.data);
         expect(r.type).to.equal(test.e.type);
         expect(r.url).to.equal(test.e.url);
-        App.get.restore();
       });
     });
   });

+ 14 - 8
ambari-web/test/utils/blueprint_test.js

@@ -387,7 +387,7 @@ describe('utils/blueprint', function() {
   });
 
   describe("#getComponentForHosts()", function() {
-
+    var res;
     beforeEach(function() {
       sinon.stub(App.ClientComponent, 'find').returns([
         Em.Object.create({
@@ -407,6 +407,7 @@ describe('utils/blueprint', function() {
           hostNames: ["host3"]
         })
       ]);
+      res = blueprintUtils.getComponentForHosts();
     });
     afterEach(function() {
       App.ClientComponent.find.restore();
@@ -414,13 +415,18 @@ describe('utils/blueprint', function() {
       App.MasterComponent.find.restore();
     });
 
-    it("generate components to host map", function() {
-      var res = blueprintUtils.getComponentForHosts();
-      expect(res['host1'][0]).to.eql("C1");
-      expect(res['host2'][0]).to.eql("C1");
-      expect(res['host2'][1]).to.eql("C2");
-      expect(res['host3'][0]).to.eql("C2");
-      expect(res['host3'][1]).to.eql("C3");
+    it('map for 3 items is created', function () {
+      expect(Object.keys(res)).to.have.property('length').equal(3);
+    });
+
+    it("host1 map is valid", function() {
+      expect(res.host1.toArray()).to.eql(['C1']);
+    });
+    it("host2 map is valid", function() {
+      expect(res.host2.toArray()).to.eql(['C1', 'C2']);
+    });
+    it("host3 map is valid", function() {
+      expect(res.host3.toArray()).to.eql(['C2', 'C3']);
     });
   });
 

+ 211 - 96
ambari-web/test/utils/config_test.js

@@ -24,10 +24,16 @@ require('models/service/hdfs');
 var setups = require('test/init_model_test');
 var modelSetup = setups.configs;
 
+function dummyCopy(val) {
+  return JSON.parse(JSON.stringify(val));
+}
+
 describe('App.config', function () {
 
   describe('#fileConfigsIntoTextarea', function () {
+
     var filename = 'capacity-scheduler.xml';
+
     var configs = [
       {
         name: 'config1',
@@ -42,69 +48,110 @@ describe('App.config', function () {
         filename: 'capacity-scheduler.xml'
       }
     ];
-    it('two configs into textarea', function () {
-      var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
-      expect(result.length).to.equal(1);
-      expect(result[0].value).to.equal('config1=value1\nconfig2=value2\n');
-      expect(result[0].recommendedValue).to.equal('config1=value1\nconfig2=value2\n');
-    });
-    it('three config into textarea', function () {
-      configs.push({
-        name: 'config3',
-        value: 'value3',
-        recommendedValue: 'value3',
-        filename: 'capacity-scheduler.xml'
+
+    var c3 = {
+      name: 'config3',
+      value: 'value3',
+      recommendedValue: 'value3',
+      filename: 'capacity-scheduler.xml'
+    };
+
+    describe('two configs into textarea', function () {
+      var result;
+      beforeEach(function () {
+        result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
+      });
+      it('One config is returned', function () {
+        expect(result.length).to.equal(1);
+      });
+      it('value is valid', function () {
+        expect(result[0].value).to.equal('config1=value1\nconfig2=value2\n');
+      });
+      it('recommendedValue is valid', function () {
+        expect(result[0].recommendedValue).to.equal('config1=value1\nconfig2=value2\n');
+      });
+    });
+
+    describe('three config into textarea', function () {
+      var newConfigs = dummyCopy(configs);
+      newConfigs.push(dummyCopy(c3));
+      var result;
+      beforeEach(function () {
+        result = App.config.fileConfigsIntoTextarea.call(App.config, newConfigs, filename);
+      });
+      it('One config is returned', function () {
+        expect(result.length).to.equal(1);
+      });
+      it('valid is valid', function () {
+        expect(result[0].value).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
+      });
+      it('recommendedValue is valid', function () {
+        expect(result[0].recommendedValue).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
+      });
+    });
+
+    describe('one of three configs has different filename', function () {
+      var newConfigs = dummyCopy(configs);
+      newConfigs.push(dummyCopy(c3));
+      newConfigs[1].filename = 'another filename';
+      var result;
+
+      beforeEach(function () {
+        result = App.config.fileConfigsIntoTextarea.call(App.config, newConfigs, filename);
+      });
+
+      it('Two configs are returned', function () {
+        //result contains two configs: one with different filename and one textarea config
+        expect(result.length).to.equal(2);
+      });
+      it('Value is valid', function () {
+        expect(result[1].value).to.equal('config1=value1\nconfig3=value3\n');
+      });
+      it('RecommendedValue is valid', function () {
+        expect(result[1].recommendedValue).to.equal('config1=value1\nconfig3=value3\n');
+      });
+    });
+
+    describe('none configs into empty textarea', function () {
+      var result;
+      beforeEach(function () {
+        result = App.config.fileConfigsIntoTextarea.call(App.config, [], 'capacity-scheduler.xml');
+      });
+      it('One config is returned', function () {
+        expect(result.length).to.equal(1);
+      });
+      it('value is empty', function () {
+        expect(result[0].value).to.equal('');
+      });
+      it('recommendedValue is none', function () {
+        expect(Em.isNone(result[0].recommendedValue)).to.be.true;
+      });
+      it('savedValue is none', function () {
+        expect(Em.isNone(result[0].savedValue)).to.be.true;
+      });
+    });
+
+    describe("filename has configs that shouldn't be included in textarea", function () {
+      var newConfigs = dummyCopy(configs);
+      newConfigs.push(dummyCopy(c3));
+      var result;
+      beforeEach(function () {
+        result = App.config.fileConfigsIntoTextarea.call(App.config, newConfigs, 'capacity-scheduler.xml', [c3]);
+      });
+      it('Two configs are returned', function () {
+        expect(result.length).to.equal(2);
+      });
+      it('value is correct', function () {
+        expect(result[1].value).to.equal('config1=value1\nconfig2=value2\n');
+      });
+      it('recommendedValue is correct', function () {
+        expect(result[1].recommendedValue).to.equal('config1=value1\nconfig2=value2\n');
+      });
+      it('skipped config is correct', function () {
+        expect(newConfigs.findProperty('name', 'config3')).to.eql(c3);
       });
-      var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
-      expect(result.length).to.equal(1);
-      expect(result[0].value).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
-      expect(result[0].recommendedValue).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
-    });
-    it('one of three configs has different filename', function () {
-      configs[1].filename = 'another filename';
-      var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
-      //result contains two configs: one with different filename and one textarea config
-      expect(result.length).to.equal(2);
-      expect(result[1].value).to.equal('config1=value1\nconfig3=value3\n');
-      expect(result[1].recommendedValue).to.equal('config1=value1\nconfig3=value3\n');
-    });
-    it('none configs into empty textarea', function () {
-      filename = 'capacity-scheduler.xml';
-      configs.clear();
-      var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
-      expect(result.length).to.equal(1);
-      expect(result[0].value).to.equal('');
-      expect(Em.isNone(result[0].recommendedValue)).to.be.true;
-      expect(Em.isNone(result[0].savedValue)).to.be.true;
-    });
-    it("filename has configs that shouldn't be included in textarea", function () {
-      var configs = [
-        {
-          name: 'config1',
-          value: 'value1',
-          recommendedValue: 'value1',
-          filename: filename
-        },
-        {
-          name: 'config2',
-          value: 'value2',
-          recommendedValue: 'value2',
-          filename: filename
-        }
-      ];
-      var cfg = {
-        name: 'config3',
-        value: 'value3',
-        recommendedValue: 'value3',
-        filename: filename
-      };
-      configs.push(cfg);
-      var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename, [cfg]);
-      expect(result.length).to.equal(2);
-      expect(result[1].value).to.equal('config1=value1\nconfig2=value2\n');
-      expect(result[1].recommendedValue).to.equal('config1=value1\nconfig2=value2\n');
-      expect(configs.findProperty('name', 'config3')).to.eql(cfg);
     });
+
   });
 
   describe('#textareaIntoFileConfigs', function () {
@@ -144,35 +191,85 @@ describe('App.config', function () {
       }
     ];
 
-    it('config1=value1 to one config', function () {
-      var result = App.config.textareaIntoFileConfigs.call(App.config, testData[0].configs, filename);
-      expect(result.length).to.equal(1);
-      expect(result[0].value).to.equal('value1');
-      expect(result[0].name).to.equal('config1');
-      expect(result[0].isRequiredByAgent).to.be.true;
-    });
-    it('config1=value1\\nconfig2=value2\\n to two configs', function () {
-      var result = App.config.textareaIntoFileConfigs.call(App.config, testData[1].configs, filename);
-      expect(result.length).to.equal(2);
-      expect(result[0].value).to.equal('value1');
-      expect(result[0].name).to.equal('config1');
-      expect(result[1].value).to.equal('value2');
-      expect(result[1].name).to.equal('config2');
-      expect(result[0].isRequiredByAgent).to.be.false;
-      expect(result[1].isRequiredByAgent).to.be.false;
-    });
-    it('config1=value1,value2\n to one config', function () {
-      var result = App.config.textareaIntoFileConfigs.call(App.config, testData[2].configs, filename);
-      expect(result.length).to.equal(1);
-      expect(result[0].value).to.equal('value1,value2');
-      expect(result[0].name).to.equal('config1');
-      expect(result[0].isRequiredByAgent).to.be.true;
-    });
-    it('config1=value1 config2=value2 to two configs', function () {
-      var result = App.config.textareaIntoFileConfigs.call(App.config, testData[3].configs, filename);
-      expect(result.length).to.equal(1);
-      expect(result[0].isRequiredByAgent).to.be.false;
+    describe('config1=value1 to one config', function () {
+      var result;
+      beforeEach(function () {
+        result = App.config.textareaIntoFileConfigs.call(App.config, testData[0].configs, filename);
+      });
+      it('One config is returned', function () {
+        expect(result.length).to.equal(1);
+      });
+      it('value is correct', function () {
+        expect(result[0].value).to.equal('value1');
+      });
+      it('name is correct', function () {
+        expect(result[0].name).to.equal('config1');
+      });
+      it('isRequiredByAgent is true', function () {
+        expect(result[0].isRequiredByAgent).to.be.true;
+      });
+    });
+
+    describe('config1=value1\\nconfig2=value2\\n to two configs', function () {
+      var result;
+      beforeEach(function () {
+        result = App.config.textareaIntoFileConfigs.call(App.config, testData[1].configs, filename);
+      });
+      it('Two configs are returned', function (){
+        expect(result.length).to.equal(2);
+      });
+      it('1st value is valid', function (){
+        expect(result[0].value).to.equal('value1');
+      });
+      it('1st name is valid', function (){
+        expect(result[0].name).to.equal('config1');
+      });
+      it('2nd value is valid', function (){
+        expect(result[1].value).to.equal('value2');
+      });
+      it('2nd name is valid', function (){
+        expect(result[1].name).to.equal('config2');
+      });
+      it('1st isRequiredByAgent is false', function (){
+        expect(result[0].isRequiredByAgent).to.be.false;
+      });
+      it('2nd isRequiredByAgent is false', function (){
+        expect(result[1].isRequiredByAgent).to.be.false;
+      });
+    });
+
+    describe('config1=value1,value2\n to one config', function () {
+      var result;
+      beforeEach(function () {
+        result = App.config.textareaIntoFileConfigs.call(App.config, testData[2].configs, filename);
+      });
+      it('One config is returned', function () {
+        expect(result.length).to.equal(1);
+      });
+      it('value is correct', function () {
+        expect(result[0].value).to.equal('value1,value2');
+      });
+      it('name is correct', function () {
+        expect(result[0].name).to.equal('config1');
+      });
+      it('isRequiredByAgent is true', function () {
+        expect(result[0].isRequiredByAgent).to.be.true;
+      });
     });
+
+    describe('config1=value1 config2=value2 to two configs', function () {
+      var result;
+      beforeEach(function () {
+        result = App.config.textareaIntoFileConfigs.call(App.config, testData[3].configs, filename);
+      });
+      it('One config is returned', function () {
+        expect(result.length).to.equal(1);
+      });
+      it('isRequiredByAgent is false', function () {
+        expect(result[0].isRequiredByAgent).to.be.false;
+      });
+    });
+
   });
 
   describe('#trimProperty',function() {
@@ -584,12 +681,23 @@ describe('App.config', function () {
       }
     });
 
-    it('overrides some values that should be different for override', function() {
-      var override = App.config.createOverride(configProperty, {}, group);
-      expect(override.get('isOriginalSCP')).to.be.false;
-      expect(override.get('overrides')).to.be.null;
-      expect(override.get('group')).to.eql(group);
-      expect(override.get('parentSCP')).to.eql(configProperty);
+    describe('overrides some values that should be different for override', function() {
+      var override;
+      beforeEach(function () {
+        override = App.config.createOverride(configProperty, {}, group);
+      });
+      it('isOriginalSCP is false', function () {
+        expect(override.get('isOriginalSCP')).to.be.false;
+      });
+      it('overrides is null', function () {
+        expect(override.get('overrides')).to.be.null;
+      });
+      it('group is valid', function () {
+        expect(override.get('group')).to.eql(group);
+      });
+      it('parentSCP is valid', function () {
+        expect(override.get('parentSCP')).to.eql(configProperty);
+      });
     });
 
     it('overrides some specific values', function() {
@@ -868,10 +976,16 @@ describe('App.config', function () {
     it('create default config object', function () {
       expect(App.config.createDefaultConfig('pName', 'pServiceName', 'pFileName', true)).to.eql(res);
     });
-    it('runs proper methods', function() {
+    it('getDefaultDisplayType is called', function() {
       expect(App.config.getDefaultDisplayType.called).to.be.true;
+    });
+    it('getDefaultCategory is called with correct arguments', function() {
       expect(App.config.getDefaultCategory.calledWith(true, 'pFileName')).to.be.true;
+    });
+    it('getIsSecure is called with correct arguments', function() {
       expect(App.config.getIsSecure.calledWith('pName')).to.be.true;
+    });
+    it('shouldSupportFinal is called with correct arguments', function() {
       expect(App.config.shouldSupportFinal.calledWith('pServiceName', 'pFileName')).to.be.true;
     });
   });
@@ -1103,4 +1217,5 @@ describe('App.config', function () {
       expect(App.config.truncateGroupName('group_has_more_than_max_characters')).to.equal('group_has...haracters');
     });
   });
+
 });

+ 26 - 15
ambari-web/test/utils/configs/config_initializer_test.js

@@ -347,23 +347,34 @@ describe('App.ConfigInitializer', function () {
       });
     });
 
-    cases['hive_database'].forEach(function (item) {
-      var title = 'hive_database value should be set to {0}';
-      it(title.format(item.value), function () {
-        sinon.stub(App, 'get')
-          .withArgs('supports.alwaysEnableManagedMySQLForHive').returns(item.alwaysEnableManagedMySQLForHive)
-          .withArgs('router.currentState.name').returns(item.currentStateName)
-          .withArgs('isManagedMySQLForHiveEnabled').returns(item.isManagedMySQLForHiveEnabled);
-        serviceConfigProperty.setProperties({
-          name: 'hive_database',
-          value: item.receivedValue,
-          options: item.options
-        });
-        App.ConfigInitializer.initialValue(serviceConfigProperty, {}, []);
-        expect(serviceConfigProperty.get('value')).to.equal(item.value);
-        expect(serviceConfigProperty.get('options').findProperty('displayName', 'New MySQL Database').hidden).to.equal(item.hidden);
+    describe('hive_database', function () {
+
+      beforeEach(function () {
+        this.stub = sinon.stub(App, 'get');
+      });
+
+      afterEach(function () {
         App.get.restore();
       });
+
+      cases['hive_database'].forEach(function (item) {
+        var title = 'hive_database value should be set to {0}';
+        it(title.format(item.value), function () {
+          this.stub
+            .withArgs('supports.alwaysEnableManagedMySQLForHive').returns(item.alwaysEnableManagedMySQLForHive)
+            .withArgs('router.currentState.name').returns(item.currentStateName)
+            .withArgs('isManagedMySQLForHiveEnabled').returns(item.isManagedMySQLForHiveEnabled);
+          serviceConfigProperty.setProperties({
+            name: 'hive_database',
+            value: item.receivedValue,
+            options: item.options
+          });
+          App.ConfigInitializer.initialValue(serviceConfigProperty, {}, []);
+          expect(serviceConfigProperty.get('value')).to.equal(item.value);
+          expect(serviceConfigProperty.get('options').findProperty('displayName', 'New MySQL Database').hidden).to.equal(item.hidden);
+        });
+      });
+
     });
 
     cases['hbase.zookeeper.quorum'].forEach(function (item) {

+ 3 - 2
ambari-web/test/utils/host_progress_popup_test.js

@@ -453,6 +453,7 @@ describe('App.HostPopup', function () {
     beforeEach(function (){
       sinon.stub(App.HostPopup, "get").returns(true);
       sinon.spy(App.HostPopup, "set");
+      this.stub = sinon.stub(App.router, "get");
     });
 
     afterEach(function (){
@@ -462,14 +463,14 @@ describe('App.HostPopup', function () {
     });
 
     it("should display '2 Background Operations Running' when there are 2 background operations running", function(){
-      sinon.stub(App.router, "get").returns(2);
+      this.stub.returns(2);
       App.HostPopup.setBackgroundOperationHeader(false);
 
       expect(App.HostPopup.set.calledWith("popupHeaderName", "2 Background Operations Running")).to.be.true;
     });
 
     it("should display '1 Background Operation Running' when there is 1 background operation running", function(){
-      sinon.stub(App.router, "get").returns(1);
+      this.stub.returns(1);
       App.HostPopup.setBackgroundOperationHeader(false);
 
       expect(App.HostPopup.set.calledWith("popupHeaderName", "1 Background Operation Running")).to.be.true;

+ 8 - 3
ambari-web/test/utils/ui_effects_test.js

@@ -24,6 +24,12 @@ describe('utils/ui_effects', function(){
     beforeEach(function(){
       $('body').append('<div id="pulsate-test-dom"></div>');
       this.clock = sinon.useFakeTimers();
+      this.clb = Em.K;
+      sinon.spy(this, 'clb');
+    });
+
+    afterEach(function () {
+      this.clb.restore();
     });
 
     it('opacity should be 0.2 on 5-th iteration', function() {
@@ -34,10 +40,9 @@ describe('utils/ui_effects', function(){
     });
     it('should call callback at the end', function() {
       var domEl = $('#pulsate-test-dom');
-      var stub = sinon.stub();
-      ui_utils.pulsate(domEl, 1000, stub);
+      ui_utils.pulsate(domEl, 1000, this.clb);
       this.clock.tick(2000);
-      expect(stub.calledOnce).to.be.ok;
+      expect(this.clb.calledOnce).to.be.ok;
     });
 
     afterEach(function(){

+ 1 - 1
ambari-web/test/views/common/chart/linear_time_test.js

@@ -370,7 +370,7 @@ describe('App.ChartLinearTimeView.LoadAggregator', function () {
       expect(aggregator.get('requests')).to.not.be.empty;
       expect(window.setTimeout.called).to.be.false;
     });
-    it("timeout started", function () {
+    it("timeout started (2)", function () {
       aggregator.set('timeoutId', null);
       aggregator.get('requests').clear();
       aggregator.add({}, {});

+ 101 - 46
ambari-web/test/views/common/configs/config_history_flow_test.js

@@ -305,54 +305,91 @@ describe.skip('App.ConfigHistoryFlowView', function () {
   });
 
   describe('#willInsertElement()', function () {
+
     beforeEach(function () {
       sinon.stub(view, 'adjustFlowView', Em.K);
       sinon.stub(view, 'keepInfoBarAtTop', Em.K);
     });
+
     afterEach(function () {
       view.adjustFlowView.restore();
       view.keepInfoBarAtTop.restore();
     });
-    it('Only current version is present', function () {
-      view.set('serviceVersions', [Em.Object.create({isCurrent: true})]);
 
-      view.willInsertElement();
-      expect(view.adjustFlowView.calledOnce).to.be.true;
-      expect(view.keepInfoBarAtTop.calledOnce).to.be.true;
-      expect(view.get('startIndex')).to.equal(0);
-      expect(view.get('serviceVersions').mapProperty('isDisplayed')).to.eql([true]);
+    describe('Only current version is present', function () {
+
+      beforeEach(function () {
+        view.set('serviceVersions', [Em.Object.create({isCurrent: true})]);
+        view.willInsertElement();
+      });
+
+      it('adjustFlowView is called once', function () {
+        expect(view.adjustFlowView.calledOnce).to.be.true;
+      });
+      it('keepInfoBarAtTop is called once', function () {
+        expect(view.keepInfoBarAtTop.calledOnce).to.be.true;
+      });
+      it('startIndex = 0', function () {
+        expect(view.get('startIndex')).to.equal(0);
+      });
+      it('serviceVersions.@each.isDisplayed = [true]', function () {
+        expect(view.get('serviceVersions').mapProperty('isDisplayed')).to.eql([true]);
+      });
     });
-    it('Five service versions are present', function () {
-      view.set('serviceVersions', [
-        Em.Object.create({isCurrent: true}),
-        Em.Object.create(),
-        Em.Object.create(),
-        Em.Object.create(),
-        Em.Object.create()
-      ]);
 
-      view.willInsertElement();
-      expect(view.adjustFlowView.calledOnce).to.be.true;
-      expect(view.keepInfoBarAtTop.calledOnce).to.be.true;
-      expect(view.get('startIndex')).to.equal(0);
-      expect(view.get('serviceVersions').mapProperty('isDisplayed')).to.eql([true, false, false, false, false]);
+    describe('Five service versions are present', function () {
+
+      beforeEach(function () {
+        view.set('serviceVersions', [
+          Em.Object.create({isCurrent: true}),
+          Em.Object.create(),
+          Em.Object.create(),
+          Em.Object.create(),
+          Em.Object.create()
+        ]);
+        view.willInsertElement();
+      });
+      it('adjustFlowView is called once', function () {
+        expect(view.adjustFlowView.calledOnce).to.be.true;
+      });
+      it('keepInfoBarAtTop is called once', function () {
+        expect(view.keepInfoBarAtTop.calledOnce).to.be.true;
+      });
+      it('startIndex = 0', function () {
+        expect(view.get('startIndex')).to.equal(0);
+      });
+      it('serviceVersions.@each.isDisplayed = [true, false, false, false, false]', function () {
+        expect(view.get('serviceVersions').mapProperty('isDisplayed')).to.eql([true, false, false, false, false]);
+      });
     });
-    it('Six service versions are present', function () {
-      view.set('serviceVersions', [
-        Em.Object.create({isCurrent: true}),
-        Em.Object.create(),
-        Em.Object.create(),
-        Em.Object.create(),
-        Em.Object.create(),
-        Em.Object.create()
-      ]);
 
-      view.willInsertElement();
-      expect(view.adjustFlowView.calledOnce).to.be.true;
-      expect(view.keepInfoBarAtTop.calledOnce).to.be.true;
-      expect(view.get('startIndex')).to.equal(1);
-      expect(view.get('serviceVersions').mapProperty('isDisplayed')).to.eql([true, false, false, false, false, false]);
+    describe('Six service versions are present', function () {
+      beforeEach(function () {
+        view.set('serviceVersions', [
+          Em.Object.create({isCurrent: true}),
+          Em.Object.create(),
+          Em.Object.create(),
+          Em.Object.create(),
+          Em.Object.create(),
+          Em.Object.create()
+        ]);
+        view.willInsertElement();
+      });
+
+      it('adjustFlowView is called once', function () {
+        expect(view.adjustFlowView.calledOnce).to.be.true;
+      });
+      it('keepInfoBarAtTop is called once', function () {
+        expect(view.keepInfoBarAtTop.calledOnce).to.be.true;
+      });
+      it('startIndex is 1', function () {
+        expect(view.get('startIndex')).to.equal(1);
+      });
+      it('serviceVersions.@each.isDisplayed = [true, false, false, false, false, false]', function () {
+        expect(view.get('serviceVersions').mapProperty('isDisplayed')).to.eql([true, false, false, false, false, false]);
+      });
     });
+
   });
 
   describe('#setInfoBarPosition()', function () {
@@ -382,12 +419,19 @@ describe.skip('App.ConfigHistoryFlowView', function () {
     var infoBar = {
       css: Em.K
     };
+
+    beforeEach(function () {
+      sinon.spy(infoBar, 'css');
+    });
+
+    afterEach(function () {
+      infoBar.css.restore();
+    });
+
     testCases.forEach(function (test) {
       it('scroll top - ' + test.params.scrollTop + ', default top - ' + test.params.defaultTop, function () {
-        sinon.spy(infoBar, 'css');
         view.setInfoBarPosition(infoBar, test.params.defaultTop, test.params.scrollTop);
         expect(infoBar.css.calledWith('top', test.result)).to.be.true;
-        infoBar.css.restore();
       });
     });
   });
@@ -614,20 +658,25 @@ describe.skip('App.ConfigHistoryFlowView', function () {
   });
 
   describe('#save()', function () {
-    it('modal popup should be displayed', function () {
+
+    beforeEach(function () {
       sinon.stub(App.ModalPopup, 'show', Em.K);
-      view.save();
+      sinon.stub(App.ServiceConfigVersion, 'find').returns([
+        { serviceName: 'service'}
+      ]);
+    });
 
-      expect(App.ModalPopup.show.calledOnce).to.be.true;
+    afterEach(function () {
       App.ModalPopup.show.restore();
+      App.ServiceConfigVersion.find.restore();
+    });
+
+    it('modal popup should be displayed', function () {
+      view.save();
+      expect(App.ModalPopup.show.calledOnce).to.be.true;
     });
 
     it('controller properties should be modified on save', function () {
-      sinon.stub(App.ServiceConfigVersion, 'find').returns([
-        {
-          serviceName: 'service'
-        }
-      ]);
       view.setProperties({
         'serviceName': 'service',
         'controller.saveConfigsFlag': false,
@@ -757,16 +806,22 @@ describe.skip('App.ConfigHistoryFlowView', function () {
       }
     ];
 
+    beforeEach(function () {
+      sinon.stub(view, 'adjustFlowView', Em.K);
+    });
+
+    afterEach(function () {
+      view.adjustFlowView.restore();
+    });
+
     testCases.forEach(function (test) {
       it('start index - ' + test.params.startIndex + ', serviceVersions length - ' + test.params.serviceVersions.length + ', versionIndex - ' + test.params.versionIndex, function () {
-        sinon.stub(view, 'adjustFlowView', Em.K);
         view.set('serviceVersions', test.params.serviceVersions);
         view.set('startIndex', test.params.startIndex);
         view.shiftFlowOnSwitch(test.params.versionIndex);
 
         expect(view.get('startIndex')).to.eql(test.result.startIndex);
         expect(view.adjustFlowView.calledOnce).to.eql(test.result.adjustFlowViewCall);
-        view.adjustFlowView.restore();
       });
     });
   });

+ 46 - 18
ambari-web/test/views/common/configs/custom_category_views/notification_configs_view_test.js

@@ -66,7 +66,7 @@ describe('App.NotificationsConfigsView', function () {
 
     });
 
-    it('should update category configs', function () {
+    describe('should update category configs', function () {
       var configs = [
         Em.Object.create({
           name: "create_notification",
@@ -82,12 +82,21 @@ describe('App.NotificationsConfigsView', function () {
         })
       ];
 
-      view.set('categoryConfigsAll', configs);
-      view.didInsertElement();
-      expect(view.get('createNotification')).to.equal('yes');
-      expect(view.get('tlsOrSsl')).to.equal('ssl');
-      expect(configs.findProperty('name', 'smtp_use_auth').get('value')).to.be.true;
-      expect(view.updateCategoryConfigs.called).to.be.true;
+      beforeEach(function () {
+        view.set('categoryConfigsAll', configs);
+        view.didInsertElement();
+      });
+
+      it('createNotification = yes', function () {
+        expect(view.get('createNotification')).to.equal('yes');
+      });
+      it('tlsOrSsl = ssl', function () {
+        expect(view.get('tlsOrSsl')).to.equal('ssl');
+      });
+      it('updateCategoryConfigs is called once', function () {
+        expect(view.updateCategoryConfigs.called).to.be.true;
+      });
+
     });
   });
 
@@ -218,19 +227,38 @@ describe('App.NotificationsConfigsView', function () {
       config.validate.restore();
     });
 
-    it("flag is true", function () {
-      view.updateConfig(config, true);
-      expect(config.get('isRequired')).to.be.true;
-      expect(config.get('isEditable')).to.be.true;
-      expect(config.validate.calledOnce).to.be.true;
+    describe("flag is true", function () {
+
+      beforeEach(function () {
+        view.updateConfig(config, true);
+      });
+      it('isRequired is true', function () {
+        expect(config.get('isRequired')).to.be.true;
+      });
+      it('isEditable is true', function () {
+        expect(config.get('isEditable')).to.be.true;
+      });
+      it('validate is called once', function () {
+        expect(config.validate.calledOnce).to.be.true;
+      });
     });
 
-    it("flag is false", function () {
-      view.updateConfig(config, false);
-      expect(config.get('isRequired')).to.be.false;
-      expect(config.get('isEditable')).to.be.false;
-      expect(config.get('errorMessage')).to.be.empty;
-      expect(config.validate.called).to.be.false;
+    describe("flag is false", function () {
+      beforeEach(function () {
+        view.updateConfig(config, false);
+      });
+      it('isRequired is false', function () {
+        expect(config.get('isRequired')).to.be.false;
+      });
+      it('isEditable is false', function () {
+        expect(config.get('isEditable')).to.be.false;
+      });
+      it('errorMessage is empty', function () {
+        expect(config.get('errorMessage')).to.be.empty;
+      });
+      it('validate is not called', function () {
+        expect(config.validate.called).to.be.false;
+      });
     });
   });
 });

+ 15 - 6
ambari-web/test/views/common/configs/service_configs_by_category_view_test.js

@@ -180,17 +180,26 @@ describe('App.ServiceConfigsByCategoryView', function () {
       }
     ];
 
+    beforeEach(function () {
+      this._view = App.ServiceConfigsByCategoryView.create({
+        serviceConfigs: Em.A([])
+      });
+      sinon.stub(this._view, 'filteredCategoryConfigs', Em.K);
+    });
+
+    afterEach(function () {
+      this._view.filteredCategoryConfigs.restore();
+      this._view.destroy();
+    });
+
     tests.forEach(function(test) {
       it(test.m, function() {
-        var _view = App.ServiceConfigsByCategoryView.create({
-          serviceConfigs: Em.A([]),
+        this._view.reopen({
           category: test.category,
           categoryConfigs: test.categoryConfigs
         });
-        sinon.stub(_view, 'filteredCategoryConfigs', Em.K);
-        _view.filteredCategoryConfigs.restore();
-        expect(_view.get('isShowBlock')).to.be.eql(test.e);
-        _view.destroy();
+        expect(this._view.get('isShowBlock')).to.be.eql(test.e);
+
       });
     });
   });

+ 19 - 8
ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js

@@ -175,19 +175,30 @@ describe('App.ListConfigWidgetView', function () {
   describe('#toggleOption', function () {
 
     beforeEach(function() {
-      sinon.stub(view, 'sendRequestRorDependentConfigs', Em.K)
+      sinon.stub(view, 'sendRequestRorDependentConfigs', Em.K);
+      view.toggleOption({context: view.get('options')[2]});
     });
     afterEach(function() {
       view.sendRequestRorDependentConfigs.restore();
     });
 
-    it('should doesn\'t do nothing if maximum number of options is selected', function () {
-      view.toggleOption({context: view.get('options')[2]});
-      expect(view.get('options')[2].get('isSelected')).to.be.true;
-      expect(view.get('options')[3].get('isDisabled')).to.be.true;
-      expect(view.get('options')[3].get('isSelected')).to.be.false;
-      expect(view.get('options')[4].get('isDisabled')).to.be.true;
-      expect(view.get('options')[4].get('isSelected')).to.be.false;
+    describe('should doesn\'t do nothing if maximum number of options is selected', function () {
+
+      it('isSelected', function () {
+        expect(view.get('options')[2].get('isSelected')).to.be.true;
+        expect(view.get('options')[3].get('isSelected')).to.be.false;
+        expect(view.get('options')[4].get('isSelected')).to.be.false;
+      });
+
+      it('isDisabled', function () {
+        expect(view.get('options')[3].get('isDisabled')).to.be.true;
+        expect(view.get('options')[4].get('isDisabled')).to.be.true;
+      });
+
+    });
+
+    it('should doesn\'t do nothing if maximum number of options is selected (2)', function () {
+
       view.toggleOption({context: view.get('options')[3]});
       expect(view.get('options')[3].get('isDisabled')).to.be.true;
       expect(view.get('options')[3].get('isSelected')).to.be.false;

+ 169 - 59
ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js

@@ -138,53 +138,162 @@ describe('App.SliderConfigWidgetView', function () {
 
   describe('#mirrorValueObs', function () {
 
-    it('check int', function () {
-      viewInt.set('mirrorValue', 1000);
-      expect(viewInt.get('isMirrorValueValid')).to.be.true;
-      expect(viewInt.get('config.value')).to.equal('1000');
-      expect(viewInt.get('config.errorMessage')).to.equal('');
-      expect(viewInt.get('config.warnMessage')).to.equal('');
-      expect(viewInt.get('config.warn')).to.be.false;
-
-      viewInt.set('mirrorValue', 100500);
-      expect(viewInt.get('isMirrorValueValid')).to.be.false;
-      expect(viewInt.get('config.value')).to.equal('1000');
-      expect(viewInt.get('config.errorMessage')).to.equal('');
-      expect(viewInt.get('config.warnMessage')).to.have.property('length').that.is.least(1);
-      expect(viewInt.get('config.warn')).to.be.true;
+    describe('check int', function () {
+
+      describe('valid value', function () {
+
+        beforeEach(function () {
+          viewInt.set('mirrorValue', 1000);
+        });
+
+        it('isMirrorValueValid is true', function () {
+          expect(viewInt.get('isMirrorValueValid')).to.be.true;
+        });
+        it('config value is 1000', function () {
+          expect(viewInt.get('config.value')).to.equal('1000');
+        });
+        it('errorMessage is empty', function () {
+          expect(viewInt.get('config.errorMessage')).to.equal('');
+        });
+        it('warnMessage is empty', function () {
+          expect(viewInt.get('config.warnMessage')).to.equal('');
+        });
+        it('warn is false', function () {
+          expect(viewInt.get('config.warn')).to.be.false;
+        });
+
+      });
+
+      describe('invalid value', function () {
+
+        beforeEach(function () {
+          viewInt.set('mirrorValue', 100500);
+        });
+
+        it('isMirrorValueValid is false', function () {
+          expect(viewInt.get('isMirrorValueValid')).to.be.false;
+        });
+        it('config value is 486', function () {
+          expect(viewInt.get('config.value')).to.equal('486');
+        });
+        it('errorMessage is empty', function () {
+          expect(viewInt.get('config.errorMessage')).to.equal('');
+        });
+        it('warnMessage is not empty', function () {
+          expect(viewInt.get('config.warnMessage')).to.have.property('length').that.is.least(1);
+        });
+        it('warn is true', function () {
+          expect(viewInt.get('config.warn')).to.be.true;
+        });
+
+      });
+
     });
 
-    it('check float', function () {
-      viewFloat.set('mirrorValue', 55.5);
-      expect(viewFloat.get('isMirrorValueValid')).to.be.true;
-      expect(viewFloat.get('config.value')).to.equal('55.5');
-      expect(viewFloat.get('config.errorMessage')).to.equal('');
-      expect(viewFloat.get('config.warnMessage')).to.equal('');
-      expect(viewFloat.get('config.warn')).to.be.false;
-
-      viewFloat.set('mirrorValue', 100500.5);
-      expect(viewFloat.get('isMirrorValueValid')).to.be.false;
-      expect(viewFloat.get('config.value')).to.equal('55.5');
-      expect(viewFloat.get('config.errorMessage')).to.equal('');
-      expect(viewFloat.get('config.warnMessage')).to.have.property('length').that.is.least(1);
-      expect(viewFloat.get('config.warn')).to.be.true;
+    describe('check float', function () {
+
+      describe('valid value', function () {
+
+        beforeEach(function () {
+          viewFloat.set('mirrorValue', 55.5);
+        });
+
+        it('isMirrorValueValid is true', function () {
+          expect(viewFloat.get('isMirrorValueValid')).to.be.true;
+        });
+        it('config value is 1000', function () {
+          expect(viewFloat.get('config.value')).to.equal('55.5');
+        });
+        it('errorMessage is empty', function () {
+          expect(viewFloat.get('config.errorMessage')).to.equal('');
+        });
+        it('warnMessage is empty', function () {
+          expect(viewFloat.get('config.warnMessage')).to.equal('');
+        });
+        it('warn is false', function () {
+          expect(viewFloat.get('config.warn')).to.be.false;
+        });
+
+      });
+
+      describe('invalid value', function () {
+
+        beforeEach(function () {
+          viewFloat.set('mirrorValue', 100500.5);
+        });
+
+        it('isMirrorValueValid is false', function () {
+          expect(viewFloat.get('isMirrorValueValid')).to.be.false;
+        });
+        it('config value is 1000', function () {
+          expect(viewFloat.get('config.value')).to.equal('72.2');
+        });
+        it('errorMessage is empty', function () {
+          expect(viewFloat.get('config.errorMessage')).to.equal('');
+        });
+        it('warnMessage is not empty', function () {
+          expect(viewFloat.get('config.warnMessage')).to.have.property('length').that.is.least(1);
+        });
+        it('warn is true', function () {
+          expect(viewFloat.get('config.warn')).to.be.true;
+        });
+
+      });
+
     });
 
-    it('check percent', function () {
-      viewPercent.set('mirrorValue', 32);
-      expect(viewPercent.get('isMirrorValueValid')).to.be.true;
-      expect(viewPercent.get('config.value')).to.equal('0.32');
-      expect(viewPercent.get('config.errorMessage')).to.equal('');
-      expect(viewPercent.get('config.warnMessage')).to.equal('');
-      expect(viewPercent.get('config.warn')).to.be.false;
-
-      viewPercent.set('mirrorValue', 100500.5);
-      expect(viewPercent.get('isMirrorValueValid')).to.be.false;
-      expect(viewPercent.get('config.value')).to.equal('0.32');
-      expect(viewPercent.get('config.errorMessage')).to.equal('');
-      expect(viewPercent.get('config.warnMessage')).to.have.property('length').that.is.least(1);
-      expect(viewPercent.get('config.warn')).to.be.true;
+    describe('check percent', function () {
+
+      describe('valid value', function () {
+
+        beforeEach(function () {
+          viewPercent.set('mirrorValue', 32);
+        });
+
+        it('isMirrorValueValid is true', function () {
+          expect(viewPercent.get('isMirrorValueValid')).to.be.true;
+        });
+        it('config value is 1000', function () {
+          expect(viewPercent.get('config.value')).to.equal('0.32');
+        });
+        it('errorMessage is empty', function () {
+          expect(viewPercent.get('config.errorMessage')).to.equal('');
+        });
+        it('warnMessage is empty', function () {
+          expect(viewPercent.get('config.warnMessage')).to.equal('');
+        });
+        it('warn is false', function () {
+          expect(viewPercent.get('config.warn')).to.be.false;
+        });
+
+      });
+
+      describe('invalid value', function () {
+
+        beforeEach(function () {
+          viewPercent.set('mirrorValue', 100500.5);
+        });
+
+        it('isMirrorValueValid is false', function () {
+          expect(viewPercent.get('isMirrorValueValid')).to.be.false;
+        });
+        it('config value is 1000', function () {
+          expect(viewPercent.get('config.value')).to.equal('0.22');
+        });
+        it('errorMessage is empty', function () {
+          expect(viewPercent.get('config.errorMessage')).to.equal('');
+        });
+        it('warnMessage is not empty', function () {
+          expect(viewPercent.get('config.warnMessage')).to.have.property('length').that.is.least(1);
+        });
+        it('warn is true', function () {
+          expect(viewPercent.get('config.warn')).to.be.true;
+        });
+
+      });
+
     });
+
   });
 
   describe('#getValueAttributeByGroup', function() {
@@ -201,10 +310,24 @@ describe('App.SliderConfigWidgetView', function () {
 
   describe('#initSlider', function() {
     beforeEach(function() {
-      this.view = App.SliderConfigWidgetView;
+      this.view = App.SliderConfigWidgetView.create();
+      sinon.stub(this.view, '$')
+        .withArgs('input.slider-input').returns([])
+        .withArgs('.ui-slider-wrapper:eq(0) .slider-tick').returns({
+          eq: Em.K,
+          addClass: Em.K,
+          on: Em.K,
+          append: Em.K,
+          find: Em.K,
+          css: Em.K,
+          width: function() {},
+          last: Em.K,
+          hide: Em.K
+        });
     });
 
     afterEach(function() {
+      this.view.$.restore();
       this.view.destroy();
       this.view = null;
     });
@@ -423,11 +546,11 @@ describe('App.SliderConfigWidgetView', function () {
     tests.forEach(function(test) {
       it('should generate ticks: {0} - tick labels: {1}'.format(test.e.ticks, test.e.ticksLabels), function() {
         var ticks, ticksLabels;
-        this.view = this.view.create(test.viewSetup);
+        this.view.reopen(test.viewSetup);
         this.view.set('controller', {
           isCompareMode: test.viewSetup.isCompareMode
         });
-        var sliderCopy= window.Slider.prototype;
+        var sliderCopy = window.Slider.prototype;
         window.Slider = function(a, b) {
           ticks = b.ticks;
           ticksLabels = b.ticks_labels;
@@ -437,23 +560,10 @@ describe('App.SliderConfigWidgetView', function () {
             }
           };
         };
-        sinon.stub(this.view, '$')
-          .withArgs('input.slider-input').returns([])
-          .withArgs('.ui-slider-wrapper:eq(0) .slider-tick').returns({
-            eq: Em.K,
-            addClass: Em.K,
-            on: Em.K,
-            append: Em.K,
-            find: Em.K,
-            css: Em.K,
-            width: function() {},
-            last: Em.K,
-            hide: Em.K
-          });
+
         this.view.willInsertElement();
         this.view.initSlider();
         window.Slider.prototype = sliderCopy;
-        this.view.$.restore();
         expect(ticks.toArray()).to.be.eql(test.e.ticks);
         expect(ticksLabels.toArray()).to.be.eql(test.e.ticksLabels);
       });

+ 17 - 26
ambari-web/test/views/common/configs/widgets/toggle_config_widget_view_test.js

@@ -73,33 +73,24 @@ describe('App.ToggleConfigWidgetView', function () {
 
   describe('#isValueCompatibleWithWidget', function () {
 
-    Em.A([
-      {
-        m: 'valid',
-        v: 'active',
-        e: true
-      },
-      {
-        m: 'invalid',
-        v: 'invalid',
-        e: false
-      }
-    ]).forEach(function (test) {
-      it(test.m, function () {
-        this.view.get('config').setProperties({
-          value: test.v,
-          isValid: true
-        });
-        expect(this.view.isValueCompatibleWithWidget()).to.equal(test.e);
-        if (test.e) {
-          expect(this.view.get('warnMessage')).to.equal('');
-          expect(this.view.get('issueMessage')).to.equal('');
-        }
-        else {
-          expect(this.view.get('warnMessage')).to.have.property('length').that.is.least(1);
-          expect(this.view.get('issueMessage')).to.have.property('length').that.is.least(1);
-        }
+    it('valid', function () {
+      this.view.get('config').setProperties({
+        value: 'active',
+        isValid: true
+      });
+      expect(this.view.isValueCompatibleWithWidget()).to.be.true;
+      expect(this.view.get('warnMessage')).to.equal('');
+      expect(this.view.get('issueMessage')).to.equal('');
+    });
+
+    it('invalid', function () {
+      this.view.get('config').setProperties({
+        value: 'invalid',
+        isValid: true
       });
+      expect(this.view.isValueCompatibleWithWidget()).to.be.false;
+      expect(this.view.get('warnMessage')).to.have.property('length').that.is.least(1);
+      expect(this.view.get('issueMessage')).to.have.property('length').that.is.least(1);
     });
 
   });

+ 103 - 65
ambari-web/test/views/common/controls_view_test.js

@@ -264,6 +264,7 @@ describe('App.ServiceConfigRadioButtons', function () {
           title: 'Ranger, HDP 2.3, external database'
         }
       ];
+    var rangerVersion = '';
 
     before(function () {
       sinon.stub(Em.run, 'next', function (arg) {
@@ -271,6 +272,18 @@ describe('App.ServiceConfigRadioButtons', function () {
       });
     });
 
+    beforeEach(function () {
+      sinon.stub(view, 'sendRequestRorDependentConfigs', Em.K);
+      this.stub = sinon.stub(App, 'get');
+      this.stub.withArgs('currentStackName').returns('HDP');
+      sinon.stub(App.StackService, 'find', function() {
+        return [Em.Object.create({
+          serviceName: 'RANGER',
+          serviceVersion: rangerVersion || ''
+        })];
+      });
+    });
+
     afterEach(function () {
       App.get.restore();
       App.StackService.find.restore();
@@ -283,26 +296,24 @@ describe('App.ServiceConfigRadioButtons', function () {
 
     cases.forEach(function (item) {
       it(item.title, function () {
-        sinon.stub(App, 'get').withArgs('currentStackName').returns('HDP').withArgs('currentStackVersion').returns(item.currentStackVersion);
-        sinon.stub(App.StackService, 'find', function() {
-          return [Em.Object.create({
-            serviceName: 'RANGER',
-            serviceVersion: item.rangerVersion || ''
-          })];
-        });
+        this.stub.withArgs('currentStackVersion').returns(item.currentStackVersion);
+        rangerVersion = item.rangerVersion;
         view.reopen({controller: item.controller});
-        sinon.stub(view, 'sendRequestRorDependentConfigs', Em.K);
         view.setProperties({
           categoryConfigsAll: item.controller.get('selectedService.configs'),
           serviceConfig: item.serviceConfig
         });
+
         var additionalView1 = view.get('categoryConfigsAll').findProperty('name', item.propertyAppendTo1).get('additionalView'),
           additionalView2 = view.get('categoryConfigsAll').findProperty('name', item.propertyAppendTo2).get('additionalView');
+
         expect(Em.isNone(additionalView1)).to.equal(item.isAdditionalView1Null);
         expect(Em.isNone(additionalView2)).to.equal(item.isAdditionalView2Null);
+
         if (!item.isAdditionalView2Null) {
           expect(additionalView2.create().get('message')).to.equal(Em.I18n.t('services.service.config.database.msg.jdbcSetup').format(item.dbType, item.driver));
         }
+
       });
     });
 
@@ -654,15 +665,35 @@ describe('App.CheckDBConnectionView', function () {
     });
 
     cases.forEach(function (item) {
-      it(item.title, function () {
-        view.set('logsPopup', item.logsPopupBefore);
-        view.setResponseStatus(item.isSuccess);
-        expect(view.get('isRequestResolved')).to.be.true;
-        expect(view.setConnectingStatus.calledOnce).to.be.true;
-        expect(view.setConnectingStatus.calledWith(false)).to.be.true;
-        expect(view.get('responseCaption')).to.equal(item.responseCaption);
-        expect(view.get('isConnectionSuccess')).to.equal(item.isConnectionSuccess);
-        expect(view.get('logsPopup')).to.eql(item.logsPopup);
+
+      describe(item.title, function () {
+
+        beforeEach(function () {
+          view.set('logsPopup', item.logsPopupBefore);
+          view.setResponseStatus(item.isSuccess);
+        });
+
+        it('isRequestResolved is true', function () {
+          expect(view.get('isRequestResolved')).to.be.true;
+        });
+
+        it('setConnectingStatus is called with valid arguments', function () {
+          expect(view.setConnectingStatus.calledOnce).to.be.true;
+          expect(view.setConnectingStatus.calledWith(false)).to.be.true;
+        });
+
+        it('responseCaption is valid', function () {
+          expect(view.get('responseCaption')).to.equal(item.responseCaption);
+        });
+
+        it('isConnectionSuccess is valid', function () {
+          expect(view.get('isConnectionSuccess')).to.equal(item.isConnectionSuccess);
+        });
+
+        it('logsPopup is valid', function () {
+          expect(view.get('logsPopup')).to.eql(item.logsPopup);
+        });
+
       });
     });
 
@@ -670,36 +701,7 @@ describe('App.CheckDBConnectionView', function () {
 
   describe('#showLogsPopup', function () {
 
-    var view,
-      cases = [
-        {
-          isConnectionSuccess: true,
-          showAlertPopupCallCount: 0,
-          title: 'successful connection'
-        },
-        {
-          isConnectionSuccess: false,
-          isRequestResolved: true,
-          showAlertPopupCallCount: 1,
-          responseFromServer: 'fail',
-          header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.error')),
-          popupMethodExecuted: 'onClose',
-          title: 'failed connection without output data, popup dismissed with Close button'
-        },
-        {
-          isConnectionSuccess: false,
-          isRequestResolved: false,
-          showAlertPopupCallCount: 1,
-          responseFromServer: {
-            stderr: 'stderr',
-            stdout: 'stdout',
-            structuredOut: 'structuredOut'
-          },
-          header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.testing')),
-          popupMethodExecuted: 'onPrimary',
-          title: 'check in progress with output data, popup dismissed with OK button'
-        }
-      ];
+    var view;
 
     beforeEach(function () {
       view = App.CheckDBConnectionView.create({
@@ -712,25 +714,61 @@ describe('App.CheckDBConnectionView', function () {
       App.showAlertPopup.restore();
     });
 
-    cases.forEach(function (item) {
-      it(item.title, function () {
-        view.setProperties({
-          isConnectionSuccess: item.isConnectionSuccess,
-          isRequestResolved: item.isRequestResolved,
-          responseFromServer: item.responseFromServer
-        });
+    it('successful connection', function () {
+      view.set('isConnectionSuccess', true);
+      view.showLogsPopup();
+      expect(App.showAlertPopup.callCount).to.equal(0);
+    });
+
+    describe('failed connection without output data, popup dismissed with Close button', function () {
+
+      beforeEach(function () {
+        view.set('isConnectionSuccess', false);
+        view.set('isRequestResolved', true);
+        view.set('responseFromServer', 'fail');
         view.showLogsPopup();
-        expect(App.showAlertPopup.callCount).to.equal(item.showAlertPopupCallCount);
-        if (!item.isConnectionSuccess) {
-          expect(view.get('logsPopup.header')).to.equal(item.header);
-          if (typeof item.responseFromServer == 'object') {
-            expect(view.get('logsPopup.bodyClass').create().get('openedTask')).to.eql(item.responseFromServer);
-          } else {
-            expect(view.get('logsPopup.body')).to.equal(item.responseFromServer);
-          }
-          view.get('logsPopup')[item.popupMethodExecuted]();
-          expect(view.get('logsPopup')).to.be.null;
-        }
+      });
+
+      it('showAlertPopup is called once', function () {
+        expect(App.showAlertPopup.callCount).to.equal(1);
+      });
+      it('logsPopup.header is valid', function () {
+        expect(view.get('logsPopup.header')).to.equal(Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.error')));
+      });
+      it('logsPopup.body is valid', function () {
+        expect(view.get('logsPopup.body')).to.equal('fail');
+      });
+      it('logsPopup is null after close', function () {
+        view.get('logsPopup').onClose();
+        expect(view.get('logsPopup')).to.be.null;
+      });
+    });
+
+    describe('check in progress with output data, popup dismissed with OK button', function () {
+      var response = {
+        stderr: 'stderr',
+        stdout: 'stdout',
+        structuredOut: 'structuredOut'
+      };
+      beforeEach(function () {
+        view.set('isConnectionSuccess', false);
+        view.set('isRequestResolved', false);
+        view.set('responseFromServer', response);
+        view.showLogsPopup();
+      });
+
+      it('showAlertPopup is called once', function () {
+        expect(App.showAlertPopup.callCount).to.equal(1);
+      });
+      it('logsPopup.header is valid', function () {
+        expect(view.get('logsPopup.header')).to.equal(Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.testing')));
+      });
+      it('logsPopup.bodyClass is valid', function () {
+        expect(view.get('logsPopup.bodyClass').create().get('openedTask')).to.eql(response);
+      });
+      it('logsPopup is null after primary click', function () {
+        view.get('logsPopup').onPrimary();
+        expect(view.get('logsPopup')).to.be.null;
       });
     });
 

+ 50 - 19
ambari-web/test/views/common/custom_date_popup_test.js

@@ -33,29 +33,60 @@ describe('CustomDatePopup', function() {
       expect(context.cancel.calledOnce).to.ok;
     });
 
-    it('empty values passed for end and start dates, validation should fail with appropriate message', function() {
-      expect(popup.onPrimary()).to.false;
-      expect(customDatePopup.get('errors.isStartDateError')).to.ok;
-      expect(customDatePopup.get('errors.isEndDateError')).to.ok;
-      expect(customDatePopup.get('errorMessages.startDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.required'));
-      expect(customDatePopup.get('errorMessages.endDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.required'));
+    describe('empty values passed for end and start dates, validation should fail with appropriate message', function () {
+      it('onPrimary is false', function () {
+        expect(popup.onPrimary()).to.false;
+      });
+      it('isStartDateError is true', function () {
+        expect(customDatePopup.get('errors.isStartDateError')).to.ok;
+      });
+      it('isEndDateError is true', function () {
+        expect(customDatePopup.get('errors.isEndDateError')).to.ok;
+      });
+      it('startDate invalid', function () {
+        expect(customDatePopup.get('errorMessages.startDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.required'));
+      });
+      it('endDate invalid', function () {
+        expect(customDatePopup.get('errorMessages.endDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.required'));
+      });
     });
 
-    it('passed start date is greater then end data, validation should fail with apporpriate message', function() {
-      customDatePopup.set('customDateFormFields.startDate', '11/11/11');
-      customDatePopup.set('customDateFormFields.endDate', '11/10/11');
-      expect(popup.onPrimary()).to.false;
-      expect(customDatePopup.get('errors.isStartDateError')).to.false;
-      expect(customDatePopup.get('errors.isEndDateError')).to.ok;
-      expect(customDatePopup.get('errorMessages.endDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.date.order'));
+    describe('passed start date is greater then end data, validation should fail with apporpriate message', function () {
+      beforeEach(function () {
+        customDatePopup.set('customDateFormFields.startDate', '11/11/11');
+        customDatePopup.set('customDateFormFields.endDate', '11/10/11');
+      });
+
+      it('onPrimary is false', function () {
+        expect(popup.onPrimary()).to.false;
+      });
+      it('isStartDateError is false', function () {
+        expect(customDatePopup.get('errors.isStartDateError')).to.false;
+      });
+      it('isEndDateError is true', function () {
+        expect(customDatePopup.get('errors.isEndDateError')).to.ok;
+      });
+      it('endDate invalid', function () {
+        expect(customDatePopup.get('errorMessages.endDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.date.order'));
+      });
     });
 
-    it('valid values passed, `valueObject` should contain `endTime` and `startTime`', function() {
-      customDatePopup.set('customDateFormFields.startDate', '11/11/11');
-      customDatePopup.set('customDateFormFields.endDate', '11/12/11');
-      popup.onPrimary();
-      expect(context.get('actualValues.startTime')).to.equal(new Date('11/11/11 01:00 AM').getTime());
-      expect(context.get('actualValues.endTime')).to.equal(new Date('11/12/11 01:00 AM').getTime());
+    describe('valid values passed, `valueObject` should contain `endTime` and `startTime`', function () {
+
+      beforeEach(function () {
+        customDatePopup.set('customDateFormFields.startDate', '11/11/11');
+        customDatePopup.set('customDateFormFields.endDate', '11/12/11');
+        popup.onPrimary();
+      });
+
+      it('startTime is valid', function() {
+        expect(context.get('actualValues.startTime')).to.equal(new Date('11/11/11 01:00 AM').getTime());
+      });
+      it('endTime is valid', function() {
+        expect(context.get('actualValues.endTime')).to.equal(new Date('11/12/11 01:00 AM').getTime());
+      });
+
     });
+
   });
 });

+ 8 - 2
ambari-web/test/views/common/filter_combo_cleanable_test.js

@@ -26,14 +26,20 @@ describe('App.FilterComboCleanableView', function() {
 
   describe('#didInsertElement', function() {
 
-    it('should clean filter when created', function() {
+    beforeEach(function () {
       sinon.stub(App, 'popover', Em.K);
+    });
+
+    afterEach(function () {
+      App.popover.restore();
+    });
+
+    it('should clean filter when created', function() {
       view.setProperties({
         filter: 'some value',
         popoverDescription: ['', '']
       });
       view.didInsertElement();
-      App.popover.restore();
       expect(view.get('filter')).to.be.empty;
     });
 

+ 66 - 21
ambari-web/test/views/common/form/manage_kdc_credentials_form_test.js

@@ -43,6 +43,21 @@ describe('#App.ManageCredentialsFormView', function() {
   App.TestAliases.testAsComputedIfThenElse(getView(), 'hintMessage', 'storePersisted', Em.I18n.t('admin.kerberos.credentials.store.hint.supported'), Em.I18n.t('admin.kerberos.credentials.store.hint.not.supported'));
 
   describe('#prepareContent', function() {
+
+    var credentials;
+
+    beforeEach(function () {
+      this.stub = sinon.stub(App, 'get');
+      sinon.stub(credentialUtils, 'credentials', function(clusterName, callback) {
+        callback(credentials);
+      });
+    });
+
+    afterEach(function () {
+      App.get.restore();
+      credentialUtils.credentials.restore();
+    });
+
     [
       {
         isStorePersistent: true,
@@ -76,17 +91,13 @@ describe('#App.ManageCredentialsFormView', function() {
       }
     ].forEach(function(test) {
       it(test.m, function(done) {
-        sinon.stub(credentialUtils, 'credentials', function(clusterName, callback) {
-          callback(test.credentials);
-        });
-        sinon.stub(App, 'get').withArgs('isCredentialStorePersistent').returns(test.e.storePersisted);
+        credentials = test.credentials;
+        this.stub.withArgs('isCredentialStorePersistent').returns(test.e.storePersisted);
         view.prepareContent();
         Em.run.next(function() {
           assert.equal(view.get('isRemovable'), test.e.isRemovable, '#isRemovable property validation');
           assert.equal(view.get('isRemoveDisabled'), test.e.isRemoveDisabled, '#isRemoveDisabled property validation');
           assert.equal(view.get('storePersisted'), test.e.storePersisted, '#storePersisted property validation');
-          credentialUtils.credentials.restore();
-          App.get.restore();
           done();
         });
       });
@@ -113,39 +124,55 @@ describe('#App.ManageCredentialsFormView', function() {
   });
 
   describe('fields validation', function() {
+    var t = Em.I18n.t;
+
     it('should flow validation', function() {
-      var t = Em.I18n.t;
       assert.isTrue(view.get('isSubmitDisabled'), 'submit disabled on initial state');
+    });
+
+    it('principal is not empty', function() {
       view.set('principal', ' a');
-      assert.equal(view.get('principalError'), t('host.spacesValidation'), 'principal contains spaces, appropriate message shown');
+      expect(view.get('principalError')).to.equal(t('host.spacesValidation'));
       assert.isTrue(view.get('isPrincipalDirty'), 'principal name modified');
       assert.isTrue(view.get('isSubmitDisabled'), 'submit disabled because principal not valid');
+    });
+
+    it('principal is empty', function() {
+      view.set('principal', ' a');
       view.set('principal', '');
-      assert.equal(view.get('principalError'), t('admin.users.editError.requiredField'), 'principal is empty, appropriate message shown');
+      expect(view.get('principalError')).to.equal(t('admin.users.editError.requiredField'));
+    });
+
+    it('principal is not empty (2)', function() {
       view.set('principal', 'some_name');
       assert.isFalse(view.get('principalError'), 'principal name valid no message shown');
       assert.isTrue(view.get('isSubmitDisabled'), 'submit disabled because password field not modified');
+    });
+
+    it('password is updated', function() {
       view.set('password', '1');
       view.set('password', '');
-      assert.equal(view.get('passwordError'), t('admin.users.editError.requiredField'), 'password is empty, appropriate message shown');
+      expect(view.get('passwordError')).to.equal(t('admin.users.editError.requiredField'));
       assert.isTrue(view.get('isPasswordDirty'), 'password modified');
       assert.isTrue(view.get('isSubmitDisabled'), 'submit disabled because password field is empty');
+    });
+
+    it('password is updated (2)', function() {
       view.set('password', 'some_pass');
+      view.set('principal', 'some_name');
       assert.isFalse(view.get('passwordError'), 'password valid no message shown');
       assert.isFalse(view.get('isSubmitDisabled'), 'submit enabled all fields are valid');
     });
+
   });
 
   describe('#removeKDCCredentials', function() {
-    it('should show confirmation popup', function() {
-      var popup = view.removeKDCCredentials().popup;
-      expect(popup).be.instanceof(App.ModalPopup);
-      popup.destroy();
-    });
-    it('should call credentialUtils#removeCredentials', function() {
+
+    var popup;
+
+    beforeEach(function () {
+      popup = view.removeKDCCredentials().popup;
       this.clock = sinon.useFakeTimers();
-      var popup = view.removeKDCCredentials().popup;
-      assert.isFalse(view.get('actionStatus'), '#actionStatus before remove');
       sinon.stub(credentialUtils, 'removeCredentials', function() {
         var dfd = $.Deferred();
         setTimeout(function() {
@@ -153,17 +180,35 @@ describe('#App.ManageCredentialsFormView', function() {
         }, 500);
         return dfd.promise();
       });
+    });
+
+    afterEach(function () {
+      popup.destroy();
+      credentialUtils.removeCredentials.restore();
+      this.clock.restore();
+    });
+
+    it('should show confirmation popup', function() {
+      expect(popup).be.instanceof(App.ModalPopup);
+    });
+
+    it('on popup open', function() {
+      assert.isFalse(view.get('actionStatus'), '#actionStatus before remove');
+    });
+
+    it('on Primary', function() {
       popup.onPrimary();
       assert.isTrue(view.get('isActionInProgress'), 'action in progress');
       assert.isTrue(view.get('isRemoveDisabled'), 'remove button disabled');
       assert.isTrue(view.get('isSubmitDisabled'), 'submit button disabled');
+    });
+
+    it('after 1s', function() {
+      popup.onPrimary();
       this.clock.tick(1000);
       assert.isFalse(view.get('isActionInProgress'), 'action finished');
       assert.equal(Em.I18n.t('common.success'), view.get('actionStatus'), '#actionStatus after remove');
       assert.isTrue(view.get('parentView.isCredentialsRemoved'), 'parentView#isCredentialsRemoved property should be triggered when remove complete');
-      credentialUtils.removeCredentials.restore();
-      this.clock.restore();
-      popup.destroy();
     });
   });
 

+ 9 - 2
ambari-web/test/views/common/modal_popup_test.js

@@ -39,10 +39,17 @@ describe('App.ModalPopup', function() {
 
   describe('#didInsertElement', function () {
 
+    beforeEach(function () {
+      this.spy = sinon.spy(popup, "focusElement");
+    });
+
+    afterEach(function () {
+      this.spy.restore();
+    });
+
     it('should focus on the first input element', function () {
-      var spy = sinon.spy(popup, "focusElement");
       popup.didInsertElement();
-      expect(spy.called).to.be.true;
+      expect(this.spy.called).to.be.true;
     });
   });
 

+ 38 - 15
ambari-web/test/views/common/modal_popups/cluster_check_popup_test.js

@@ -245,26 +245,49 @@ describe('App.showClusterCheckPopup', function () {
   });
 
   cases.forEach(function (item) {
-    it(item.title, function () {
-      var popup = App.showClusterCheckPopup(item.inputData.data, item.inputData.popup, item.inputData.configs, item.inputData.upgradeVersion),
+
+    describe(item.title, function () {
+
+      var popup;
+      var popupBody;
+
+      beforeEach(function () {
+        popup = App.showClusterCheckPopup(item.inputData.data, item.inputData.popup, item.inputData.configs, item.inputData.upgradeVersion);
         popupBody = popup.bodyClass.create();
-      popup.onPrimary();
-      Em.keys(item.result).forEach(function (key) {
-        expect(popup[key]).to.equal(item.result[key]);
+        popup.onPrimary();
       });
-      Em.keys(item.bodyResult).forEach(function (key) {
-        expect(popupBody[key]).to.eql(item.bodyResult[key]);
+
+      it('result', function () {
+        Em.keys(item.result).forEach(function (key) {
+          expect(popup[key]).to.equal(item.result[key]);
+        });
+      });
+
+      it('bodyResult', function () {
+        Em.keys(item.bodyResult).forEach(function (key) {
+          expect(popupBody[key]).to.eql(item.bodyResult[key]);
+        });
       });
-      expect(isCallbackExecuted).to.equal(item.isCallbackExecuted);
+
+      it('callbackExecuted', function () {
+        expect(isCallbackExecuted).to.equal(item.isCallbackExecuted);
+      });
+
       if (item.bodyResult.hasConfigsMergeConflicts) {
-        var configsMergeTable = popupBody.configsMergeTable.create();
-        configsMergeTable.didInsertElement();
-        expect(configsMergeTable.configs).to.eql(item.configsResult);
-        expect(App.tooltip.calledOnce).to.be.true;
-        expect(App.tooltip.firstCall.args[1].title).to.equal(item.inputData.upgradeVersion);
-      } else {
-        expect(App.tooltip.calledOnce).to.be.false;
+        it('hasConfigsMergeConflicts = true', function () {
+          var configsMergeTable = popupBody.configsMergeTable.create();
+          configsMergeTable.didInsertElement();
+          expect(configsMergeTable.configs).to.eql(item.configsResult);
+          expect(App.tooltip.calledOnce).to.be.true;
+          expect(App.tooltip.firstCall.args[1].title).to.equal(item.inputData.upgradeVersion);
+        });
       }
+      else {
+        it('App.tooltip is not called', function () {
+          expect(App.tooltip.called).to.be.false;
+        });
+      }
+
     });
   });
 

+ 24 - 6
ambari-web/test/views/common/modal_popups/hosts_table_list_popup_test.js

@@ -49,14 +49,32 @@ describe('App.showHostsTableListPopup', function () {
   ];
 
   cases.forEach(function (item) {
-    it(item.title, function () {
-      var popup = App.showHostsTableListPopup(item.header, item.hostName, item.items),
+
+    describe(item.title, function () {
+
+      var popup;
+      var popupBody;
+
+      beforeEach(function () {
+        popup = App.showHostsTableListPopup(item.header, item.hostName, item.items);
         popupBody = popup.bodyClass.create();
-      expect(popup.header).to.equal(item.header);
-      expect(popupBody.get('hostName')).to.equal(item.hostName);
-      expect(popupBody.get('items')).to.eql(item.items);
-      expect(popupBody.get('isObjectsList')).to.equal(item.isObjectsList);
+      });
+
+      it('header is valid', function () {
+        expect(popup.header).to.equal(item.header);
+      });
+      it('hostName is valid', function () {
+        expect(popupBody.get('hostName')).to.equal(item.hostName);
+      });
+      it('items are valid', function () {
+        expect(popupBody.get('items')).to.eql(item.items);
+      });
+      it('isObjectsList is valid', function () {
+        expect(popupBody.get('isObjectsList')).to.equal(item.isObjectsList);
+      });
+
     });
+
   });
 
 });

+ 37 - 22
ambari-web/test/views/common/widget/graph_widget_view_test.js

@@ -194,33 +194,48 @@ describe('App.GraphWidgetView', function () {
       }
     ];
 
-    beforeEach(function () {
-      sinon.stub(view, 'prepareCSV').returns('key,value');
-      sinon.stub(fileUtils, 'downloadTextFile', Em.K);
-      sinon.stub(App, 'showAlertPopup', Em.K);
-    });
+    cases.forEach(function (item) {
 
-    afterEach(function () {
-      view.prepareCSV.restore();
-      fileUtils.downloadTextFile.restore();
-      App.showAlertPopup.restore();
-    });
+      describe(item.title, function () {
+
+        beforeEach(function () {
+          sinon.stub(view, 'prepareCSV').returns('key,value');
+          sinon.stub(fileUtils, 'downloadTextFile', Em.K);
+          sinon.stub(App, 'showAlertPopup', Em.K);
+          view.set('data', item.data);
+          view.exportGraphData(item.event || {});
+        });
+
+        afterEach(function () {
+          view.prepareCSV.restore();
+          fileUtils.downloadTextFile.restore();
+          App.showAlertPopup.restore();
+        });
+
+        it('isExportMenuHidden is true', function () {
+          expect(view.get('isExportMenuHidden')).to.be.true;
+        });
+
+        it('downloadTextFile calls count is calid', function () {
+          expect(fileUtils.downloadTextFile.callCount).to.equal(item.downloadTextFileCallCount);
+        });
+
+        it('showAlertPopup calls count is valid', function () {
+          expect(App.showAlertPopup.callCount).to.equal(item.showAlertPopupCallCount);
+        });
 
-    cases.forEach(function (item) {
-      it(item.title, function () {
-        view.set('data', item.data);
-        view.exportGraphData(item.event || {});
-        expect(view.get('isExportMenuHidden')).to.be.true;
-        expect(fileUtils.downloadTextFile.callCount).to.equal(item.downloadTextFileCallCount);
-        expect(App.showAlertPopup.callCount).to.equal(item.showAlertPopupCallCount);
         if (item.downloadTextFileCallCount) {
-          var fileType = item.event && item.event.context ? 'csv' : 'json',
-            downloadArgs = fileUtils.downloadTextFile.firstCall.args;
-          expect(downloadArgs[0].replace(/\s/g, '')).to.equal(item.fileData);
-          expect(downloadArgs[1]).to.equal(fileType);
-          expect(downloadArgs[2]).to.equal('data.' + fileType);
+          it('download args are valid', function () {
+            var fileType = item.event && item.event.context ? 'csv' : 'json',
+              downloadArgs = fileUtils.downloadTextFile.firstCall.args;
+            expect(downloadArgs[0].replace(/\s/g, '')).to.equal(item.fileData);
+            expect(downloadArgs[1]).to.equal(fileType);
+            expect(downloadArgs[2]).to.equal('data.' + fileType);
+          });
         }
+
       });
+
     });
 
   });

+ 5 - 2
ambari-web/test/views/main/admin/stack_upgrade/menu_view_test.js

@@ -27,6 +27,10 @@ describe('App.MainAdminStackMenuView', function () {
 
   describe('#content', function () {
 
+    beforeEach(function () {
+      this.stub = sinon.stub(App, 'get');
+    });
+
     afterEach(function () {
       App.get.restore();
     });
@@ -44,8 +48,7 @@ describe('App.MainAdminStackMenuView', function () {
         }
       ]).forEach(function (test) {
         it(test.m, function () {
-          var stub = sinon.stub(App, 'get');
-          stub.withArgs('stackVersionsAvailable').returns(test.stackVersionsAvailable);
+          this.stub.withArgs('stackVersionsAvailable').returns(test.stackVersionsAvailable);
           view.propertyDidChange('content');
           expect(view.get('content').findProperty('name', 'versions').get('hidden')).to.equal(test.e);
         });

+ 10 - 4
ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js

@@ -203,16 +203,22 @@ describe('App.mainAdminStackVersionsView', function () {
         }
       ];
 
+    var displayOlderVersions = false;
+
+    beforeEach(function () {
+      sinon.stub(App, 'get', function (key) {
+        return key == 'supports.displayOlderVersions' ? displayOlderVersions : Em.get(App, key);
+      });
+    });
+
     afterEach(function () {
       App.get.restore();
     });
 
     testCases.forEach(function(t) {
-      var msg = t.filter.get('value') ? t.filter.get('value') : "All";
+      var msg = t.filter.get('value') || "All";
       it(t.message || "filter By " + msg, function () {
-        sinon.stub(App, 'get', function (key) {
-          return key == 'supports.displayOlderVersions' ? Boolean(t.displayOlderVersions) : Em.get(App, key);
-        });
+        displayOlderVersions = t.displayOlderVersions;
         view.set('controller.currentVersion', t.noCurrentVersion ? null : {repository_version: '2.2.1.1'});
         expect(view.filterBy(versions, t.filter)).to.eql(t.filteredVersions);
       });

+ 5 - 1
ambari-web/test/views/main/admin_test.js

@@ -72,13 +72,17 @@ describe('App.MainAdminView', function () {
       }
     ];
 
+    beforeEach(function () {
+      this.stub = sinon.stub(App, 'get');
+    });
+
     afterEach(function () {
       App.get.restore();
     });
 
     cases.forEach(function (item) {
       it(item.title, function () {
-        sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(item.isHadoopWindowsStack);
+        this.stub.withArgs('isHadoopWindowsStack').returns(item.isHadoopWindowsStack);
         view.propertyDidChange('categories');
         expect(view.get('categories')).to.eql(item.categories);
       });

+ 144 - 67
ambari-web/test/views/main/charts/heatmap/heatmap_host_test.js

@@ -157,91 +157,168 @@ describe('App.MainChartsHeatmapHostView', function () {
       this.mock.restore();
     });
 
-    it("set diskUsage", function () {
-      var childView = Em.Object.create({
-        details: {
-          diskUsage: ''
-        }
+    describe('set diskUsage', function () {
+      var childView;
+      beforeEach(function () {
+        childView = Em.Object.create({
+          details: {
+            diskUsage: ''
+          }
+        });
+        this.mock.returns(childView);
+        view.set('content', {
+          diskTotal: 100,
+          diskFree: 50
+        });
+        view.mouseEnter();
+      });
+
+      it("details.diskUsage = usage", function () {
+        expect(childView.get('details.diskUsage')).to.equal('usage');
+      });
+
+      it("getUsage is called with valid arguments", function () {
+        expect(view.getUsage.calledWith(100, 50)).to.be.true;
       });
-      this.mock.returns(childView);
-      view.set('content', {
-        diskTotal: 100,
-        diskFree: 50
+
+      it("setMetric is called once", function () {
+        expect(view.setMetric.calledOnce).to.be.true;
+      });
+
+      it("openDetailsBlock is called once", function () {
+        expect(view.openDetailsBlock.calledOnce).to.be.true;
       });
-      view.mouseEnter();
-      expect(childView.get('details.diskUsage')).to.equal('usage');
-      expect(view.getUsage.calledWith(100, 50)).to.be.true;
-      expect(view.setMetric.calledOnce).to.be.true;
-      expect(view.openDetailsBlock.calledOnce).to.be.true;
+
     });
 
-    it("set cpuUsage", function () {
-      var childView = Em.Object.create({
-        details: {
-          cpuUsage: ''
-        }
+    describe('set cpuUsage', function () {
+      var childView;
+      beforeEach(function () {
+        childView = Em.Object.create({
+          details: {
+            cpuUsage: ''
+          }
+        });
+        this.mock.returns(childView);
+        view.set('content', {
+          cpuSystem: 100,
+          cpuUser: 50
+        });
+        view.mouseEnter();
       });
-      this.mock.returns(childView);
-      view.set('content', {
-        cpuSystem: 100,
-        cpuUser: 50
+
+      it("details.cpuUsage = cpu_usage", function () {
+        expect(childView.get('details.cpuUsage')).to.equal('cpu_usage');
+      });
+
+      it("getCpuUsage is called with valid arguments", function () {
+        expect(view.getCpuUsage.calledWith(100, 50)).to.be.true;
+      });
+
+      it("setMetric is called once", function () {
+        expect(view.setMetric.calledOnce).to.be.true;
+      });
+
+      it("openDetailsBlock is called once", function () {
+        expect(view.openDetailsBlock.calledOnce).to.be.true;
       });
-      view.mouseEnter();
-      expect(childView.get('details.cpuUsage')).to.equal('cpu_usage');
-      expect(view.getCpuUsage.calledWith(100, 50)).to.be.true;
-      expect(view.setMetric.calledOnce).to.be.true;
-      expect(view.openDetailsBlock.calledOnce).to.be.true;
+
     });
 
-    it("set memoryUsage", function () {
-      var childView = Em.Object.create({
-        details: {
-          memoryUsage: ''
-        }
+    describe('set memoryUsage', function () {
+      var childView;
+      beforeEach(function () {
+        childView = Em.Object.create({
+          details: {
+            memoryUsage: ''
+          }
+        });
+        this.mock.returns(childView);
+        view.set('content', {
+          memTotal: 100,
+          memFree: 50
+        });
+        view.mouseEnter();
+      });
+
+      it("details.memoryUsage = usage", function () {
+        expect(childView.get('details.memoryUsage')).to.equal('usage');
       });
-      this.mock.returns(childView);
-      view.set('content', {
-        memTotal: 100,
-        memFree: 50
+
+      it("getUsage is called with valid arguments", function () {
+        expect(view.getUsage.calledWith(100, 50)).to.be.true;
+      });
+
+      it("setMetric is called once", function () {
+        expect(view.setMetric.calledOnce).to.be.true;
       });
-      view.mouseEnter();
-      expect(childView.get('details.memoryUsage')).to.equal('usage');
-      expect(view.getUsage.calledWith(100, 50)).to.be.true;
-      expect(view.setMetric.calledOnce).to.be.true;
-      expect(view.openDetailsBlock.calledOnce).to.be.true;
+
+      it("openDetailsBlock is called once", function () {
+        expect(view.openDetailsBlock.calledOnce).to.be.true;
+      });
+
     });
 
-    it("set hostComponents", function () {
-      var childView = Em.Object.create({
-        details: {
-          hostComponents: ''
-        }
+    describe('set hostComponents', function () {
+      var childView;
+      beforeEach(function () {
+        childView = Em.Object.create({
+          details: {
+            hostComponents: ''
+          }
+        });
+        this.mock.returns(childView);
+        view.set('content', {
+          hostComponents: ['host1']
+        });
+        view.mouseEnter();
+      });
+
+      it("hostComponents = ['c1']", function () {
+        expect(childView.get('details.hostComponents')).to.eql(['c1']);
+      });
+
+      it("getHostComponents is called with valid arguments", function () {
+        expect(view.getHostComponents.calledWith(['host1'])).to.be.true;
       });
-      this.mock.returns(childView);
-      view.set('content', {
-        hostComponents: ['host1']
+
+      it("setMetric is called once", function () {
+        expect(view.setMetric.calledOnce).to.be.true;
+      });
+
+      it("openDetailsBlock is called once", function () {
+        expect(view.openDetailsBlock.calledOnce).to.be.true;
       });
-      view.mouseEnter();
-      expect(childView.get('details.hostComponents')).to.eql(['c1']);
-      expect(view.getHostComponents.calledWith(['host1'])).to.be.true;
-      expect(view.setMetric.calledOnce).to.be.true;
-      expect(view.openDetailsBlock.calledOnce).to.be.true;
+
     });
 
-    it("set hostName", function () {
-      var childView = Em.Object.create({
-        details: {
-          hostName: ''
-        }
+    describe('set hostName', function () {
+      var childView;
+      beforeEach(function () {
+        childView = Em.Object.create({
+          details: {
+            hostName: ''
+          }
+        });
+        this.mock.returns(childView);
+        view.set('content', {
+          hostName: 'host1'
+        });
+        view.mouseEnter();
       });
-      this.mock.returns(childView);
-      view.set('content', {
-        hostName: 'host1'
+
+      it("hostName = host1", function () {
+        expect(childView.get('details.hostName')).to.equal('host1');
+      });
+
+      it("setMetric is called once", function () {
+        expect(view.setMetric.calledOnce).to.be.true;
       });
-      view.mouseEnter();
-      expect(childView.get('details.hostName')).to.equal('host1');
-      expect(view.setMetric.calledOnce).to.be.true;
-      expect(view.openDetailsBlock.calledOnce).to.be.true;
+
+      it("openDetailsBlock is called once", function () {
+        expect(view.openDetailsBlock.calledOnce).to.be.true;
+      });
+
     });
   });
 

+ 18 - 5
ambari-web/test/views/main/dashboard/widget_test.js

@@ -147,25 +147,38 @@ describe('App.DashboardWidgetView', function () {
       thresh1: '1',
       thresh2: '2'
     });
-    before(function () {
+    beforeEach(function () {
       sinon.spy(obj, 'observeThresh1Value');
       sinon.spy(obj, 'observeThresh2Value');
       sinon.stub(dashboardWidgetView.get('parentView'), 'getUserPref').returns({
         complete: Em.K
       });
+      var popup = dashboardWidgetView.showEditDialog(obj);
+      popup.onPrimary();
     });
-    after(function () {
+    afterEach(function () {
       obj.observeThresh1Value.restore();
       obj.observeThresh2Value.restore();
       dashboardWidgetView.get('parentView').getUserPref.restore();
     });
-    it("open popup", function () {
-      var popup = dashboardWidgetView.showEditDialog(obj);
-      popup.onPrimary();
+
+    it("observeThresh1Value is called once", function () {
       expect(obj.observeThresh1Value.calledOnce).to.be.true;
+    });
+
+    it("observeThresh2Value is called once", function () {
       expect(obj.observeThresh2Value.calledOnce).to.be.true;
+    });
+
+    it("thresh1 = 1", function () {
       expect(dashboardWidgetView.get('thresh1')).to.equal(1);
+    });
+
+    it("thresh2 = 2", function () {
       expect(dashboardWidgetView.get('thresh2')).to.equal(2);
+    });
+
+    it("getUserPref is called once", function () {
       expect(dashboardWidgetView.get('parentView').getUserPref.calledOnce).to.be.true;
     });
   });

+ 8 - 2
ambari-web/test/views/main/dashboard/widgets/datanode_live_test.js

@@ -51,18 +51,24 @@ describe('App.DataNodeUpView', function() {
     }
   ];
 
-  tests.forEach(function(test) {
-    describe('', function() {
+  tests.forEach(function(test, index) {
+
+    describe('test#' + (index + 1), function () {
+
       var dataNodeUpView = App.DataNodeUpView.create({model_type:null, data: test.data, content: test.data.toString()});
+
       it('isRed', function() {
         expect(dataNodeUpView.get('isRed')).to.equal(test.e.isRed);
       });
+
       it('isOrange', function() {
         expect(dataNodeUpView.get('isOrange')).to.equal(test.e.isOrange);
       });
+
       it('isGreen', function() {
         expect(dataNodeUpView.get('isGreen')).to.equal(test.e.isGreen);
       });
+
     });
   });
 

+ 6 - 0
ambari-web/test/views/main/host/details/host_component_views/datanode_view_test.js

@@ -27,14 +27,17 @@ describe('App.DataNodeComponentView', function () {
   });
 
   describe("#getDNDecommissionStatus()", function () {
+
     beforeEach(function () {
       this.stub = sinon.stub(App.HDFSService, 'find');
       sinon.stub(App.ajax, 'send');
     });
+
     afterEach(function () {
       App.ajax.send.restore();
       this.stub.restore();
     });
+
     it("snameNode absent and no activeNameNode", function () {
       this.stub.returns([
         Em.Object.create({
@@ -49,6 +52,7 @@ describe('App.DataNodeComponentView', function () {
         "componentName": "NAMENODE"
       });
     });
+
     it("snameNode present and no activeNameNode", function () {
       this.stub.returns([
         Em.Object.create({
@@ -63,6 +67,7 @@ describe('App.DataNodeComponentView', function () {
         "componentName": "NAMENODE"
       });
     });
+
     it("snameNode absent and activeNameNode valid", function () {
       this.stub.returns([
         Em.Object.create({
@@ -77,6 +82,7 @@ describe('App.DataNodeComponentView', function () {
         "componentName": "NAMENODE"
       });
     });
+
   });
 
   describe("#getDNDecommissionStatusSuccessCallback()", function () {

+ 6 - 3
ambari-web/test/views/main/host/menu_test.js

@@ -27,6 +27,10 @@ describe('App.MainHostMenuView', function () {
 
   describe('#content', function () {
 
+    beforeEach(function () {
+      this.mock = sinon.stub(App, 'get');
+    });
+
     afterEach(function () {
       App.get.restore();
     });
@@ -58,9 +62,8 @@ describe('App.MainHostMenuView', function () {
         }
       ]).forEach(function (test) {
         it(test.m, function () {
-          var stub = sinon.stub(App, 'get');
-          stub.withArgs('stackVersionsAvailable').returns(test.stackVersionsAvailable);
-          stub.withArgs('supports.stackUpgrade').returns(test.stackUpgrade);
+          this.mock.withArgs('stackVersionsAvailable').returns(test.stackVersionsAvailable);
+          this.mock.withArgs('supports.stackUpgrade').returns(test.stackUpgrade);
           view.propertyDidChange('content');
           expect(view.get('content').findProperty('name', 'versions').get('hidden')).to.equal(test.e);
         });

+ 6 - 2
ambari-web/test/views/main/menu_test.js

@@ -91,13 +91,17 @@ describe('App.MainMenuView', function () {
         }
       ];
 
+      beforeEach(function () {
+        this.mock = sinon.stub(App, 'get');
+      });
+
       afterEach(function () {
-        App.get.restore();
+        this.mock.restore();
       });
 
       cases.forEach(function (item) {
         it(item.title, function () {
-          sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(item.isHadoopWindowsStack);
+          this.mock.withArgs('isHadoopWindowsStack').returns(item.isHadoopWindowsStack);
           var menuItem = mainMenuView.get('content').findProperty('content.routing', item.itemName);
           menuItem.propertyDidChange('dropdownCategories');
           expect(menuItem.get('dropdownCategories')).to.eql(item.dropdownCategories);

+ 42 - 21
ambari-web/test/views/main/service/info/metrics/ambari_metrics/regionserver_base_test.js

@@ -22,28 +22,49 @@ require('views/main/service/info/metrics/ambari_metrics/regionserver_base');
 
 describe('App.ChartServiceMetricsAMS_RegionServerBaseView', function () {
 
-  var regionServerView = App.ChartServiceMetricsAMS_RegionServerBaseView.extend({
-    id: "service-metrics-ambari-metrics-region-server-test",
-    title: 'test-title',
-    ajaxIndex: 'service.metrics.ambari_metrics.region_server.regions',
-    displayName: 'test-display-name',
-    regionServerName: 'test'
-  }).create();
-
-  it('#transformData should transform data for regionserver requests', function () {
-    var jsonData = {
-      "metrics": {
-        "hbase": {
-          "regionserver": {
-            "test": [[11.0, 1424948261], [11.0, 1424948306], [11.0, 1424948321]]
-          }
+  var regionServerView;
+  var jsonData = {
+    "metrics": {
+      "hbase": {
+        "regionserver": {
+          "test": [[11.0, 1424948261], [11.0, 1424948306], [11.0, 1424948321]]
         }
       }
-    };
-    var result = regionServerView.transformToSeries(jsonData);
-    expect(result[0].name === regionServerView.displayName).to.be.true;
-    expect(result[0].data.length === jsonData.metrics.hbase.regionserver['test'].length).to.be.true;
-    expect(result[0].data[0]).to.have.property('y').to.equal(11);
-    expect(result[0].data[0]).to.have.property('x').to.equal(1424948261);
+    }
+  };
+
+  beforeEach(function () {
+    regionServerView = App.ChartServiceMetricsAMS_RegionServerBaseView.extend({
+      id: "service-metrics-ambari-metrics-region-server-test",
+      title: 'test-title',
+      ajaxIndex: 'service.metrics.ambari_metrics.region_server.regions',
+      displayName: 'test-display-name',
+      regionServerName: 'test'
+    }).create();
+  });
+
+  describe('#transformToSeries', function () {
+
+    beforeEach(function () {
+      this.result = regionServerView.transformToSeries(jsonData);
+    });
+
+    it('displayName', function () {
+      expect(this.result[0].name === regionServerView.displayName).to.be.true;
+    });
+
+    it('data.length', function () {
+      expect(this.result[0].data.length).to.equal(jsonData.metrics.hbase.regionserver['test'].length);
+    });
+
+    it('y-property', function () {
+      expect(this.result[0].data[0]).to.have.property('y').to.equal(11);
+    });
+
+    it('x-property', function () {
+      expect(this.result[0].data[0]).to.have.property('x').to.equal(1424948261);
+    });
+
   });
+
 });

+ 175 - 103
ambari-web/test/views/main/service/info/summary_test.js

@@ -50,67 +50,113 @@ describe('App.MainServiceInfoSummaryView', function() {
       expect(view.get('servers')).to.be.empty;
     });
 
-    it('if one server exists then first server should have isComma and isAnd property false', function () {
-      view.set('controller.content', Em.Object.create({
-        id: 'ZOOKEEPER',
-        serviceName: 'ZOOKEEPER',
-        hostComponents: [
-          Em.Object.create({
-            displayName: '',
-            isMaster: true
-          })
-        ]
-      }));
-      expect(view.get('servers').objectAt(0).isComma).to.equal(false);
-      expect(view.get('servers').objectAt(0).isAnd).to.equal(false);
+    describe('if one server exists then first server should have isComma and isAnd property false', function () {
+
+      beforeEach(function () {
+        view.set('controller.content', Em.Object.create({
+          id: 'ZOOKEEPER',
+          serviceName: 'ZOOKEEPER',
+          hostComponents: [
+            Em.Object.create({
+              displayName: '',
+              isMaster: true
+            })
+          ]
+        }));
+      });
+
+      it('isComma', function () {
+        expect(view.get('servers').objectAt(0).isComma).to.equal(false);});
+
+      it('isAnd', function () {
+        expect(view.get('servers').objectAt(0).isAnd).to.equal(false);
+      });
     });
 
-    it('if more than one servers exist then first server should have isComma - true and isAnd - false', function () {
-      view.set('controller.content', Em.Object.create({
-        id: 'ZOOKEEPER',
-        serviceName: 'ZOOKEEPER',
-        hostComponents: [
-          Em.Object.create({
-            displayName: '',
-            isMaster: true
-          }),
-          Em.Object.create({
-            displayName: '',
-            isMaster: true
-          })
-        ]
-      }));
-      expect(view.get('servers').objectAt(0).isComma).to.equal(true);
-      expect(view.get('servers').objectAt(0).isAnd).to.equal(false);
-      expect(view.get('servers').objectAt(1).isComma).to.equal(false);
-      expect(view.get('servers').objectAt(1).isAnd).to.equal(false);
+    describe('if more than one servers exist then first server should have isComma - true and isAnd - false', function() {
+
+      beforeEach(function () {
+        view.set('controller.content', Em.Object.create({
+          id: 'ZOOKEEPER',
+          serviceName: 'ZOOKEEPER',
+          hostComponents: [
+            Em.Object.create({
+              displayName: '',
+              isMaster: true
+            }),
+            Em.Object.create({
+              displayName: '',
+              isMaster: true
+            })
+          ]
+        }));
+      });
+
+      it('0 isComma', function () {
+        expect(view.get('servers').objectAt(0).isComma).to.equal(true);
+      });
+
+      it('0 isAnd', function () {
+        expect(view.get('servers').objectAt(0).isAnd).to.equal(false);
+      });
+
+      it('1 isComma', function () {
+        expect(view.get('servers').objectAt(1).isComma).to.equal(false);
+      });
+
+      it('1 isAnd', function () {
+        expect(view.get('servers').objectAt(1).isAnd).to.equal(false);
+      });
+
     });
 
-    it('if more than two servers exist then second server should have isComma - false and isAnd - true', function () {
-      view.set('controller.content', Em.Object.create({
-        id: 'ZOOKEEPER',
-        serviceName: 'ZOOKEEPER',
-        hostComponents: [
-          Em.Object.create({
-            displayName: '',
-            isMaster: true
-          }),
-          Em.Object.create({
-            displayName: '',
-            isMaster: true
-          }),
-          Em.Object.create({
-            displayName: '',
-            isMaster: true
-          })
-        ]
-      }));
-      expect(view.get('servers').objectAt(0).isComma).to.equal(true);
-      expect(view.get('servers').objectAt(0).isAnd).to.equal(false);
-      expect(view.get('servers').objectAt(1).isComma).to.equal(false);
-      expect(view.get('servers').objectAt(1).isAnd).to.equal(true);
-      expect(view.get('servers').objectAt(2).isComma).to.equal(false);
-      expect(view.get('servers').objectAt(2).isAnd).to.equal(false);
+    describe('if more than two servers exist then second server should have isComma - false and isAnd - true', function () {
+
+      beforeEach(function () {
+        view.set('controller.content', Em.Object.create({
+          id: 'ZOOKEEPER',
+          serviceName: 'ZOOKEEPER',
+          hostComponents: [
+            Em.Object.create({
+              displayName: '',
+              isMaster: true
+            }),
+            Em.Object.create({
+              displayName: '',
+              isMaster: true
+            }),
+            Em.Object.create({
+              displayName: '',
+              isMaster: true
+            })
+          ]
+        }));
+      });
+
+      it('0 isComma', function () {
+        expect(view.get('servers').objectAt(0).isComma).to.equal(true);
+      });
+
+      it('0 isAnd', function () {
+        expect(view.get('servers').objectAt(0).isAnd).to.equal(false);
+      });
+
+      it('1 isComma', function () {
+        expect(view.get('servers').objectAt(1).isComma).to.equal(false);
+      });
+
+      it('1 isAnd', function () {
+        expect(view.get('servers').objectAt(1).isAnd).to.equal(true);
+      });
+
+      it('2 isComma', function () {
+        expect(view.get('servers').objectAt(2).isComma).to.equal(false);
+      });
+
+      it('2 isAnd', function () {
+        expect(view.get('servers').objectAt(2).isAnd).to.equal(false);
+      });
+
     });
 
   });
@@ -398,58 +444,84 @@ describe('App.MainServiceInfoSummaryView', function() {
   });
 
   describe("#restartAllStaleConfigComponents", function () {
-    it("trigger restartAllServiceHostComponents", function () {
-      var view = App.MainServiceInfoSummaryView.create({
-        controller: Em.Object.create({
-          content: {
-            serviceName: "HDFS"
-          },
-          getActiveWidgetLayout: Em.K
-        }),
-        service: Em.Object.create({
-          displayName: 'HDFS'
-        })
+
+    describe('trigger restartAllServiceHostComponents', function () {
+      var view;
+      beforeEach(function () {
+        view = App.MainServiceInfoSummaryView.create({
+          controller: Em.Object.create({
+            content: {
+              serviceName: "HDFS"
+            },
+            getActiveWidgetLayout: Em.K
+          }),
+          service: Em.Object.create({
+            displayName: 'HDFS'
+          })
+        });
+        sinon.stub(batchUtils, "restartAllServiceHostComponents", Em.K);
+      });
+
+      afterEach(function () {
+        batchUtils.restartAllServiceHostComponents.restore();
+      });
+
+      it('batch request is started', function () {
+        view.restartAllStaleConfigComponents().onPrimary();
+        expect(batchUtils.restartAllServiceHostComponents.calledOnce).to.equal(true);
       });
-      sinon.stub(batchUtils, "restartAllServiceHostComponents", Em.K);
-      view.restartAllStaleConfigComponents().onPrimary();
-      expect(batchUtils.restartAllServiceHostComponents.calledOnce).to.equal(true);
-      batchUtils.restartAllServiceHostComponents.restore();
+
     });
-    it("trigger check last check point warning before triggering restartAllServiceHostComponents", function () {
-      var view = App.MainServiceInfoSummaryView.create({
-        controller: Em.Object.create({
-          content: {
-            serviceName: "HDFS",
-            hostComponents: [{
-              componentName: 'NAMENODE',
-              workStatus: 'STARTED'
-            }],
-            restartRequiredHostsAndComponents: {
-              "host1": ['NameNode'],
-              "host2": ['DataNode', 'ZooKeeper']
-            }
-          },
-          getActiveWidgetLayout: Em.K
-        }),
-        service: Em.Object.create({
-          displayName: 'HDFS'
-        })
+
+    describe('trigger check last check point warning before triggering restartAllServiceHostComponents', function () {
+
+      var view;
+      var mainServiceItemController;
+
+      beforeEach(function () {
+        view = App.MainServiceInfoSummaryView.create({
+          controller: Em.Object.create({
+            content: {
+              serviceName: "HDFS",
+              hostComponents: [{
+                componentName: 'NAMENODE',
+                workStatus: 'STARTED'
+              }],
+              restartRequiredHostsAndComponents: {
+                "host1": ['NameNode'],
+                "host2": ['DataNode', 'ZooKeeper']
+              }
+            },
+            getActiveWidgetLayout: Em.K
+          }),
+          service: Em.Object.create({
+            displayName: 'HDFS'
+          })
+        });
+        mainServiceItemController = App.MainServiceItemController.create({});
+        sinon.stub(mainServiceItemController, 'checkNnLastCheckpointTime', function() {
+          return true;
+        });
+        sinon.stub(App.router, 'get', function(k) {
+          if ('mainServiceItemController' === k) {
+            return mainServiceItemController;
+          }
+          return Em.get(App.router, k);
+        });
       });
-      var mainServiceItemController = App.MainServiceItemController.create({});
-      sinon.stub(mainServiceItemController, 'checkNnLastCheckpointTime', function() {
-        return true;
+
+      afterEach(function () {
+        mainServiceItemController.checkNnLastCheckpointTime.restore();
+        App.router.get.restore();
       });
-      sinon.stub(App.router, 'get', function(k) {
-        if ('mainServiceItemController' === k) {
-          return mainServiceItemController;
-        }
-        return Em.get(App.router, k);
+
+      it('NN Last CheckPoint is checked', function () {
+        view.restartAllStaleConfigComponents();
+        expect(mainServiceItemController.checkNnLastCheckpointTime.calledOnce).to.equal(true);
       });
-      view.restartAllStaleConfigComponents();
-      expect(mainServiceItemController.checkNnLastCheckpointTime.calledOnce).to.equal(true);
-      mainServiceItemController.checkNnLastCheckpointTime.restore();
-      App.router.get.restore();
+
     });
+
   });
 
 });

+ 10 - 2
ambari-web/test/views/wizard/step0_view_test.js

@@ -75,14 +75,22 @@ describe('App.WizardStep0ViewClusterNameInput', function () {
   });
 
   describe('#keyPress', function() {
+
+    beforeEach(function () {
+      sinon.spy(view.get('parentView.controller'), 'submit');
+    });
+
+    afterEach(function () {
+      view.get('parentView.controller').submit.restore();
+    });
+
     it('should return true if pressed not Enter', function() {
       expect(view.keyPress({keyCode: 1})).to.equal(true);
+      expect(view.get('parentView.controller').submit.called).to.equal(false);
     });
     it('should submit form if Enter pressed', function() {
-      sinon.spy(view.get('parentView.controller'), 'submit');
       expect(view.keyPress({keyCode: 13})).to.equal(false);
       expect(view.get('parentView.controller').submit.calledOnce).to.equal(true);
-      view.get('parentView.controller').submit.restore();
     });
   });
 

+ 9 - 2
ambari-web/test/views/wizard/step10_view_test.js

@@ -28,11 +28,18 @@ describe('App.WizardStep10View', function() {
     });
   });
   describe('#didInsertElement()', function() {
-    it('should call loadStep', function() {
+
+    beforeEach(function () {
       sinon.stub(view.get('controller'), 'loadStep', Em.K);
+    });
+
+    afterEach(function () {
+      view.get('controller').loadStep.restore();
+    });
+
+    it('should call loadStep', function() {
       view.didInsertElement();
       expect(view.get('controller').loadStep.calledOnce).to.equal(true);
-      view.get('controller').loadStep.restore();
     });
   });
 

+ 55 - 18
ambari-web/test/views/wizard/step1_view_test.js

@@ -169,25 +169,55 @@ describe('App.WizardStep1View', function () {
       expect(view.get('operatingSystems.length')).to.equal(0);
     });
 
-    it('should create repo groups from repo list', function () {
-      controller = App.WizardStep1Controller.create({
-        content: {
-          stacks: App.Stack.find()
-        }
+    describe('should create repo groups from repo list', function () {
+
+      var repositories;
+
+      beforeEach(function () {
+        controller = App.WizardStep1Controller.create({
+          content: {
+            stacks: App.Stack.find()
+          }
+        });
+
+        view = App.WizardStep1View.create({'controller': controller});
+        view.set('$', function () {
+          return Em.Object.create({hide: Em.K, toggle: Em.K});
+        });
+
+        repositories = view.get('allRepositories');
       });
-      view = App.WizardStep1View.create({'controller': controller});
-      view.set('$', function () {
-        return Em.Object.create({hide: Em.K, toggle: Em.K});
+
+      it('operatingSystems.length', function () {
+        expect(view.get('operatingSystems.length')).to.equal(2);
+      });
+
+      it('operatingSystems.0.osType', function () {
+        expect(view.get('operatingSystems')[0].get('osType')).to.equal('redhat5');
+      });
+
+      it('operatingSystems.1.osType', function () {
+        expect(view.get('operatingSystems')[1].get('osType')).to.equal('redhat6');
+      });
+
+      it('operatingSystems.0.isSelected', function () {
+        expect(view.get('operatingSystems')[0].get('isSelected')).to.be.true;
       });
-      var repositories = view.get('allRepositories');
-      expect(view.get('operatingSystems.length')).to.equal(2);
-      expect(view.get('operatingSystems')[0].get('osType')).to.equal('redhat5');
-      expect(view.get('operatingSystems')[1].get('osType')).to.equal('redhat6');
-      expect(view.get('operatingSystems')[0].get('isSelected')).to.be.true;
-      expect(view.get('operatingSystems')[1].get('isSelected')).to.be.true;
-      expect(view.get('operatingSystems')[0].get('repositories')).to.eql([repositories[0], repositories[1]]);
-      expect(view.get('operatingSystems')[1].get('repositories')).to.eql([repositories[2], repositories[3]]);
+
+      it('operatingSystems.1.isSelected', function () {
+        expect(view.get('operatingSystems')[1].get('isSelected')).to.be.true;
+      });
+
+      it('operatingSystems.0.repositories', function () {
+        expect(view.get('operatingSystems')[0].get('repositories')).to.eql([repositories[0], repositories[1]]);
+      });
+
+      it('operatingSystems.1.repositories', function () {
+        expect(view.get('operatingSystems')[1].get('repositories')).to.eql([repositories[2], repositories[3]]);
+      });
+
     });
+
   });
 
   describe('#invalidFormatUrlExist', function () {
@@ -312,12 +342,19 @@ describe('App.WizardStep1View', function () {
   });
 
   describe('#didInsertElement', function () {
-    it('should create tooltip', function () {
+
+    beforeEach(function () {
       sinon.stub($.fn, 'tooltip', Em.K);
+    });
+
+    afterEach(function () {
+      $.fn.tooltip.restore();
+    });
+
+    it('should create tooltip', function () {
       view.set('isRLCollapsed', false);
       view.didInsertElement();
       expect($.fn.tooltip.calledOnce).to.equal(true);
-      $.fn.tooltip.restore();
     });
   });
 

+ 91 - 40
ambari-web/test/views/wizard/step3/hostWarningPopupBody_view_test.js

@@ -53,11 +53,18 @@ describe('App.WizardStep3HostWarningPopupBody', function() {
   });
 
   describe('#showHostsPopup', function() {
-    it('should call App.ModalPopup.show', function() {
+
+    beforeEach(function () {
       sinon.stub(App.ModalPopup, 'show', Em.K);
+    });
+
+    afterEach(function () {
+      App.ModalPopup.show.restore();
+    });
+
+    it('should call App.ModalPopup.show', function() {
       view.showHostsPopup({context: []});
       expect(App.ModalPopup.show.calledOnce).to.equal(true);
-      App.ModalPopup.show.restore();
     });
   });
 
@@ -115,6 +122,15 @@ describe('App.WizardStep3HostWarningPopupBody', function() {
     });
 
     describe('#click', function() {
+
+      beforeEach(function () {
+        sinon.spy(lazyloading, 'run');
+      });
+
+      afterEach(function () {
+        lazyloading.run.restore();
+      });
+
       Em.A([
           {
             isLoaded: false,
@@ -142,7 +158,6 @@ describe('App.WizardStep3HostWarningPopupBody', function() {
               isLoaded: test.isLoaded,
               isLazyLoading: test.isLazyLoading
             });
-            sinon.spy(lazyloading, 'run');
             v.click();
             if (test.e) {
               expect(lazyloading.run.calledOnce).to.equal(true);
@@ -150,7 +165,6 @@ describe('App.WizardStep3HostWarningPopupBody', function() {
             else {
               expect(lazyloading.run.called).to.equal(false);
             }
-            lazyloading.run.restore();
           });
         });
     });
@@ -181,47 +195,40 @@ describe('App.WizardStep3HostWarningPopupBody', function() {
     ];
     beforeEach(function() {
       view.reopen({content: content, warningsByHost: [], hostNamesWithWarnings: ['c', 'd']});
+      this.newContent = view.get('contentInDetails');
     });
     it('should map hosts', function() {
-      var newContent = view.get('contentInDetails');
-      expect(newContent.contains('c d')).to.equal(true);
+      expect(this.newContent.contains('c d')).to.equal(true);
     });
     it('should map firewall warnings', function() {
-      var newContent = view.get('contentInDetails');
-      expect(newContent.contains('n1<br>n2<br>n3')).to.equal(true);
+      expect(this.newContent.contains('n1<br>n2<br>n3')).to.equal(true);
     });
     it('should map fileFolders warnings', function() {
-      var newContent = view.get('contentInDetails');
-      expect(newContent.contains('n4 n5 n6')).to.equal(true);
+      expect(this.newContent.contains('n4 n5 n6')).to.equal(true);
     });
     it('should map process warnings', function() {
-      var newContent = view.get('contentInDetails');
-      expect(newContent.contains('(h1,u1,pid1)')).to.equal(true);
-      expect(newContent.contains('(h2,u1,pid1)')).to.equal(true);
-      expect(newContent.contains('(h2,u2,pid2)')).to.equal(true);
-      expect(newContent.contains('(h3,u1,pid3)')).to.equal(true);
+      expect(this.newContent.contains('(h1,u1,pid1)')).to.equal(true);
+      expect(this.newContent.contains('(h2,u1,pid1)')).to.equal(true);
+      expect(this.newContent.contains('(h2,u2,pid2)')).to.equal(true);
+      expect(this.newContent.contains('(h3,u1,pid3)')).to.equal(true);
     });
     it('should map package warnings', function() {
-      var newContent = view.get('contentInDetails');
-      expect(newContent.contains('n10 n11 n12')).to.equal(true);
+      expect(this.newContent.contains('n10 n11 n12')).to.equal(true);
     });
     it('should map service warnings', function() {
-      var newContent = view.get('contentInDetails');
-      expect(newContent.contains('n13 n14 n15')).to.equal(true);
+      expect(this.newContent.contains('n13 n14 n15')).to.equal(true);
     });
     it('should map user warnings', function() {
-      var newContent = view.get('contentInDetails');
-      expect(newContent.contains('n16 n17 n18')).to.equal(true);
+      expect(this.newContent.contains('n16 n17 n18')).to.equal(true);
     });
     it('should map reverse lookup warnings', function() {
-      var newContent = view.get('contentInDetails');
-      expect(newContent.contains('h1')).to.equal(true);
+      expect(this.newContent.contains('h1')).to.equal(true);
     });
   });
 
   describe('#content', function () {
 
-    it('should return array with warning objects', function () {
+    beforeEach(function () {
       view.set('bodyController', Em.Object.create({
         hostCheckWarnings: [
           {
@@ -333,23 +340,67 @@ describe('App.WizardStep3HostWarningPopupBody', function() {
           }
         ]
       });
-      var content = view.get('content');
-      expect(content.mapProperty('isCollapsed').uniq()).to.eql([true]);
-      expect(content.findProperty('category', 'hostNameResolution').get('warnings')[0].hostsList).
+      this.content = view.get('content');
+    });
+
+    it('isCollapsed', function () {
+      expect(this.content.mapProperty('isCollapsed').uniq()).to.eql([true]);
+    });
+
+    it('hostNameResolution', function () {
+      expect(this.content.findProperty('category', 'hostNameResolution').get('warnings')[0].hostsList).
         to.equal('h0<br>h1<br>h2<br>h3<br>h4<br>h5<br>h5<br>h7<br>h8<br>h9<br> ' + Em.I18n.t('installer.step3.hostWarningsPopup.moreHosts').format(1));
-      expect(content.findProperty('category', 'repositories').get('warnings')[0].hostsList).to.equal('h11<br>h12');
-      expect(content.findProperty('category', 'disk').get('warnings')[0].hostsList).to.equal('h13');
-      expect(content.findProperty('category', 'jdk').get('warnings')[0].hostsList).to.equal('h14');
-      expect(content.findProperty('category', 'thp').get('warnings')[0].hostsList).to.equal('h15');
-      expect(content.findProperty('category', 'firewall').get('warnings').mapProperty('hostsList')).to.eql(['h16', 'h17']);
-      expect(content.findProperty('category', 'process').get('warnings')[0].hostsList).to.equal('h18');
-      expect(content.findProperty('category', 'package').get('warnings')[0].hostsList).to.equal('h19');
-      expect(content.findProperty('category', 'fileFolders').get('warnings')[0].hostsList).to.equal('h20');
-      expect(content.findProperty('category', 'service').get('warnings')[0].hostsList).to.equal('h21');
-      expect(content.findProperty('category', 'user').get('warnings')[0].hostsList).to.equal('h22');
-      expect(content.findProperty('category', 'misc').get('warnings')[0].hostsList).to.equal('h23');
-      expect(content.findProperty('category', 'alternatives').get('warnings')[0].hostsList).to.equal('h24');
-      expect(content.findProperty('category', 'reverseLookup').get('warnings').mapProperty('hostsList')).to.eql([
+    });
+
+    it('repositories', function () {
+      expect(this.content.findProperty('category', 'repositories').get('warnings')[0].hostsList).to.equal('h11<br>h12');
+    });
+
+    it('disk', function () {
+      expect(this.content.findProperty('category', 'disk').get('warnings')[0].hostsList).to.equal('h13');
+    });
+
+    it('jdk', function () {
+      expect(this.content.findProperty('category', 'jdk').get('warnings')[0].hostsList).to.equal('h14');
+    });
+
+    it('thp', function () {
+      expect(this.content.findProperty('category', 'thp').get('warnings')[0].hostsList).to.equal('h15');
+    });
+
+    it('firewall', function () {
+      expect(this.content.findProperty('category', 'firewall').get('warnings').mapProperty('hostsList')).to.eql(['h16', 'h17']);
+    });
+
+    it('process', function () {
+      expect(this.content.findProperty('category', 'process').get('warnings')[0].hostsList).to.equal('h18');});
+
+    it('package', function () {
+      expect(this.content.findProperty('category', 'package').get('warnings')[0].hostsList).to.equal('h19');
+    });
+
+    it('fileFolders', function () {
+      expect(this.content.findProperty('category', 'fileFolders').get('warnings')[0].hostsList).to.equal('h20');
+    });
+
+    it('service', function () {
+      expect(this.content.findProperty('category', 'service').get('warnings')[0].hostsList).to.equal('h21');
+    });
+
+    it('user', function () {
+      expect(this.content.findProperty('category', 'user').get('warnings')[0].hostsList).to.equal('h22');
+    });
+
+    it('misc', function () {
+      expect(this.content.findProperty('category', 'misc').get('warnings')[0].hostsList).to.equal('h23');
+    });
+
+    it('alternatives', function () {
+      expect(this.content.findProperty('category', 'alternatives').get('warnings')[0].hostsList).to.equal('h24');
+    });
+
+    it('reverseLookup', function () {
+      expect(this.content.findProperty('category', 'reverseLookup').get('warnings').mapProperty('hostsList')).to.eql([
         'h25', 'h26', 'h27', 'h28', 'h29', 'h30', 'h31', 'h32', 'h33', 'h34', 'h35<br>h36'
       ]);
     });

+ 18 - 5
ambari-web/test/views/wizard/step3_view_test.js

@@ -352,14 +352,20 @@ describe('App.WizardStep3View', function () {
   });
 
   describe('#hostBootStatusObserver', function() {
-    it('should call "Em.run.once" three times', function() {
+
+    beforeEach(function () {
       sinon.spy(Em.run, 'once');
       view.hostBootStatusObserver();
-      expect(Em.run.once.calledThrice).to.equal(true);
+    });
+
+    afterEach(function () {
+      Em.run.once.restore();
+    });
+
+    it('should call "Em.run.once" three times', function() {
       expect(Em.run.once.firstCall.args[1]).to.equal('countCategoryHosts');
       expect(Em.run.once.secondCall.args[1]).to.equal('filter');
       expect(Em.run.once.thirdCall.args[1]).to.equal('monitorStatuses');
-      Em.run.once.restore();
     });
   });
 
@@ -397,12 +403,19 @@ describe('App.WizardStep3View', function () {
   });
 
   describe('#watchSelectionOnce', function() {
-    it('should call "Em.run.once" one time', function() {
+
+    beforeEach(function () {
       sinon.spy(Em.run, 'once');
       view.watchSelectionOnce();
+    });
+
+    afterEach(function () {
+      Em.run.once.restore();
+    });
+
+    it('should call "Em.run.once" one time', function() {
       expect(Em.run.once.calledOnce).to.equal(true);
       expect(Em.run.once.firstCall.args[1]).to.equal('watchSelection');
-      Em.run.once.restore();
     });
   });
 

+ 17 - 4
ambari-web/test/views/wizard/step5_view_test.js

@@ -89,11 +89,18 @@ describe('App.WizardStep5View', function() {
   });
 
   describe('#didInsertElement', function() {
-    it('should call controller.loadStep', function() {
+
+    beforeEach(function () {
       sinon.stub(view.get('controller'), 'loadStep', Em.K);
+    });
+
+    afterEach(function () {
+      view.get('controller').loadStep.restore();
+    });
+
+    it('should call controller.loadStep', function() {
       view.didInsertElement();
       expect(view.get('controller').loadStep.calledOnce).to.equal(true);
-      view.get('controller').loadStep.restore();
     });
   });
 
@@ -361,15 +368,21 @@ describe('App.InputHostView', function() {
       }
     ]);
 
+    beforeEach(function () {
+      sinon.stub(view, 'initContent', Em.K);
+    });
+
+    afterEach(function () {
+      view.initContent.restore();
+    });
+
     tests.forEach(function(test) {
       it(test.m, function() {
         view.set('content', test.content);
         view.set('component', {component_name: test.componentName});
         view.set('controller.componentToRebalance', test.componentToRebalance);
-        sinon.stub(view, 'initContent', Em.K);
         view.rebalanceComponentHostsOnce();
         expect(view.initContent.calledOnce).to.equal(test.e.initContent);
-        view.initContent.restore();
       });
     });
   });

+ 10 - 4
ambari-web/test/views/wizard/step6_view_test.js

@@ -166,25 +166,31 @@ describe('App.WizardStep6HostView', function() {
   });
 
   describe('#didInsertElement', function() {
+
+    var data = [];
+
     beforeEach(function() {
       sinon.stub(App, 'popover', Em.K);
+      sinon.stub(view.get('controller'), 'getMasterComponentsForHost', function() {return data;});
     });
+
     afterEach(function() {
       App.popover.restore();
+      view.get('controller').getMasterComponentsForHost.restore();
     });
+
     it('should create popover if not controller.isMasters', function() {
-      sinon.stub(view.get('controller'), 'getMasterComponentsForHost', function() {return [{}, {}];});
+      data = [{}, {}];
       view.set('controller.isMasters', false);
       view.didInsertElement();
       expect(App.popover.calledOnce).to.equal(true);
-      view.get('controller').getMasterComponentsForHost.restore();
     });
+
     it('should create popover even if controller.getMasterComponentsForHost is an empty array', function() {
-      sinon.stub(view.get('controller'), 'getMasterComponentsForHost', function() {return [];});
+      data = [{}];
       view.set('controller.isMasters', true);
       view.didInsertElement();
       expect(App.popover.calledOnce).to.equal(true);
-      view.get('controller').getMasterComponentsForHost.restore();
     });
   });
 

+ 18 - 4
ambari-web/test/views/wizard/step8_view_test.js

@@ -30,23 +30,37 @@ describe('App.WizardStep8View', function() {
   });
 
   describe('#didInsertElement', function() {
-    it('should call loadStep', function() {
+
+    beforeEach(function () {
       view.set('controller', Em.Object.create({
         loadStep: Em.K
       }));
       sinon.spy(view.get('controller'), 'loadStep');
+    });
+
+    afterEach(function () {
+      view.get('controller').loadStep.restore();
+    });
+
+    it('should call loadStep', function() {
       view.didInsertElement();
       expect(view.get('controller').loadStep.calledOnce).to.equal(true);
-      view.get('controller').loadStep.restore();
     });
   });
 
   describe('#printReview', function() {
-    it('should call jqprint', function() {
+
+    beforeEach(function() {
       sinon.stub($.fn, 'jqprint', Em.K);
+    });
+
+    afterEach(function () {
+      $.fn.jqprint.restore();
+    });
+
+    it('should call jqprint', function() {
       view.printReview();
       expect($.fn.jqprint.calledOnce).to.equal(true);
-      $.fn.jqprint.restore();
     });
   });
 

+ 136 - 74
ambari-web/test/views/wizard/step9/hostLogPopupBody_view_test.js

@@ -101,11 +101,18 @@ describe('App.WizardStep9HostLogPopupBodyView', function() {
   });
 
   describe('#backToTaskList', function() {
-    it('should call destroyClipBoard', function() {
+
+    beforeEach(function () {
       sinon.stub(view, 'destroyClipBoard', Em.K);
+    });
+
+    afterEach(function () {
+      view.destroyClipBoard.restore();
+    });
+
+    it('should call destroyClipBoard', function() {
       view.backToTaskList();
       expect(view.destroyClipBoard.calledOnce).to.equal(true);
-      view.destroyClipBoard.restore();
     });
     it('should set isLogWrapHidden to true', function() {
       view.set('isLogWrapHidden', false);
@@ -154,104 +161,159 @@ describe('App.WizardStep9HostLogPopupBodyView', function() {
       }
     };
 
-    it('should map tasks', function() {
+    beforeEach(function () {
       view.set('parentView.host.logTasks', [testTask]);
-      var t = view.get('tasks');
-      expect(t.length).to.equal(1);
-      var first = t[0];
-      expect(first.get('id')).to.equal(1);
-      expect(first.get('requestId')).to.equal(2);
-      expect(first.get('command')).to.equal('cmd');
-      expect(first.get('commandDetail')).to.equal(' Test Component Description');
-      expect(first.get('role')).to.equal('Pig');
-      expect(first.get('stderr')).to.equal('stderr');
-      expect(first.get('stdout')).to.equal('stdout');
-      expect(first.get('isVisible')).to.equal(true);
-      expect(first.get('hostName')).to.equal('host1');
+      this.t = view.get('tasks');
+      this.first = this.t[0];
+    });
+
+    it('should map tasks', function() {
+      expect(this.t.length).to.equal(1);
+    });
+
+    it('should map id', function() {
+      expect(this.first.get('id')).to.equal(1);
+    });
+
+    it('should map requestId', function() {
+      expect(this.first.get('requestId')).to.equal(2);
+    });
+
+    it('should map command', function() {
+      expect(this.first.get('command')).to.equal('cmd');
     });
 
-    it('should set cog icon', function() {
-      var t = Em.copy(testTask);
-      t.Tasks.status = 'pending';
-      view.set('parentView.host.logTasks', [t]);
-      var first = view.get('tasks')[0];
-      expect(first.get('icon')).to.equal('icon-cog');
+    it('should map commandDetail', function() {
+      expect(this.first.get('commandDetail')).to.equal(' Test Component Description');
     });
 
-    it('should set cog icon (2)', function() {
-      var t = Em.copy(testTask);
-      t.Tasks.status = 'queued';
-      view.set('parentView.host.logTasks', [t]);
-      var first = view.get('tasks')[0];
-      expect(first.get('icon')).to.equal('icon-cog');
+    it('should map role', function() {
+      expect(this.first.get('role')).to.equal('Pig');
     });
 
-    it('should set cogs icon', function() {
-      var t = Em.copy(testTask);
-      t.Tasks.status = 'in_progress';
-      view.set('parentView.host.logTasks', [t]);
-      var first = view.get('tasks')[0];
-      expect(first.get('icon')).to.equal('icon-cogs');
+    it('should map stderr', function() {
+      expect(this.first.get('stderr')).to.equal('stderr');
     });
 
-    it('should set ok icon', function() {
-      var t = Em.copy(testTask);
-      t.Tasks.status = 'completed';
-      view.set('parentView.host.logTasks', [t]);
-      var first = view.get('tasks')[0];
-      expect(first.get('icon')).to.equal('icon-ok');
+    it('should map stdout', function() {
+      expect(this.first.get('stdout')).to.equal('stdout');
     });
 
-    it('should set icon-exclamation-sign icon', function() {
-      var t = Em.copy(testTask);
-      t.Tasks.status = 'failed';
-      view.set('parentView.host.logTasks', [t]);
-      var first = view.get('tasks')[0];
-      expect(first.get('icon')).to.equal('icon-exclamation-sign');
+    it('should map isVisible', function() {
+      expect(this.first.get('isVisible')).to.equal(true);
     });
 
-    it('should set minus icon', function() {
-      var t = Em.copy(testTask);
-      t.Tasks.status = 'aborted';
-      view.set('parentView.host.logTasks', [t]);
-      var first = view.get('tasks')[0];
-      expect(first.get('icon')).to.equal('icon-minus');
+    it('should map hostName', function() {
+      expect(this.first.get('hostName')).to.equal('host1');
     });
 
-    it('should set time icon', function() {
-      var t = Em.copy(testTask);
-      t.Tasks.status = 'timedout';
-      view.set('parentView.host.logTasks', [t]);
-      var first = view.get('tasks')[0];
-      expect(first.get('icon')).to.equal('icon-time');
+    describe('icons', function () {
+
+      Em.A([
+        {
+          status: 'pending',
+          icon:'icon-cog'
+        },
+        {
+          status: 'queued',
+          icon:'icon-cog'
+        },
+        {
+          status: 'in_progress',
+          icon:'icon-cogs'
+        },
+        {
+          status: 'completed',
+          icon:'icon-ok'
+        },
+        {
+          status: 'failed',
+          icon:'icon-exclamation-sign'
+        },
+        {
+          status: 'aborted',
+          icon:'icon-minus'
+        },
+        {
+          status: 'timedout',
+          icon:'icon-time'
+        }
+      ]).forEach(function (test) {
+        it(test.status + ' -> ' + test.icon, function () {
+          var t = Em.copy(testTask);
+          t.Tasks.status = test.status;
+          view.set('parentView.host.logTasks', [t]);
+          view.propertyDidChange('tasks');
+          expect(view.get('tasks')[0].icon).to.equal(test.icon);
+        });
+      });
+
     });
 
   });
 
   describe('#toggleTaskLog', function() {
-    it('isLogWrapHidden is true', function() {
+
+    beforeEach(function () {
+      view.set('parentView.c', Em.Object.create({loadCurrentTaskLog: Em.K}));
+      sinon.spy(view.get('parentView.c'), 'loadCurrentTaskLog');
+    });
+
+    afterEach(function () {
+      view.get('parentView.c').loadCurrentTaskLog.restore();
+    });
+
+    describe('isLogWrapHidden is true', function () {
+
       var taskInfo = {
         id: 1,
         requestId: 2
       };
-      view.set('isLogWrapHidden', true);
-      view.set('parentView.c', Em.Object.create({loadCurrentTaskLog: Em.K}));
-      sinon.spy(view.get('parentView.c'), 'loadCurrentTaskLog');
-      view.toggleTaskLog({context: taskInfo});
-      expect(view.get('isLogWrapHidden')).to.equal(false);
-      expect(view.get('parentView.c.currentOpenTaskId')).to.equal(taskInfo.id);
-      expect(view.get('parentView.c.currentOpenTaskRequestId')).to.equal(taskInfo.requestId);
-      expect(view.get('parentView.c').loadCurrentTaskLog.calledOnce).to.equal(true);
-      view.get('parentView.c').loadCurrentTaskLog.restore();
+
+      beforeEach(function () {
+        view.set('isLogWrapHidden', true);
+        view.toggleTaskLog({context: taskInfo});
+      });
+
+      it('isLogWrapHidden is set false', function() {
+        expect(view.get('isLogWrapHidden')).to.equal(false);
+      });
+
+      it('currentOpenTaskId is equal to id', function() {
+        expect(view.get('parentView.c.currentOpenTaskId')).to.equal(taskInfo.id);
+      });
+
+      it('currentOpenTaskRequestId is equal to requestId', function() {
+        expect(view.get('parentView.c.currentOpenTaskRequestId')).to.equal(taskInfo.requestId);
+      });
+
+      it('loadCurrentTaskLog called once', function() {
+        expect(view.get('parentView.c').loadCurrentTaskLog.calledOnce).to.equal(true);
+      });
+
     });
-    it('isLogWrapHidden is false', function() {
+
+    describe('isLogWrapHidden is false', function () {
+
       var taskInfo = {};
-      view.set('isLogWrapHidden', false);
-      view.set('parentView.c', Em.Object.create({loadCurrentTaskLog: Em.K}));
-      view.toggleTaskLog({context: taskInfo});
-      expect(view.get('isLogWrapHidden')).to.equal(true);
-      expect(view.get('parentView.c.currentOpenTaskId')).to.equal(0);
-      expect(view.get('parentView.c.currentOpenTaskRequestId')).to.equal(0);
+
+      beforeEach(function () {
+        view.set('isLogWrapHidden', false);
+        view.toggleTaskLog({context: taskInfo});
+      });
+
+      it('isLogWrapHidden is set true', function() {
+        expect(view.get('isLogWrapHidden')).to.equal(true);
+      });
+
+      it('currentOpenTaskId is 0', function() {
+        expect(view.get('parentView.c.currentOpenTaskId')).to.equal(0);
+      });
+
+      it('currentOpenTaskRequestId is 0', function() {
+        expect(view.get('parentView.c.currentOpenTaskRequestId')).to.equal(0);
+      });
+
     });
   });
 

+ 34 - 14
ambari-web/test/views/wizard/step9_view_test.js

@@ -231,17 +231,21 @@ describe('App.WizardStep9View', function () {
   });
 
   describe('#content', function () {
-    it('should be equal to controller.hosts', function () {
+
+    var hosts = [{}, {}, {}];
+
+    beforeEach(function () {
       sinon.stub(v, 'hostStatusObserver', Em.K);
-      var hosts = [
-        {},
-        {},
-        {}
-      ];
       v.set('controller.hosts', hosts);
-      expect(v.get('content')).to.eql(hosts);
+    });
+
+    afterEach(function () {
       v.hostStatusObserver.restore();
     });
+
+    it('should be equal to controller.hosts', function () {
+      expect(v.get('content')).to.eql(hosts);
+    });
   });
 
   describe('#categoryObject', function () {
@@ -552,11 +556,18 @@ describe('App.HostStatusView', function () {
   });
 
   describe('#didInsertElement', function () {
-    it('should call onStatus', function () {
+
+    beforeEach(function () {
       sinon.stub(hv, 'onStatus', Em.K);
+    });
+
+    afterEach(function () {
+      hv.onStatus.restore();
+    });
+
+    it('should call onStatus', function () {
       hv.didInsertElement();
       expect(hv.onStatus.calledOnce).to.equal(true);
-      hv.onStatus.restore();
     });
   });
 
@@ -680,21 +691,30 @@ describe('App.HostStatusView', function () {
   });
 
   describe('#hostLogPopup', function() {
+
     describe('#onClose', function() {
+
       beforeEach(function() {
         hv.set('controller', {currentOpenTaskId: 123});
         hv.set('obj', Em.Object.create());
+        this.p = hv.hostLogPopup();
+        sinon.spy(this.p, 'hide');
+      });
+
+      afterEach(function () {
+        this.p.hide.restore();
       });
+
       it('popup should clear currentOpenTaskId', function() {
-        hv.hostLogPopup().onClose();
+        this.p.onClose();
         expect(hv.get('controller.currentOpenTaskId')).to.equal(0);
       });
+
       it('onClose popup should hide popup', function() {
-        var p = hv.hostLogPopup();
-        sinon.spy(p, 'hide');
-        p.onClose();
-        expect(p.hide.calledOnce).to.equal(true);
+        this.p.onClose();
+        expect(this.p.hide.calledOnce).to.equal(true);
       });
+
     });
   });