Add javascript tests
This patch adds javascript tests to increase coverage. Change-Id: I6b5c24004683667db5e7dc8e0a177e68ccb9914b
This commit is contained in:
parent
7f06143158
commit
5ba2e4705b
@ -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);
|
||||
}));
|
||||
});
|
||||
})();
|
@ -41,5 +41,9 @@
|
||||
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);
|
||||
}));
|
||||
});
|
||||
})();
|
||||
|
@ -16,16 +16,16 @@
|
||||
"use strict";
|
||||
|
||||
describe('cluster templates service', function() {
|
||||
var service, detailRoute;
|
||||
var service, detailRoute, magnum;
|
||||
beforeEach(module('horizon.dashboard.container-infra.cluster-templates'));
|
||||
beforeEach(inject(function($injector) {
|
||||
service = $injector.get('horizon.dashboard.container-infra.clusters.service');
|
||||
detailRoute = $injector.get('horizon.app.core.detailRoute');
|
||||
magnum = $injector.get('horizon.app.core.openstack-service-api.magnum');
|
||||
}));
|
||||
|
||||
describe('getClustersPromise', function() {
|
||||
it("provides a promise", inject(function($q, $injector, $timeout) {
|
||||
var magnum = $injector.get('horizon.app.core.openstack-service-api.magnum');
|
||||
var deferred = $q.defer();
|
||||
spyOn(magnum, 'getClusters').and.returnValue(deferred.promise);
|
||||
var result = service.getClustersPromise({});
|
||||
@ -38,6 +38,20 @@
|
||||
expect(magnum.getClusters).toHaveBeenCalled();
|
||||
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() {
|
||||
@ -46,7 +60,5 @@
|
||||
expect(result).toBe(detailRoute + "OS::Magnum::Cluster/123abc");
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
})();
|
||||
|
@ -58,7 +58,7 @@
|
||||
|
||||
function perform(selected) {
|
||||
// rotate certificate
|
||||
return magnum.rotateCertificate(selected.id).success(success);
|
||||
return magnum.rotateCertificate(selected.id).then(success);
|
||||
}
|
||||
|
||||
function success(response) {
|
||||
|
@ -17,21 +17,20 @@
|
||||
|
||||
describe('horizon.dashboard.container-infra.clusters.rotate-certificate.service', function() {
|
||||
|
||||
var service, selected, magnum;
|
||||
|
||||
function fakePromise() {
|
||||
return { success: angular.noop };
|
||||
}
|
||||
var $q, service, selected, magnum, deferred;
|
||||
|
||||
beforeEach(module('horizon.app.core'));
|
||||
beforeEach(module('horizon.framework'));
|
||||
beforeEach(module('horizon.dashboard.container-infra.clusters'));
|
||||
|
||||
beforeEach(inject(function($injector) {
|
||||
beforeEach(inject(function($injector, _$q_) {
|
||||
$q = _$q_;
|
||||
service = $injector.get(
|
||||
'horizon.dashboard.container-infra.clusters.rotate-certificate.service');
|
||||
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() {
|
||||
|
@ -51,7 +51,7 @@
|
||||
|
||||
function perform(selected) {
|
||||
// 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");
|
||||
});
|
||||
}
|
||||
|
@ -19,21 +19,20 @@
|
||||
|
||||
describe('horizon.dashboard.container-infra.clusters.show-certificate.service', function() {
|
||||
|
||||
var service, selected, magnum;
|
||||
|
||||
function fakePromise() {
|
||||
return { success: angular.noop };
|
||||
}
|
||||
var $q, service, selected, magnum, deferred;
|
||||
|
||||
beforeEach(module('horizon.app.core'));
|
||||
beforeEach(module('horizon.framework'));
|
||||
beforeEach(module('horizon.dashboard.container-infra.clusters'));
|
||||
|
||||
beforeEach(inject(function($injector) {
|
||||
beforeEach(inject(function($injector, _$q_) {
|
||||
$q = _$q_;
|
||||
service = $injector.get(
|
||||
'horizon.dashboard.container-infra.clusters.show-certificate.service');
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user