From 6dc4bd203d3e44ce6500a4b81a27158d6c73185c Mon Sep 17 00:00:00 2001 From: pengyuesheng Date: Wed, 27 Mar 2019 14:28:22 +0800 Subject: [PATCH] After deleting the server group, jump to the correct page On the server group Details page, after deleting the server group, jump to a wrong page. This patch jump to the correct page after deleting the server group. Change-Id: If47aa64a8539bcc3996aa484db1e847a3059c2aa Closes-Bug: #1821851 --- .../actions/delete.action.service.js | 10 ++++++++- .../actions/delete.action.service.spec.js | 22 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.js b/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.js index 0f3d4ce957..51b8b22858 100644 --- a/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.js +++ b/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.js @@ -20,6 +20,7 @@ .factory('horizon.app.core.server_groups.actions.delete.service', deleteServerGroupService); deleteServerGroupService.$inject = [ + '$location', 'horizon.app.core.openstack-service-api.nova', 'horizon.app.core.openstack-service-api.policy', 'horizon.app.core.server_groups.resourceType', @@ -39,6 +40,7 @@ * On cancel, do nothing. */ function deleteServerGroupService( + $location, nova, policy, serverGroupResourceType, @@ -77,7 +79,13 @@ deleteModalResult.fail.forEach(function markFailed(item) { actionResult.failed(serverGroupResourceType, item.context.id); }); - return actionResult.result; + var path = '/project/server_groups'; + if ($location.url() !== path && actionResult.result.failed.length === 0 && + actionResult.result.deleted.length > 0) { + $location.path(path); + } else { + return actionResult.result; + } } function labelize(count) { diff --git a/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.spec.js b/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.spec.js index 84e61f8be8..5fdc213a49 100644 --- a/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.spec.js +++ b/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.spec.js @@ -17,7 +17,7 @@ describe('horizon.app.core.server_groups.actions.delete.service', function() { - var $scope, deferredModal, novaAPI, service; + var $scope, deferredModal, novaAPI, service, $location; var deleteModalService = { open: function () { deferredModal.resolve({ @@ -39,6 +39,7 @@ beforeEach(inject(function($injector, _$rootScope_, $q) { $scope = _$rootScope_.$new(); deferredModal = $q.defer(); + $location = $injector.get("$location"); novaAPI = $injector.get('horizon.app.core.openstack-service-api.nova'); service = $injector.get('horizon.app.core.server_groups.actions.delete.service'); })); @@ -57,6 +58,8 @@ it('should only delete server groups that are valid', testValids); it('should pass in a function that deletes a server group', testNova); it('should check the policy if the user is allowed to delete server group', testAllowed); + it('Should jump to the project server_groups page when deleting the server_groups', + testDeleteResult); //////////// @@ -128,6 +131,23 @@ var allowed = service.allowed(); expect(allowed).toBeTruthy(); } + + function testDeleteResult() { + $location.path("ngdetails/OS::Nova::ServerGroup/1"); + var servergroup = {id: 1, name: 'sg1'}; + deferredModal.resolve({fail: [], pass:[{data:{"data": "", "status": "204"}, + context:servergroup}]}); + spyOn(novaAPI, 'deleteServerGroup').and.returnValue(deferredModal.promise); + service.perform(servergroup); + $scope.$apply(); + + var contextArg = deleteModalService.open.calls.argsFor(0)[2]; + var deleteFunction = contextArg.deleteEntity; + deleteFunction(servergroup.id); + expect(novaAPI.deleteServerGroup).toHaveBeenCalledWith(servergroup.id, true); + expect($location.path()).toEqual("/project/server_groups"); + } + }); // end of delete modal }); // end of delete server group