Add tests for controllers in tech-debt
Controllers image-form and hz-namespace-resource-type-form do not have any tests. This patch simply adds unit tests. Change-Id: I537b7bdf6b778c333f84491891afeb8dbc45eb53 Closes-Bug: #1501513
This commit is contained in:
parent
a23a7e0b6c
commit
8a9329c5fe
@ -161,10 +161,10 @@ module.exports = function (config) {
|
||||
|
||||
// Coverage threshold values.
|
||||
thresholdReporter: {
|
||||
statements: 89, // target 100
|
||||
branches: 82, // target 100
|
||||
functions: 88, // target 100
|
||||
lines: 89 // target 100
|
||||
statements: 90, // target 100
|
||||
branches: 84, // target 100
|
||||
functions: 89, // target 100
|
||||
lines: 90 // target 100
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -0,0 +1,50 @@
|
||||
/**
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
describe('horizon.app.tech-debt.hzNamespaceResourceTypeFormController', function() {
|
||||
|
||||
var $window, controller;
|
||||
|
||||
beforeEach(module('horizon.app.tech-debt'));
|
||||
beforeEach(inject(function($injector) {
|
||||
controller = $injector.get('$controller');
|
||||
$window = $injector.get('$window');
|
||||
}));
|
||||
|
||||
function createController() {
|
||||
return controller('hzNamespaceResourceTypeFormController', {});
|
||||
}
|
||||
|
||||
it('should set resource_types', function() {
|
||||
$window.resource_types = [1];
|
||||
|
||||
var ctrl = createController();
|
||||
expect(ctrl.resource_types).toEqual([1]);
|
||||
});
|
||||
|
||||
it('should save resource_types', function() {
|
||||
$window.resource_types = [1];
|
||||
|
||||
var ctrl = createController();
|
||||
ctrl.saveResourceTypes();
|
||||
|
||||
expect(ctrl.resource_types).toEqual('[1]');
|
||||
});
|
||||
|
||||
});
|
||||
})();
|
@ -20,12 +20,13 @@
|
||||
|
||||
function ImageFormController() {
|
||||
var ctrl = this;
|
||||
|
||||
ctrl.copyFrom = angular.element('.image_url').val();
|
||||
ctrl.diskFormat = angular.element('.disk_format').val();
|
||||
ctrl.selectImageFormat = function (path) {
|
||||
if (!path) { return; }
|
||||
var format = path.substr(path.lastIndexOf(".") + 1)
|
||||
.toLowerCase().replace(/[^a-z0-9]+/gi, "");
|
||||
var format = path.substr(path.lastIndexOf(".") + 1).toLowerCase().replace(/[^a-z0-9]+/gi, "");
|
||||
|
||||
/* eslint-disable angular/ng_angularelement */
|
||||
if ($('#id_disk_format').find('[value=' + format + ']').length !== 0) {
|
||||
/* eslint-enable angular/ng_angularelement */
|
||||
|
@ -0,0 +1,84 @@
|
||||
/**
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
describe('horizon.app.tech-debt.ImageFormController', function() {
|
||||
|
||||
var $document, controller;
|
||||
var gzHtml = '<div id="id_disk_format"><input class="disk_format" value="gz"></input></div>';
|
||||
|
||||
beforeEach(module('horizon.app.tech-debt'));
|
||||
beforeEach(inject(function($injector) {
|
||||
controller = $injector.get('$controller');
|
||||
$document = $injector.get('$document');
|
||||
}));
|
||||
|
||||
function createController() {
|
||||
return controller('ImageFormController', {});
|
||||
}
|
||||
|
||||
it('should set copyFrom', function() {
|
||||
$document.find('body').append('<input class="image_url" value="ImageUrl"></input>');
|
||||
|
||||
var ctrl = createController();
|
||||
expect(ctrl.copyFrom).toEqual('ImageUrl');
|
||||
$document.find('.image_url').remove();
|
||||
});
|
||||
|
||||
it('should set diskFormat', function() {
|
||||
$document.find('body').append('<input class="disk_format" value="DiskFormat"></input>');
|
||||
|
||||
var ctrl = createController();
|
||||
expect(ctrl.diskFormat).toEqual('DiskFormat');
|
||||
$document.find('.disk_format').remove();
|
||||
});
|
||||
|
||||
it('should set image format to detected format', function() {
|
||||
$document.find('body').append(gzHtml);
|
||||
|
||||
var ctrl = createController();
|
||||
|
||||
ctrl.selectImageFormat("image.tar.gz");
|
||||
|
||||
expect(ctrl.diskFormat).toEqual('gz');
|
||||
$document.find('#id_disk_format').remove();
|
||||
});
|
||||
|
||||
it('should set disk format to blank if selection does not match', function() {
|
||||
$document.find('body').append(gzHtml);
|
||||
|
||||
var ctrl = createController();
|
||||
|
||||
ctrl.selectImageFormat("image.tar.bz2");
|
||||
|
||||
expect(ctrl.diskFormat).toEqual('');
|
||||
$document.find('#id_disk_format').remove();
|
||||
});
|
||||
|
||||
it('should not set disk format to blank if path is empty', function() {
|
||||
$document.find('body').append(gzHtml);
|
||||
|
||||
var ctrl = createController();
|
||||
|
||||
ctrl.selectImageFormat();
|
||||
|
||||
expect(ctrl.diskFormat).toEqual('gz');
|
||||
$document.find('#id_disk_format').remove();
|
||||
});
|
||||
|
||||
});
|
||||
})();
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
describe('horizon.app.tech-debt', function () {
|
||||
it('should have been defined', function () {
|
||||
expect(angular.module('horizon.app.tech-debt')).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
})();
|
Loading…
Reference in New Issue
Block a user