Skip to content

Commit

Permalink
Merge pull request #3219 from himdel/topology-parseurl
Browse files Browse the repository at this point in the history
topologyService (js) - fix and test screen url to data url conversion
(cherry picked from commit e2c0f81)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1533519
  • Loading branch information
mzazrivec authored and simaishi committed Jan 11, 2018
1 parent 5bb0d82 commit 487c59a
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 11 deletions.
35 changes: 24 additions & 11 deletions app/assets/javascripts/services/topology_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
126 changes: 126 additions & 0 deletions spec/javascripts/services/topology_service_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
});

0 comments on commit 487c59a

Please sign in to comment.