From d77152e7e41df069441ecf6724179a3e178212bb Mon Sep 17 00:00:00 2001 From: Ryosuke Mizuno Date: Tue, 1 Nov 2016 14:50:43 +0900 Subject: [PATCH] Add javascript tests for clusterSignCertificate model and service This patch adds javascript tests for the following modules. - horizon.dashboard.container-infra.clusters.sign-certificate .model - horizon.dashboard.container-infra.clusters.sign-certificate .service Change-Id: I09fd08989c9810db45cc1809a71b9d9156dec9b9 --- .../sign-certificate-model.spec.js | 46 +++++++++++ .../sign-certificate.service.spec.js | 78 +++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate-model.spec.js create mode 100644 magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.spec.js diff --git a/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate-model.spec.js b/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate-model.spec.js new file mode 100644 index 00000000..cb28ddf6 --- /dev/null +++ b/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate-model.spec.js @@ -0,0 +1,46 @@ +/** + * (c) Copyright 2016 NEC Corporation + * + * 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.dashboard.container-infra.cluster-templates.model', function() { + var certificate; + + beforeEach(module('horizon.dashboard.container-infra.clusters')); + beforeEach(inject(function($injector) { + certificate = $injector.get( + 'horizon.dashboard.container-infra.clusters.sign-certificate-model'); + })); + + it('should be init CertificateModel', function() { + var clusterId = 1; + certificate.init(clusterId); + expect(certificate.newCertificateSpec.cluster_uuid).toEqual(clusterId); + }); + + it('signCertificate', inject(function($q, $injector) { + var magnum = $injector.get('horizon.app.core.openstack-service-api.magnum'); + var deferred = $q.defer(); + spyOn(magnum, 'signCertificate').and.returnValue(deferred.promise); + + certificate.init(null); + certificate.signCertificate(); + expect(magnum.signCertificate).toHaveBeenCalled(); + })); + + }); +})(); diff --git a/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.spec.js b/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.spec.js new file mode 100644 index 00000000..1fa0f935 --- /dev/null +++ b/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.spec.js @@ -0,0 +1,78 @@ +/** + * (c) Copyright 2016 NEC Corporation + * + * 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.dashboard.container-infra.clusters.sign-certificate.service', + function() { + + var $q, service, magnum, deferred, fakeDeferred, model; + + var fakeModal = { + result: { + then: function(callback) { + callback('test'); + } + } + }; + + var fakesignCertificate = { + data:{ + pem: "" + } + }; + + beforeEach(module('horizon.app.core')); + beforeEach(module('horizon.framework')); + beforeEach(module('horizon.dashboard.container-infra.clusters')); + + beforeEach(inject(function($injector, _$rootScope_, _$q_, $modal) { + $q = _$q_; + service = $injector.get( + 'horizon.dashboard.container-infra.clusters.sign-certificate.service'); + magnum = $injector.get('horizon.app.core.openstack-service-api.magnum'); + deferred = $q.defer(); + deferred.resolve({data: {uuid: 1}}); + spyOn(magnum, 'downloadTextAsFile').and.returnValue(deferred.promise); + + model = $injector.get('horizon.dashboard.container-infra.clusters.sign-certificate-model'); + fakeDeferred = $q.defer(); + fakeDeferred.resolve(fakesignCertificate); + spyOn(model, 'signCertificate').and.returnValue(fakeDeferred.promise); + + spyOn($modal, 'open').and.returnValue(fakeModal); + })); + + it('should pass allow()', function() { + var allowed = service.allowed(); + expect(allowed).toBeTruthy(); + }); + + it('should pass submit() and success()', inject(function($timeout) { + + var selected = {id : 1}; + service.initScope(); + service.perform(selected); + $timeout.flush(); + + expect(model.signCertificate).toHaveBeenCalled(); + expect(magnum.downloadTextAsFile).toHaveBeenCalled(); + + })); + + }); +})();