From 487c59abe139a7abda7578d60733671075ddd61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Z=C3=A1zrivec?= Date: Thu, 11 Jan 2018 11:00:45 +0100 Subject: [PATCH] Merge pull request #3219 from himdel/topology-parseurl topologyService (js) - fix and test screen url to data url conversion (cherry picked from commit e2c0f815a0b5c7d5bc3f999652221aa89b340844) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1533519 --- .../javascripts/services/topology_service.js | 35 +++-- .../services/topology_service_spec.js | 126 ++++++++++++++++++ 2 files changed, 150 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/services/topology_service.js b/app/assets/javascripts/services/topology_service.js index d34aa92c019..2639a5948e6 100644 --- a/app/assets/javascripts/services/topology_service.js +++ b/app/assets/javascripts/services/topology_service.js @@ -273,24 +273,37 @@ ManageIQ.angular.app.service('topologyService', ['$location', '$http', 'miqServi controller.kinds = $scope.kinds = topologyService.reduce_kinds(controller.items, controller.kinds, size_limit, controller.remove_hierarchy); } }; - var refresh = function() { - var id; - var url = ''; - if ($location.absUrl().match('show/$') || $location.absUrl().match('show$')) { - url = controller.dataUrl; - } else if ($location.absUrl().match('show/[0-9]*\\?display=topology/?$') || $location.absUrl().match('_topology/show/[0-9]+/?$')) { - id = '/' + (/\/show\/(\d+)/.exec($location.absUrl())[1]); - url = controller.detailUrl || controller.dataUrl; - url += id; + + controller.parseUrl = function(screenUrl) { + if (screenUrl.match('show/?$')) { + return controller.dataUrl; + } + + var match = screenUrl.match(/(ems_container|show)\/([0-9]+)\?display=topology$/) || + screenUrl.match(/(_topology)\/show\/([0-9]+)\/?$/); + + if (match) { + var id = match[2]; + var url = controller.detailUrl || controller.dataUrl; + + // ems_container is restful? and thus special :( + // FIXME: get rid of detailUrl, use a separate container project controller instead + if (match[1] === 'ems_container') { + url = controller.dataUrl; + } + + return url + (id && '/' + id); } + }; + + controller.refresh = function() { + var url = controller.parseUrl($location.absUrl()); $http.get(url) .then(controller.getTopologyData ? controller.getTopologyData : getTopologyData) .catch(miqService.handleFailure); }; - controller.refresh = refresh; - ManageIQ.angular.rxSubject.subscribe(function(event) { if (event.name === 'refreshTopology') { controller.refresh(); diff --git a/spec/javascripts/services/topology_service_spec.js b/spec/javascripts/services/topology_service_spec.js index 50b7b2f29a3..a19703998d5 100644 --- a/spec/javascripts/services/topology_service_spec.js +++ b/spec/javascripts/services/topology_service_spec.js @@ -43,4 +43,130 @@ describe('topologyService', function() { }); }); + describe('browser url to json endopoint url conversion', function() { + var controller; + + beforeEach(function() { + controller = {}; + testService.mixinRefresh(controller); + }); + + context('cloud', function() { + beforeEach(function() { + controller.dataUrl = '/cloud_topology/data'; + controller.detailUrl = null; + + testService.mixinRefresh(controller); + }); + + it('Compute > Cloud > Topology', function() { + var url = controller.parseUrl('/cloud_topology/show'); + expect(url).toEqual('/cloud_topology/data'); + }); + + it('Compute > Cloud > Providers > detail > Topology', function() { + var url = controller.parseUrl('/cloud_topology/show/10000000000004'); + expect(url).toEqual('/cloud_topology/data/10000000000004'); + }); + }); + + context('container', function() { + beforeEach(function() { + controller.dataUrl = '/container_topology/data'; + controller.detailUrl = '/container_project_topology/data'; + + testService.mixinRefresh(controller); + }); + + it('Compute > Containers > Topology', function() { + var url = controller.parseUrl('/container_topology/show'); + expect(url).toEqual('/container_topology/data'); + }); + + it('Compute > Containers > Providers > detail > Topology', function() { + var url = controller.parseUrl('/ems_container/10000000000040?display=topology') + expect(url).toEqual('/container_topology/data/10000000000040'); + }); + }); + + context('container project', function() { + beforeEach(function() { + controller.dataUrl = '/container_topology/data'; + controller.detailUrl = '/container_project_topology/data'; + + testService.mixinRefresh(controller); + }); + + it('Compute > Containers > Projects > detail > Topology', function() { + var url = controller.parseUrl('/container_project/show/10000000000001?display=topology'); + expect(url).toEqual('/container_project_topology/data/10000000000001'); + }); + }); + + context('infra', function() { + beforeEach(function() { + controller.dataUrl = '/infra_topology/data'; + controller.detailUrl = null; + + testService.mixinRefresh(controller); + }); + + it('Compute > Infrastructure > Topology', function() { + var url = controller.parseUrl('/infra_topology/show'); + expect(url).toEqual('/infra_topology/data'); + }); + + it('Compute > Infrastructure > Providers > detail > Topology', function() { + var url = controller.parseUrl('/infra_topology/show/10000000000028'); + expect(url).toEqual('/infra_topology/data/10000000000028'); + }); + }); + + context('middleware', function() { + beforeEach(function() { + controller.dataUrl = '/middleware_topology/data'; + controller.detailUrl = null; + + testService.mixinRefresh(controller); + }); + + it('Middleware > Topology', function() { + var url = controller.parseUrl('/middleware_topology/show'); + expect(url).toEqual('/middleware_topology/data'); + }); + + it('Middleware > Providers > detail > Topology', function() { + var url = controller.parseUrl('/middleware_topology/show/10000000000023'); + expect(url).toEqual('/middleware_topology/data/10000000000023'); + }); + }); + + /** TODO: network, once converted + it('Networks > Topology', function() { + var url = controller.parseUrl('/network_topology/show'); + expect(url).toEqual('/network_topology/data'); + }); + + it('Networks > Providers > detail > Topology', function() { + var url = controller.parseUrl('/network_topology/show/10000000000005'); + expect(url).toEqual('/network_topology/data/10000000000005'); + }); + */ + + context('physical infra', function() { + beforeEach(function() { + controller.dataUrl = '/physical_infra_topology/data'; + controller.detailUrl = null; + + testService.mixinRefresh(controller); + }); + + it('Compute > Physical Infrastructure > Topology', function() { + var url = controller.parseUrl('/physical_infra_topology/show'); + expect(url).toEqual('/physical_infra_topology/data'); + }); + + // TODO: physical infrastructure - topology from detail screen, add once there is a working detail screen + }); + }); });