summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-12-02 22:56:38 +0000
committerGerrit Code Review <review@openstack.org>2015-12-02 22:56:38 +0000
commitb51f0eef3ab74f7dff5f19a622c1254d1ea68e7c (patch)
treeb5d0765f8d90cab3ac9ba9d46216c5a051ad1ca6
parent07ac5e2e505cdc5a8046e6319f859347eeb1cf5a (diff)
parent222bd716fa8e511d8d8d61067625eacb0cca70c8 (diff)
Merge "Launch Instance Modal should be exist as a Service"
-rw-r--r--openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.controller.js33
-rw-r--r--openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.controller.spec.js70
-rw-r--r--openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.service.js66
-rw-r--r--openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.service.spec.js103
4 files changed, 192 insertions, 80 deletions
diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.controller.js b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.controller.js
index 801a5af..bc2edf9 100644
--- a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.controller.js
+++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.controller.js
@@ -21,36 +21,17 @@
21 .controller('LaunchInstanceModalController', LaunchInstanceModalController); 21 .controller('LaunchInstanceModalController', LaunchInstanceModalController);
22 22
23 LaunchInstanceModalController.$inject = [ 23 LaunchInstanceModalController.$inject = [
24 '$modal', 24 'horizon.dashboard.project.workflow.launch-instance.modal.service'
25 '$window',
26 'horizon.dashboard.project.workflow.launch-instance.modal-spec'
27 ]; 25 ];
28 26
29 function LaunchInstanceModalController($modal, $window, modalSpec) { 27 function LaunchInstanceModalController(modalService) {
30 var ctrl = this; 28 var ctrl = this;
31 29
32 ctrl.openLaunchInstanceWizard = function (launchContext) { 30 ctrl.openLaunchInstanceWizard = openLaunchInstanceWizard;
33 var localSpec = { 31
34 resolve: { 32 function openLaunchInstanceWizard(launchContext) {
35 launchContext: function () { 33 modalService.open(launchContext);
36 return launchContext; 34 }
37 }
38 }
39 };
40 angular.extend(localSpec, modalSpec);
41 var launchInstanceModal = $modal.open(localSpec);
42 var handleModalClose = function (redirectPropertyName) {
43 return function () {
44 if (launchContext && launchContext[redirectPropertyName]) {
45 $window.location.href = launchContext[redirectPropertyName];
46 }
47 };
48 };
49 launchInstanceModal.result.then(
50 handleModalClose('successUrl'),
51 handleModalClose('dismissUrl')
52 );
53 };
54 } 35 }
55 36
56})(); 37})();
diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.controller.spec.js b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.controller.spec.js
index 5d7fa2b..3cdd94f 100644
--- a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.controller.spec.js
+++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.controller.spec.js
@@ -17,23 +17,19 @@
17 'use strict'; 17 'use strict';
18 18
19 describe('LaunchInstanceModalController tests', function() { 19 describe('LaunchInstanceModalController tests', function() {
20 var ctrl, modal, $window; 20 var ctrl, modalService;
21 21
22 beforeEach(module('horizon.dashboard.project')); 22 beforeEach(module('horizon.dashboard.project'));
23
23 beforeEach(module(function($provide) { 24 beforeEach(module(function($provide) {
24 modal = { 25 modalService = {
25 open: function() { 26 open: function() { }
26 return {
27 result: {
28 then: angular.noop
29 }
30 };
31 }
32 }; 27 };
33 $window = { location: { href: '/' } }; 28
34 $provide.value('$modal', modal); 29 $provide.value(
35 $provide.value('$modalSpec', {}); 30 'horizon.dashboard.project.workflow.launch-instance.modal.service',
36 $provide.value('$window', $window); 31 modalService
32 );
37 })); 33 }));
38 34
39 beforeEach(inject(function($controller) { 35 beforeEach(inject(function($controller) {
@@ -56,55 +52,21 @@
56 launchContext = {}; 52 launchContext = {};
57 }); 53 });
58 54
59 it('calls modal.open', function() { 55 it('calls modal.service.open', function() {
60 spyOn(modal, 'open').and.returnValue({ result: { then: angular.noop } }); 56 spyOn(modalService, 'open').and.callThrough();
61 func(launchContext); 57 func(launchContext);
62 expect(modal.open).toHaveBeenCalled(); 58 expect(modalService.open).toHaveBeenCalled();
63 }); 59 });
64 60
65 it('calls modal.open with expected values', function() { 61 it('calls modalService.open with expected values', function() {
66 spyOn(modal, 'open').and.returnValue({ result: { then: angular.noop } }); 62 spyOn(modalService, 'open').and.callThrough();
67 launchContext = { info: 'information' }; 63 launchContext = { info: 'information' };
68 func(launchContext); 64 func(launchContext);
69 65
70 var resolve = modal.open.calls.argsFor(0)[0].resolve; 66 var args = modalService.open.calls.argsFor(0)[0];
71 expect(resolve).toBeDefined(); 67 expect(args).toEqual(launchContext);
72 expect(resolve.launchContext).toBeDefined();
73 expect(resolve.launchContext()).toEqual({ info: 'information' });
74 }); 68 });
75 69
76 it('sets up the correct success and failure paths', function() {
77 var successFunc, errFunc;
78
79 launchContext = { successUrl: '/good/path', dismissUrl: '/bad/path' };
80 spyOn(modal, 'open').and
81 .returnValue({
82 result: {
83 then: function(x, y) { successFunc = x; errFunc = y; }
84 }
85 });
86 func(launchContext);
87 successFunc('successUrl');
88 expect($window.location.href).toBe('/good/path');
89 errFunc('dismissUrl');
90 expect($window.location.href).toBe('/bad/path');
91 });
92
93 it("doesn't redirect if not configured to", function() {
94 var successFunc, errFunc;
95 launchContext = {};
96 spyOn(modal, 'open').and
97 .returnValue({
98 result: {
99 then: function(x, y) { successFunc = x; errFunc = y; }
100 }
101 });
102 func(launchContext);
103 successFunc('successUrl');
104 expect($window.location.href).toBe('/');
105 errFunc('dismissUrl');
106 expect($window.location.href).toBe('/');
107 });
108 }); 70 });
109 }); 71 });
110 72
diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.service.js b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.service.js
new file mode 100644
index 0000000..8bc4979
--- /dev/null
+++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.service.js
@@ -0,0 +1,66 @@
1/*
2 * (c) Copyright 2015 Hewlett-Packard Development Company, L.P.
3 *
4 * Licensed under the Apache License, Version 2.0 (the 'License');
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16(function () {
17 'use strict';
18
19 angular
20 .module('horizon.dashboard.project.workflow.launch-instance')
21 .factory(
22 'horizon.dashboard.project.workflow.launch-instance.modal.service',
23 LaunchInstanceModalService
24 );
25
26 LaunchInstanceModalService.$inject = [
27 '$modal',
28 '$window',
29 'horizon.dashboard.project.workflow.launch-instance.modal-spec'
30 ];
31
32 function LaunchInstanceModalService($modal, $window, modalSpec) {
33 var service = {
34 open: open
35 };
36
37 return service;
38
39 function open(launchContext) {
40 var localSpec = {
41 resolve: {
42 launchContext: function () {
43 return launchContext;
44 }
45 }
46 };
47
48 angular.extend(localSpec, modalSpec);
49
50 var launchInstanceModal = $modal.open(localSpec);
51 var handleModalClose = function (redirectPropertyName) {
52 return function () {
53 if (launchContext && launchContext[redirectPropertyName]) {
54 $window.location.href = launchContext[redirectPropertyName];
55 }
56 };
57 };
58
59 launchInstanceModal.result.then(
60 handleModalClose('successUrl'),
61 handleModalClose('dismissUrl')
62 );
63 }
64 }
65
66})();
diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.service.spec.js b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.service.spec.js
new file mode 100644
index 0000000..2cdb639
--- /dev/null
+++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/launch-instance-modal.service.spec.js
@@ -0,0 +1,103 @@
1/*
2 * (c) Copyright 2015 Hewlett-Packard Development Company, L.P.
3 *
4 * Licensed under the Apache License, Version 2.0 (the 'License');
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16(function () {
17 'use strict';
18
19 describe('LaunchInstanceModalController tests', function() {
20 var service, modal, $window;
21
22 beforeEach(module('horizon.dashboard.project'));
23 beforeEach(module(function($provide) {
24 modal = {
25 open: function() {
26 return {
27 result: {
28 then: angular.noop
29 }
30 };
31 }
32 };
33 $window = { location: { href: '/' } };
34 $provide.value('$modal', modal);
35 $provide.value('$modalSpec', {});
36 $provide.value('$window', $window);
37 }));
38
39 beforeEach(inject(function($injector) {
40 service = $injector.get('horizon.dashboard.project.workflow.launch-instance.modal.service');
41 }));
42
43 describe('open function tests', function() {
44 var func, launchContext;
45
46 beforeEach(function() {
47 func = service.open;
48 launchContext = {};
49 });
50
51 it('calls modal.open', function() {
52 spyOn(modal, 'open').and.returnValue({ result: { then: angular.noop } });
53 func(launchContext);
54 expect(modal.open).toHaveBeenCalled();
55 });
56
57 it('calls modal.open with expected values', function() {
58 spyOn(modal, 'open').and.returnValue({ result: { then: angular.noop } });
59 launchContext = { info: 'information' };
60 func(launchContext);
61
62 var resolve = modal.open.calls.argsFor(0)[0].resolve;
63 expect(resolve).toBeDefined();
64 expect(resolve.launchContext).toBeDefined();
65 expect(resolve.launchContext()).toEqual({ info: 'information' });
66 });
67
68 it('sets up the correct success and failure paths', function() {
69 var successFunc, errFunc;
70
71 launchContext = { successUrl: '/good/path', dismissUrl: '/bad/path' };
72 spyOn(modal, 'open').and
73 .returnValue({
74 result: {
75 then: function(x, y) { successFunc = x; errFunc = y; }
76 }
77 });
78 func(launchContext);
79 successFunc('successUrl');
80 expect($window.location.href).toBe('/good/path');
81 errFunc('dismissUrl');
82 expect($window.location.href).toBe('/bad/path');
83 });
84
85 it("doesn't redirect if not configured to", function() {
86 var successFunc, errFunc;
87 launchContext = {};
88 spyOn(modal, 'open').and
89 .returnValue({
90 result: {
91 then: function(x, y) { successFunc = x; errFunc = y; }
92 }
93 });
94 func(launchContext);
95 successFunc('successUrl');
96 expect($window.location.href).toBe('/');
97 errFunc('dismissUrl');
98 expect($window.location.href).toBe('/');
99 });
100 });
101 });
102
103})();