ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From onechipore...@apache.org
Subject [1/3] AMBARI-5474. Unit tests for steps 3-4. (onechiporenko)
Date Tue, 15 Apr 2014 14:55:06 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 7e5604788 -> 5ef841a0e


http://git-wip-us.apache.org/repos/asf/ambari/blob/5ef841a0/ambari-web/test/installer/step4_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/installer/step4_test.js b/ambari-web/test/installer/step4_test.js
index eedeeb8..72079cc 100644
--- a/ambari-web/test/installer/step4_test.js
+++ b/ambari-web/test/installer/step4_test.js
@@ -338,4 +338,13 @@ describe('App.WizardStep4Controller', function () {
     }, this);
   });
 
+  describe('#monitoringCheckPopup', function() {
+    it('should show App.ModalPopup', function() {
+      sinon.spy(App.ModalPopup, 'show');
+      controller.monitoringCheckPopup();
+      expect(App.ModalPopup.show.calledOnce).to.equal(true);
+      App.ModalPopup.show.restore();
+    });
+  })
+
 });
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/5ef841a0/ambari-web/test/views/wizard/step3/hostLogPopupBody_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/wizard/step3/hostLogPopupBody_view_test.js b/ambari-web/test/views/wizard/step3/hostLogPopupBody_view_test.js
new file mode 100644
index 0000000..934c3f8
--- /dev/null
+++ b/ambari-web/test/views/wizard/step3/hostLogPopupBody_view_test.js
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+require('views/wizard/step3/hostLogPopupBody_view');
+var view;
+describe('App.WizardStep3HostLogPopupBody', function() {
+
+  beforeEach(function() {
+    view = App.WizardStep3HostLogPopupBody.create({
+      parentView: Em.Object.create({
+        host: Em.Object.create()
+      })
+    });
+  });
+
+  describe('#bootLog', function() {
+    it('should be equal to parentView.host.bootLog', function() {
+      var log = 'i wanna play a game';
+      view.set('parentView.host.bootLog', log);
+      expect(view.get('bootLog')).to.equal(log);
+    });
+  });
+
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/5ef841a0/ambari-web/test/views/wizard/step3/hostWarningPopupFooter_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/wizard/step3/hostWarningPopupFooter_view_test.js b/ambari-web/test/views/wizard/step3/hostWarningPopupFooter_view_test.js
new file mode 100644
index 0000000..8b121d0
--- /dev/null
+++ b/ambari-web/test/views/wizard/step3/hostWarningPopupFooter_view_test.js
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+require('views/wizard/step3/hostWarningPopupFooter_view');
+var view;
+
+describe('App.WizardStep3HostWarningPopupFooter', function() {
+
+  beforeEach(function() {
+    view = App.WizardStep3HostWarningPopupFooter.create();
+    view.reopen({footerController: Em.Object.create()});
+  });
+
+  describe('#progressWidth', function() {
+    it('based on footerController.checksUpdateProgress', function() {
+      view.set('footerController.checksUpdateProgress', 42);
+      expect(view.get('progressWidth')).to.equal('width:42%');
+    });
+  });
+
+  describe('#isUpdateInProgress', function() {
+    var tests = Em.A([
+      {checksUpdateProgress: 0, e: false},
+      {checksUpdateProgress: 100, e: false},
+      {checksUpdateProgress: 50, e: true}
+    ]);
+    tests.forEach(function(test) {
+      it(test.checksUpdateProgress, function() {
+        view.set('footerController.checksUpdateProgress', test.checksUpdateProgress);
+        expect(view.get('isUpdateInProgress')).to.equal(test.e);
+      });
+    });
+  });
+
+  describe('#updateStatusClass', function() {
+    var tests = Em.A([
+      {checksUpdateStatus: 'SUCCESS', e: 'text-success'},
+      {checksUpdateStatus: 'FAILED', e: 'text-error'},
+      {checksUpdateStatus: 'PANIC', e: null}
+    ]);
+    tests.forEach(function(test) {
+      it(test.checksUpdateStatus, function() {
+        view.set('footerController.checksUpdateStatus', test.checksUpdateStatus);
+        if (Em.isNone(test.e)) {
+          expect(view.get('updateStatusClass')).to.be.null;
+        }
+        else {
+          expect(view.get('updateStatusClass')).to.equal(test.e);
+        }
+      })
+    });
+  });
+
+  describe('#updateStatus', function() {
+    var tests = Em.A([
+      {checksUpdateStatus: 'SUCCESS', e: Em.I18n.t('installer.step3.warnings.updateChecks.success')},
+      {checksUpdateStatus: 'FAILED', e: Em.I18n.t('installer.step3.warnings.updateChecks.failed')},
+      {checksUpdateStatus: 'PANIC', e: null}
+    ]);
+    tests.forEach(function(test) {
+      it(test.checksUpdateStatus, function() {
+        view.set('footerController.checksUpdateStatus', test.checksUpdateStatus);
+        if (Em.isNone(test.e)) {
+          expect(view.get('updateStatus')).to.be.null;
+        }
+        else {
+          expect(view.get('updateStatus')).to.equal(test.e);
+        }
+      })
+    });
+  });
+
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/5ef841a0/ambari-web/test/views/wizard/step3_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/wizard/step3_view_test.js b/ambari-web/test/views/wizard/step3_view_test.js
index b38068a..4f5d473 100644
--- a/ambari-web/test/views/wizard/step3_view_test.js
+++ b/ambari-web/test/views/wizard/step3_view_test.js
@@ -17,8 +17,9 @@
  */
 
 var App = require('app');
+require('messages');
 require('views/wizard/step3_view');
-
+var v;
 describe('App.WizardStep3View', function () {
   Em.run.next = function(callback){
     callback()
@@ -48,7 +49,7 @@ describe('App.WizardStep3View', function () {
     }.property('content')
   });
 
-  describe('watchSelection', function () {
+  describe('#watchSelection', function () {
     it('2 of 3 hosts selected', function () {
       view.watchSelection();
       expect(view.get('noHostsSelected')).to.equal(false);
@@ -68,22 +69,21 @@ describe('App.WizardStep3View', function () {
     });
   });
 
-
-  describe('selectAll', function () {
+  describe('#selectAll', function () {
     it('select all hosts', function () {
       view.selectAll();
       expect(view.get('content').everyProperty('isChecked', true)).to.equal(true);
     });
   });
 
-  describe('unSelectAll', function () {
+  describe('#unSelectAll', function () {
     it('unselect all hosts', function () {
       view.unSelectAll();
       expect(view.get('content').everyProperty('isChecked', false)).to.equal(true);
     });
   });
 
-  var testCases = [
+  var testCases = Em.A([
     {
       title: 'none hosts',
       content: [],
@@ -239,9 +239,9 @@ describe('App.WizardStep3View', function () {
         "FAILED": 0
       }
     }
-  ];
+  ]);
 
-  describe('countCategoryHosts', function () {
+  describe('#countCategoryHosts', function () {
     testCases.forEach(function (test) {
       it(test.title, function () {
         view.set('content', test.content);
@@ -253,7 +253,7 @@ describe('App.WizardStep3View', function () {
     }, this);
   });
 
-  describe('filter', function () {
+  describe('#filter', function () {
     testCases.forEach(function (test) {
       describe(test.title, function () {
         view.get('categories').forEach(function (category) {
@@ -268,4 +268,217 @@ describe('App.WizardStep3View', function () {
     }, this);
   });
 
+  describe('#monitorStatuses', function() {
+    var tests = Em.A([
+      {
+        controller: Em.Object.create({bootHosts: Em.A([])}),
+        m: 'Empty hosts list',
+        e: {status: 'alert-warn', linkText: ''}
+      },
+      {
+        controller: Em.Object.create({bootHosts: Em.A([{}]), isWarningsLoaded: false}),
+        m: 'isWarningsLoaded false',
+        e: {status: 'alert-info', linkText: ''}
+      },
+      {
+        controller: Em.Object.create({bootHosts: Em.A([{}]), isWarningsLoaded: true, isHostHaveWarnings:
true}),
+        m: 'isWarningsLoaded true, isHostHaveWarnings true',
+        e: {status: 'alert-warn', linkText: Em.I18n.t('installer.step3.warnings.linkText')}
+      },
+      {
+        controller: Em.Object.create({bootHosts: Em.A([{}]), isWarningsLoaded: true, repoCategoryWarnings:
['']}),
+        m: 'isWarningsLoaded true, repoCategoryWarnings not empty',
+        e: {status: 'alert-warn', linkText: Em.I18n.t('installer.step3.warnings.linkText')}
+      },
+      {
+        controller: Em.Object.create({bootHosts: Em.A([{}]), isWarningsLoaded: true, diskCategoryWarnings:
['']}),
+        m: 'isWarningsLoaded true, diskCategoryWarnings not empty',
+        e: {status: 'alert-warn', linkText: Em.I18n.t('installer.step3.warnings.linkText')}
+      },
+      {
+        controller: Em.Object.create({bootHosts: Em.A([{}]), isWarningsLoaded: true, diskCategoryWarnings:
[], repoCategoryWarnings: []}),
+        m: 'isWarningsLoaded true, diskCategoryWarnings is empty, repoCategoryWarnings is
empty',
+        e: {status: 'alert-success', linkText: Em.I18n.t('installer.step3.noWarnings.linkText')}
+      },
+      {
+        controller: Em.Object.create({bootHosts: Em.A([{bootStatus: 'FAILED'}]), isWarningsLoaded:
true, diskCategoryWarnings: [], repoCategoryWarnings: []}),
+        m: 'isWarningsLoaded true, diskCategoryWarnings is empty, repoCategoryWarnings is
empty, all failed',
+        e: {status: 'alert-warn', linkText: ''}
+      }
+    ]);
+
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        v = App.WizardStep3View.create({
+          controller: test.controller
+        });
+        v.monitorStatuses();
+        expect(v.get('status')).to.equal(test.e.status);
+        expect(v.get('linkText')).to.equal(test.e.linkText);
+      });
+    });
+  });
+
+  describe('#retrySelectedHosts', function() {
+    it('should set active category "All"', function() {
+      view.set('controller', Em.Object.create({retrySelectedHosts: Em.K, registeredHosts:
[]}));
+      view.retrySelectedHosts();
+      expect(view.get('categories').findProperty('hostsBootStatus', 'ALL').get('isActive')).to.equal(true);
+    });
+  });
+
+  describe('#selectCategory', function() {
+    var tests = Em.A(['ALL','RUNNING','REGISTERING','REGISTERED','FAILED']);
+    tests.forEach(function(test) {
+      it('should set active category "' + test + '"', function() {
+        view.set('controller', Em.Object.create({retrySelectedHosts: Em.K, registeredHosts:
[]}));
+        view.selectCategory({context:Em.Object.create({hostsBootStatus:test})});
+        expect(view.get('categories').findProperty('hostsBootStatus', test).get('isActive')).to.equal(true);
+      });
+    });
+  });
+
+  describe('#countCategoryHosts', function() {
+    it('should set host count for each category', function() {
+      view.set('content', Em.A([
+        Em.Object.create({bootStatus: 'RUNNING'}),
+        Em.Object.create({bootStatus: 'REGISTERING'}),
+        Em.Object.create({bootStatus: 'REGISTERED'}),
+        Em.Object.create({bootStatus: 'FAILED'})
+      ]));
+      view.countCategoryHosts();
+      expect(view.get('categories').mapProperty('hostsCount')).to.eql([4,1,1,1,1]);
+    });
+  });
+
+  describe('#hostBootStatusObserver', function() {
+    it('should call "Em.run.once" three times', function() {
+      sinon.spy(Em.run, 'once');
+      view.hostBootStatusObserver();
+      expect(Em.run.once.calledThrice).to.equal(true);
+      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();
+    });
+  });
+
+  describe('#watchSelection', function() {
+    describe('should set "pageChecked"', function() {
+      var tests = Em.A([
+        {pageContent: Em.A([]),m:'false if empty "pageContent"', e: false},
+        {pageContent: Em.A([{isChecked: false}]),m:'false if not-empty "pageContent" and
not all "isChecked" true', e: false},
+        {pageContent: Em.A([{isChecked: true}]),m:'true if not-empty "pageContent" and all
"isChecked" true', e: false}
+      ]);
+      tests.forEach(function(test) {
+        it(test.m, function() {
+          view.set('pageContent', test.pageContent);
+          view.watchSelection();
+          expect(view.get('pageChecked')).to.equal(test.e);
+        });
+      });
+    });
+    describe('should set "noHostsSelected" and "selectedHostsCount"', function() {
+      var tests = Em.A([
+        {pageContent: Em.A([]),content:Em.A([]),m:' - "true", "0" if content is empty',e:{selectedHostsCount:
0, noHostsSelected: true}},
+        {pageContent: Em.A([]),content:Em.A([Em.Object.create({isChecked: false})]),m:' -
"true", "0" if no one isChecked',e:{selectedHostsCount: 0, noHostsSelected: true}},
+        {pageContent: Em.A([]),content:Em.A([Em.Object.create({isChecked: true}),Em.Object.create({isChecked:
false})]),m:' - "false", "1" if one isChecked',e:{selectedHostsCount: 1, noHostsSelected:
false}}
+      ]);
+      tests.forEach(function(test) {
+        it(test.m, function() {
+          view.set('pageContent', test.pageContent);
+          view.set('content', test.content);
+          view.watchSelection();
+          expect(view.get('noHostsSelected')).to.equal(test.e.noHostsSelected);
+          expect(view.get('selectedHostsCount')).to.equal(test.e.selectedHostsCount);
+        });
+      });
+    });
+  });
+
+  describe('#watchSelectionOnce', function() {
+    it('should call "Em.run.once" one time', function() {
+      sinon.spy(Em.run, 'once');
+      view.watchSelectionOnce();
+      expect(Em.run.once.calledOnce).to.equal(true);
+      expect(Em.run.once.firstCall.args[1]).to.equal('watchSelection');
+      Em.run.once.restore();
+    });
+  });
+
+  describe('#selectedCategory', function() {
+    it('should equal category with isActive = true', function() {
+      view.get('categories').findProperty('hostsBootStatus', 'FAILED').set('isActive', true);
+      expect(view.get('selectedCategory.hostsBootStatus')).to.equal('FAILED');
+    });
+  });
+
+  describe('#onPageChecked', function() {
+    var tests = Em.A([
+      {
+        selectionInProgress: true,
+        pageContent: [Em.Object.create({isChecked: true}), Em.Object.create({isChecked: false})],
+        pageChecked: true,
+        m: 'shouldn\'t do nothing if selectionInProgress is true',
+        e: [true, false]
+      },
+      {
+        selectionInProgress: false,
+        pageContent: [Em.Object.create({isChecked: true}), Em.Object.create({isChecked: false})],
+        pageChecked: true,
+        m: 'should set each isChecked to pageChecked value',
+        e: [true, true]
+      }
+    ]);
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        v = App.WizardStep3View.create({
+          'pageContent': test.pageContent,
+          'pageChecked': test.pageChecked,
+          'selectionInProgress': test.selectionInProgress
+        });
+        v.onPageChecked();
+        expect(v.get('pageContent').mapProperty('isChecked')).to.eql(test.e);
+      });
+    });
+  });
+
+});
+
+var wView;
+describe('App.WizardHostView', function() {
+
+  beforeEach(function() {
+    wView = App.WizardHostView.create({
+      hostInfo: {},
+      controller: Em.Object.create({
+        removeHost: Em.K,
+        retryHost: Em.K
+      })
+    });
+    sinon.spy(wView.get('controller'), 'retryHost');
+    sinon.spy(wView.get('controller'), 'removeHost');
+  });
+
+  afterEach(function() {
+    wView.get('controller').retryHost.restore();
+    wView.get('controller').removeHost.restore();
+  });
+
+  describe('#retry', function() {
+    it('should call controller.retryHost', function() {
+      wView.retry();
+      expect(wView.get('controller').retryHost.calledWith({})).to.equal(true);
+      expect(wView.get('controller').retryHost.calledOnce).to.equal(true);
+    });
+  });
+
+  describe('#remove', function() {
+    it('should call controller.removeHost', function() {
+      wView.remove();
+      expect(wView.get('controller').removeHost.calledWith({})).to.equal(true);
+      expect(wView.get('controller').removeHost.calledOnce).to.equal(true);
+    });
+  });
+
 });


Mime
View raw message