Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
AMBARI-25135. Cover service mixin with unit tests
  • Loading branch information
aleksandrkovalenko committed Feb 5, 2019
1 parent dfdb8bf commit 9256fa11b2829f5f3cf2be8d0da9ed45d77505bd
Showing 3 changed files with 175 additions and 0 deletions.
@@ -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',
@@ -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;
});
});
});
@@ -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;
});
});
});

0 comments on commit 9256fa1

Please sign in to comment.