diff --git a/magnum_ui/static/dashboard/container-infra/cluster-templates/details/drawer.controller.spec.js b/magnum_ui/static/dashboard/container-infra/cluster-templates/details/drawer.controller.spec.js new file mode 100644 index 00000000..bdbd8ae0 --- /dev/null +++ b/magnum_ui/static/dashboard/container-infra/cluster-templates/details/drawer.controller.spec.js @@ -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); + })); + }); +})(); diff --git a/magnum_ui/static/dashboard/container-infra/cluster-templates/details/overview.controller.spec.js b/magnum_ui/static/dashboard/container-infra/cluster-templates/details/overview.controller.spec.js index 8f8639f9..5fc98e9e 100644 --- a/magnum_ui/static/dashboard/container-infra/cluster-templates/details/overview.controller.spec.js +++ b/magnum_ui/static/dashboard/container-infra/cluster-templates/details/overview.controller.spec.js @@ -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); + })); }); })(); diff --git a/magnum_ui/static/dashboard/container-infra/clusters/clusters.service.spec.js b/magnum_ui/static/dashboard/container-infra/clusters/clusters.service.spec.js index e2993218..fe27e8d5 100644 --- a/magnum_ui/static/dashboard/container-infra/clusters/clusters.service.spec.js +++ b/magnum_ui/static/dashboard/container-infra/clusters/clusters.service.spec.js @@ -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"); })); }); - }); - })(); diff --git a/magnum_ui/static/dashboard/container-infra/clusters/rotate-certificate/rotate-certificate.service.js b/magnum_ui/static/dashboard/container-infra/clusters/rotate-certificate/rotate-certificate.service.js index 60ef61e7..f0339864 100644 --- a/magnum_ui/static/dashboard/container-infra/clusters/rotate-certificate/rotate-certificate.service.js +++ b/magnum_ui/static/dashboard/container-infra/clusters/rotate-certificate/rotate-certificate.service.js @@ -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) { diff --git a/magnum_ui/static/dashboard/container-infra/clusters/rotate-certificate/rotate-certificate.service.spec.js b/magnum_ui/static/dashboard/container-infra/clusters/rotate-certificate/rotate-certificate.service.spec.js index 840f287f..71f4a92f 100644 --- a/magnum_ui/static/dashboard/container-infra/clusters/rotate-certificate/rotate-certificate.service.spec.js +++ b/magnum_ui/static/dashboard/container-infra/clusters/rotate-certificate/rotate-certificate.service.spec.js @@ -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() { diff --git a/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js b/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js index 1b890eaf..aef3e8d9 100644 --- a/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js +++ b/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js @@ -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"); }); } diff --git a/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.spec.js b/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.spec.js index 23628a36..f76a359b 100644 --- a/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.spec.js +++ b/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.spec.js @@ -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() {