Add javascript tests

This patch adds javascript tests to increase coverage.

Change-Id: I6b5c24004683667db5e7dc8e0a177e68ccb9914b
This commit is contained in:
Shu Muto 2018-01-16 12:41:30 +09:00
parent 7f06143158
commit 5ba2e4705b
7 changed files with 68 additions and 20 deletions

View File

@ -0,0 +1,34 @@
/**
* 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('cluster template drawer controller', function() {
var ctrl;
beforeEach(module('horizon.dashboard.container-infra.cluster-templates'));
beforeEach(inject(function($controller) {
ctrl = $controller('horizon.dashboard.container-infra.cluster-templates.DrawerController',
{});
}));
it('objLen returns number of attributes of object', inject(function() {
expect(ctrl.objLen(undefined)).toBe(0);
expect(ctrl.objLen({a: 0})).toBe(1);
}));
});
})();

View File

@ -41,5 +41,9 @@
expect(ctrl.image_uuid).toBeDefined(); expect(ctrl.image_uuid).toBeDefined();
})); }));
it('objLen returns number of attributes of object', inject(function() {
expect(ctrl.objLen(undefined)).toBe(0);
expect(ctrl.objLen({a: 0})).toBe(1);
}));
}); });
})(); })();

View File

@ -16,16 +16,16 @@
"use strict"; "use strict";
describe('cluster templates service', function() { describe('cluster templates service', function() {
var service, detailRoute; var service, detailRoute, magnum;
beforeEach(module('horizon.dashboard.container-infra.cluster-templates')); beforeEach(module('horizon.dashboard.container-infra.cluster-templates'));
beforeEach(inject(function($injector) { beforeEach(inject(function($injector) {
service = $injector.get('horizon.dashboard.container-infra.clusters.service'); service = $injector.get('horizon.dashboard.container-infra.clusters.service');
detailRoute = $injector.get('horizon.app.core.detailRoute'); detailRoute = $injector.get('horizon.app.core.detailRoute');
magnum = $injector.get('horizon.app.core.openstack-service-api.magnum');
})); }));
describe('getClustersPromise', function() { describe('getClustersPromise', function() {
it("provides a promise", inject(function($q, $injector, $timeout) { it("provides a promise", inject(function($q, $injector, $timeout) {
var magnum = $injector.get('horizon.app.core.openstack-service-api.magnum');
var deferred = $q.defer(); var deferred = $q.defer();
spyOn(magnum, 'getClusters').and.returnValue(deferred.promise); spyOn(magnum, 'getClusters').and.returnValue(deferred.promise);
var result = service.getClustersPromise({}); var result = service.getClustersPromise({});
@ -38,6 +38,20 @@
expect(magnum.getClusters).toHaveBeenCalled(); expect(magnum.getClusters).toHaveBeenCalled();
expect(result.$$state.value.data.items[0].name).toBe('cluster1'); expect(result.$$state.value.data.items[0].name).toBe('cluster1');
})); }));
it("provides a promise with updated_at", inject(function($q, $injector, $timeout) {
var deferred = $q.defer();
spyOn(magnum, 'getClusters').and.returnValue(deferred.promise);
var result = service.getClustersPromise({});
deferred.resolve({
data:{
items: [{id: 123, name: 'cluster1', updated_at: '2017-01-16'}]
}
});
$timeout.flush();
expect(magnum.getClusters).toHaveBeenCalled();
expect(result.$$state.value.data.items[0].name).toBe('cluster1');
}));
}); });
describe('urlFunction', function() { describe('urlFunction', function() {
@ -46,7 +60,5 @@
expect(result).toBe(detailRoute + "OS::Magnum::Cluster/123abc"); expect(result).toBe(detailRoute + "OS::Magnum::Cluster/123abc");
})); }));
}); });
}); });
})(); })();

View File

@ -58,7 +58,7 @@
function perform(selected) { function perform(selected) {
// rotate certificate // rotate certificate
return magnum.rotateCertificate(selected.id).success(success); return magnum.rotateCertificate(selected.id).then(success);
} }
function success(response) { function success(response) {

View File

@ -17,21 +17,20 @@
describe('horizon.dashboard.container-infra.clusters.rotate-certificate.service', function() { describe('horizon.dashboard.container-infra.clusters.rotate-certificate.service', function() {
var service, selected, magnum; var $q, service, selected, magnum, deferred;
function fakePromise() {
return { success: angular.noop };
}
beforeEach(module('horizon.app.core')); beforeEach(module('horizon.app.core'));
beforeEach(module('horizon.framework')); beforeEach(module('horizon.framework'));
beforeEach(module('horizon.dashboard.container-infra.clusters')); beforeEach(module('horizon.dashboard.container-infra.clusters'));
beforeEach(inject(function($injector) { beforeEach(inject(function($injector, _$q_) {
$q = _$q_;
service = $injector.get( service = $injector.get(
'horizon.dashboard.container-infra.clusters.rotate-certificate.service'); 'horizon.dashboard.container-infra.clusters.rotate-certificate.service');
magnum = $injector.get('horizon.app.core.openstack-service-api.magnum'); magnum = $injector.get('horizon.app.core.openstack-service-api.magnum');
spyOn(magnum, 'rotateCertificate').and.callFake(fakePromise); deferred = $q.defer();
deferred.resolve({});
spyOn(magnum, 'rotateCertificate').and.returnValue(deferred.promise);
})); }));
it('should check the policy', function() { it('should check the policy', function() {

View File

@ -51,7 +51,7 @@
function perform(selected) { function perform(selected) {
// get certificate // get certificate
return magnum.showCertificate(selected.id).success(function(response) { return magnum.showCertificate(selected.id).then(function(response) {
textDownload.downloadTextFile(response.pem, selected.name + "_ca.pem"); textDownload.downloadTextFile(response.pem, selected.name + "_ca.pem");
}); });
} }

View File

@ -19,21 +19,20 @@
describe('horizon.dashboard.container-infra.clusters.show-certificate.service', function() { describe('horizon.dashboard.container-infra.clusters.show-certificate.service', function() {
var service, selected, magnum; var $q, service, selected, magnum, deferred;
function fakePromise() {
return { success: angular.noop };
}
beforeEach(module('horizon.app.core')); beforeEach(module('horizon.app.core'));
beforeEach(module('horizon.framework')); beforeEach(module('horizon.framework'));
beforeEach(module('horizon.dashboard.container-infra.clusters')); beforeEach(module('horizon.dashboard.container-infra.clusters'));
beforeEach(inject(function($injector) { beforeEach(inject(function($injector, _$q_) {
$q = _$q_;
service = $injector.get( service = $injector.get(
'horizon.dashboard.container-infra.clusters.show-certificate.service'); 'horizon.dashboard.container-infra.clusters.show-certificate.service');
magnum = $injector.get('horizon.app.core.openstack-service-api.magnum'); magnum = $injector.get('horizon.app.core.openstack-service-api.magnum');
spyOn(magnum, 'showCertificate').and.callFake(fakePromise); deferred = $q.defer();
deferred.resolve({});
spyOn(magnum, 'showCertificate').and.returnValue(deferred.promise);
})); }));
it('should check the policy', function() { it('should check the policy', function() {