You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ak...@apache.org on 2019/02/05 17:19:21 UTC

[ambari] branch trunk updated: AMBARI-25135. Cover service mixin with unit tests

This is an automated email from the ASF dual-hosted git repository.

akovalenko pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 9256fa1  AMBARI-25135. Cover service mixin with unit tests
9256fa1 is described below

commit 9256fa11b2829f5f3cf2be8d0da9ed45d77505bd
Author: Aleksandr Kovalenko <ak...@apache.org>
AuthorDate: Tue Jan 29 19:45:26 2019 +0200

    AMBARI-25135. Cover service mixin with unit tests
---
 ambari-web/app/assets/test/tests.js                |   2 +
 .../mixins/main/service/groups_mapping_test.js     |  71 ++++++++++++++
 .../mixins/main/service/themes_mapping_test.js     | 102 +++++++++++++++++++++
 3 files changed, 175 insertions(+)

diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index 3d039f8..5e0b52c 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -215,6 +215,8 @@ var files = [
   'test/mixins/main/service/configs/widget_popover_support_test',
   'test/mixins/main/service/configs/config_overridable_test',
   'test/mixins/main/service/configs/component_actions_by_configs_test',
+  'test/mixins/main/service/groups_mapping_test',
+  'test/mixins/main/service/themes_mapping_test',
   'test/mixins/routers/redirections_test',
   'test/mixins/wizard/addSeccurityConfigs_test',
   'test/mixins/wizard/assign_master_components_test',
diff --git a/ambari-web/test/mixins/main/service/groups_mapping_test.js b/ambari-web/test/mixins/main/service/groups_mapping_test.js
new file mode 100644
index 0000000..d4d5ce7
--- /dev/null
+++ b/ambari-web/test/mixins/main/service/groups_mapping_test.js
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+var testHelpers = require('test/helpers');
+
+describe('App.GroupsMappingMixin', function () {
+  var mixin;
+
+  beforeEach(function () {
+    mixin = Em.Object.create(App.GroupsMappingMixin, {});
+  });
+  
+  describe('#loadConfigGroups', function() {
+    beforeEach(function() {
+      sinon.stub(mixin, 'trackRequest');
+    });
+    afterEach(function() {
+      mixin.trackRequest.restore();
+    });
+    
+    it('configGroupsAreLoaded should be true', function() {
+      mixin.loadConfigGroups([]);
+      expect(mixin.get('configGroupsAreLoaded')).to.be.true;
+    });
+  
+    it('App.ajax.send should be called', function() {
+      mixin.loadConfigGroups(['S1', 'S2']);
+      expect(testHelpers.findAjaxRequest('name', 'configs.config_groups.load.services')[0]).to.exists;
+    });
+  });
+  
+  describe('#saveConfigGroupsToModel', function() {
+    var dfd = {resolve: sinon.spy()};
+    
+    beforeEach(function() {
+      sinon.stub(App.configGroupsMapper, 'map');
+      mixin.saveConfigGroupsToModel({}, {}, {serviceNames: 'S1,S2', dfd: dfd});
+    });
+    afterEach(function() {
+      App.configGroupsMapper.map.restore();
+    });
+    
+    it('App.configGroupsMapper.map should be called', function() {
+      expect(App.configGroupsMapper.map.calledWith({}, false, ['S1', 'S2'])).to.be.true;
+    });
+  
+    it('configGroupsAreLoaded should be true', function() {
+      expect(mixin.get('configGroupsAreLoaded')).to.be.true;
+    });
+  
+    it('resolve should be called', function() {
+      expect(dfd.resolve.called).to.be.true;
+    });
+  });
+});
diff --git a/ambari-web/test/mixins/main/service/themes_mapping_test.js b/ambari-web/test/mixins/main/service/themes_mapping_test.js
new file mode 100644
index 0000000..f547229
--- /dev/null
+++ b/ambari-web/test/mixins/main/service/themes_mapping_test.js
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+var testHelpers = require('test/helpers');
+
+describe('App.ThemesMappingMixin', function () {
+  var mixin;
+
+  beforeEach(function () {
+    mixin = Em.Object.create(App.ThemesMappingMixin, {});
+  });
+  
+  describe('#loadConfigTheme', function() {
+    beforeEach(function() {
+      sinon.stub(App.Tab, 'find').returns([{
+        serviceName: 'S2'
+      }]);
+      sinon.stub(App, 'get').returns('stack1');
+    });
+    afterEach(function() {
+      App.Tab.find.restore();
+      App.get.restore();
+    });
+    
+    it('App.ajax.send should be called', function() {
+      mixin.loadConfigTheme('S1');
+      expect(testHelpers.findAjaxRequest('name', 'configs.theme')[0].data).to.be.eql({
+        serviceName: 'S1',
+        stackVersionUrl: 'stack1'
+      });
+    });
+  });
+  
+  describe('#_saveThemeToModel', function() {
+    beforeEach(function() {
+      sinon.stub(App.themesMapper, 'map');
+    });
+    afterEach(function() {
+      App.themesMapper.map.restore();
+    });
+    
+    it('App.themesMapper.map should be called', function() {
+      mixin._saveThemeToModel({}, {}, {serviceName: 'S1'});
+      expect(App.themesMapper.map.calledWith({}, ['S1'])).to.be.true;
+    });
+  });
+  
+  describe('#loadConfigThemeForServices', function() {
+    beforeEach(function() {
+      sinon.stub(App, 'get').returns('stack1');
+    });
+    afterEach(function() {
+      App.get.restore();
+    });
+    
+    it('App.ajax.send should be called', function() {
+      mixin.loadConfigThemeForServices(['S1', 'S2']);
+      expect(testHelpers.findAjaxRequest('name', 'configs.theme.services')[0].data).to.be.eql({
+        serviceNames: 'S1,S2',
+        stackVersionUrl: 'stack1'
+      });
+    });
+  });
+  
+  describe('#_loadConfigThemeForServicesSuccess', function() {
+    beforeEach(function() {
+      sinon.stub(App.themesMapper, 'map');
+    });
+    afterEach(function() {
+      App.themesMapper.map.restore();
+    });
+    
+    it('App.themesMapper.map should be called', function() {
+      mixin._loadConfigThemeForServicesSuccess(
+        {items: [{themes: [[]]}]},
+        {},
+        {serviceNames: 'S1,S2'});
+      expect(App.themesMapper.map.calledWith(
+        {
+          items: [[]]
+        },
+        ['S1', 'S2']
+      )).to.be.true;
+    });
+  });
+});