diff --git a/openstack_dashboard/karma.conf.js b/openstack_dashboard/karma.conf.js index d18b0bfd7b..3c9e6ba4bd 100644 --- a/openstack_dashboard/karma.conf.js +++ b/openstack_dashboard/karma.conf.js @@ -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 } }); }; diff --git a/openstack_dashboard/static/app/tech-debt/hz-namespace-resource-type-form.controller.spec.js b/openstack_dashboard/static/app/tech-debt/hz-namespace-resource-type-form.controller.spec.js new file mode 100644 index 0000000000..589f4e5316 --- /dev/null +++ b/openstack_dashboard/static/app/tech-debt/hz-namespace-resource-type-form.controller.spec.js @@ -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]'); + }); + + }); +})(); diff --git a/openstack_dashboard/static/app/tech-debt/image-form.controller.js b/openstack_dashboard/static/app/tech-debt/image-form.controller.js index 99250b6082..ea6594f716 100644 --- a/openstack_dashboard/static/app/tech-debt/image-form.controller.js +++ b/openstack_dashboard/static/app/tech-debt/image-form.controller.js @@ -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 */ diff --git a/openstack_dashboard/static/app/tech-debt/image-form.controller.spec.js b/openstack_dashboard/static/app/tech-debt/image-form.controller.spec.js new file mode 100644 index 0000000000..f54af5b346 --- /dev/null +++ b/openstack_dashboard/static/app/tech-debt/image-form.controller.spec.js @@ -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 = '
'; + + 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(''); + + var ctrl = createController(); + expect(ctrl.copyFrom).toEqual('ImageUrl'); + $document.find('.image_url').remove(); + }); + + it('should set diskFormat', function() { + $document.find('body').append(''); + + 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(); + }); + + }); +})(); diff --git a/openstack_dashboard/static/app/tech-debt/tech-debt.module.spec.js b/openstack_dashboard/static/app/tech-debt/tech-debt.module.spec.js new file mode 100644 index 0000000000..742ab1c293 --- /dev/null +++ b/openstack_dashboard/static/app/tech-debt/tech-debt.module.spec.js @@ -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(); + }); + }); + +})();