Browse Source

AMBARI-7213. Fix ui unit tests for app.js. (jaimin)

Jaimin Jetly 10 years ago
parent
commit
221c5a13f2

+ 1 - 1
ambari-web/app/app.js

@@ -88,7 +88,7 @@ module.exports = Em.Application.create({
   isHaEnabled: function () {
     if (!this.get('isHadoop2Stack')) return false;
     var isHDFSInstalled = App.Service.find().findProperty('serviceName','HDFS');
-    return isHDFSInstalled && !this.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE');
+    return !!isHDFSInstalled && !this.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE');
   }.property('router.clusterController.isLoaded', 'isHadoop2Stack'),
 
   /**

+ 38 - 1
ambari-web/test/app_test.js

@@ -199,7 +199,20 @@ describe('App', function () {
     });
   });
 
-  describe('#isHaEnabled', function () {
+  describe('#isHaEnabled when HDFS is installed:', function () {
+
+    beforeEach(function () {
+      sinon.stub(App.Service, 'find', function () {
+        return [{
+          id : 'HDFS',
+          serviceName: 'HDFS'
+        }];
+      });
+    });
+
+    afterEach(function () {
+      App.Service.find.restore();
+    });
 
     it('if hadoop stack version less than 2 then isHaEnabled should be false', function () {
       App.set('currentStackVersion', 'HDP-1.3.1');
@@ -222,6 +235,30 @@ describe('App', function () {
     });
   });
 
+  describe('#isHaEnabled when HDFS is not installed:', function () {
+
+    beforeEach(function () {
+      sinon.stub(App.Service, 'find', function () {
+        return [{
+          id : 'ZOOKEEPER',
+          serviceName: 'ZOOKEEPER'
+        }];
+      });
+    });
+
+    afterEach(function () {
+      App.Service.find.restore();
+    });
+
+    it('if hadoop stack version higher than 2 but HDFS not installed then isHaEnabled should be false', function () {
+      App.set('currentStackVersion', 'HDP-2.1');
+      expect(App.get('isHaEnabled')).to.equal(false);
+      App.set('currentStackVersion', "HDP-1.2.2");
+    });
+
+  });
+
+
   describe('#services', function () {
     var stackServices = [
       Em.Object.create({

+ 8 - 1
ambari-web/test/controllers/main/host/details_test.js

@@ -429,6 +429,10 @@ describe('App.MainHostDetailsController', function () {
       expect(controller.constructConfigUrlParams(data)).to.eql([]);
     });
     it('isHaEnabled = true', function () {
+      App.store.load(App.Service, {
+        id: 'HDFS',
+        service_name: 'HDFS'
+      });
       var data = {Clusters: {desired_configs: {'core-site': {tag: 1}}}};
       App.HostComponent.find().clear();
       App.set('currentStackVersion', 'HDP-2.0.2');
@@ -540,7 +544,6 @@ describe('App.MainHostDetailsController', function () {
   });
 
   describe('#setZKConfigs()', function () {
-
     it('configs is null', function () {
       expect(controller.setZKConfigs(null)).to.be.false;
     });
@@ -550,6 +553,10 @@ describe('App.MainHostDetailsController', function () {
     it('isHaEnabled = true', function () {
       var configs = {'core-site': {}};
       App.HostComponent.find().clear();
+      App.store.load(App.Service, {
+        id: 'HDFS',
+        service_name: 'HDFS'
+      });
       App.set('currentStackVersion', 'HDP-2.0.2');
       expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
       expect(configs).to.eql({"core-site": {