Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs js test for Middleware Topology Controller for Issue #8214 #8642

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function MiddlewareTopologyCtrl($scope, $http, $interval, $location, topologySer
*/
added.attr("class", function(d) { return d.item.kind; });
added.append("circle")
.attr("r", function(d) { return getDimensions(d).r})
.attr("r", function(d) { return self.getDimensions(d).r})
.attr('class' , function(d) {
return topologyService.getItemStatusClass(d);
});
Expand All @@ -71,12 +71,12 @@ function MiddlewareTopologyCtrl($scope, $http, $interval, $location, topologySer
return self.dblclick(d);});
added.append("image")
.attr("xlink:href",function(d) {
return "/assets/svg/" + class_name(d) + ".svg";
return "/assets/svg/" + self.class_name(d) + ".svg";
})
.attr("y", function(d) { return getDimensions(d).y})
.attr("x", function(d) { return getDimensions(d).x})
.attr("height", function(d) { return getDimensions(d).height})
.attr("width", function(d) { return getDimensions(d).width});
.attr("y", function(d) { return self.getDimensions(d).y})
.attr("x", function(d) { return self.getDimensions(d).x})
.attr("height", function(d) { return self.getDimensions(d).height})
.attr("width", function(d) { return self.getDimensions(d).width});
added.append("text")
.attr("x", 26)
.attr("y", 24)
Expand All @@ -92,16 +92,16 @@ function MiddlewareTopologyCtrl($scope, $http, $interval, $location, topologySer
ev.preventDefault();
});

function class_name(d) {
self.class_name = function class_name(d) {
var class_name = d.item.icon;
return class_name;
}
};

this.dblclick = function dblclick(d) {
window.location.assign(topologyService.geturl(d));
};

function getDimensions(d) {
self.getDimensions = function getDimensions(d) {
switch (d.item.kind) {
case "MiddlewareManager":
return { x: -20, y: -20, height: 40, width: 40, r: 28};
Expand All @@ -113,7 +113,7 @@ function MiddlewareTopologyCtrl($scope, $http, $interval, $location, topologySer
return { x: -9, y: -9, height: 18, width: 18, r: 17};
}

}
};

$scope.searchNode = function() {
var svg = topologyService.getSVG(d3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
describe('middlewareTopologyController', function () {
var scope, $controller, $httpBackend;
var mock_data = getJSONFixture('middleware_topology_response.json');

var mw_manager = {
id: "1", item: {
"name": "Hawkular",
"kind": "MiddlewareManager",
"miq_id": 1,
"status": "Unknown",
"display_kind": "Hawkular",
"icon": "vendor-hawkular",
"id": "1"
}
};

var mw_server = {
id: "/t;28026b36-8fe4-4332-84c8-524e173a68bf/f;91044f79-156e-4076-8056-ac3ac44ffff9/r;Local~~", item: {
"name": "Local",
"kind": "MiddlewareServer",
"miq_id": 4,
"status": "Unknown",
"display_kind": "MiddlewareServer",
"icon": "vendor-hawkular",
"id": "Local~~"
}
};

var mw_deployment = {
id: "/t;28026b36-8fe4-4332-84c8-524e173a68bf/f;91044f79-156e-4076-8056-ac3ac44ffff9/r;Local~~/r;Local~%2Fdeployment%3Dhawkular-command-gateway-war.war",
item: {
"name": "hawkular-command-gateway-war.war",
"kind": "MiddlewareDeployment",
"miq_id": 49,
"status": "Unknown",
"display_kind": "MiddlewareDeployment",
"icon": "middleware_deployment_war",
"id": "Local~/deployment=hawkular-command-gateway-war.war"
}
};

beforeEach(module('mwTopologyApp'));

beforeEach(inject(function (_$httpBackend_, $rootScope, _$controller_, $location) {
spyOn($location, 'absUrl').and.returnValue('/middleware_topology/show');
scope = $rootScope.$new();

$httpBackend = _$httpBackend_;
$httpBackend.when('GET', '/middleware_topology/data').respond(mock_data);
$controller = _$controller_('middlewareTopologyController',
{$scope: scope});
$httpBackend.flush();
}));

afterEach(function () {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});

describe('mw topology data loads successfully', function () {
it('in all main objects', function () {
expect(scope.items).toBeDefined();
expect(scope.relations).toBeDefined();
expect(scope.kinds).toBeDefined();
});
});

describe('kinds contains all expected mw kinds', function () {
it('in all main objects', function () {
expect(Object.keys(scope.kinds).length).toBe(3);
expect(scope.kinds["MiddlewareManager"]).toBeDefined();
expect(scope.kinds["MiddlewareServer"]).toBeDefined();
expect(scope.kinds["MiddlewareDeployment"]).toBeDefined();
});
});

describe('the mw topology gets correct icons', function () {
it('in graph elements', function () {
expect($controller.class_name(mw_manager)).toContain("vendor-hawkular");
expect($controller.class_name(mw_server)).toContain("vendor-hawkular");
expect($controller.class_name(mw_deployment)).toContain("middleware_deployment_war");
});
});

describe('dimensions are returned correctly', function () {
it('for all objects', function () {
expect($controller.getDimensions(mw_manager)).toEqual({x: -20, y: -20, height: 40, width: 40, r: 28});
expect($controller.getDimensions(mw_server)).toEqual({x: -12, y: -12, height: 23, width: 23, r: 19});
expect($controller.getDimensions(mw_deployment)).toEqual({x: -9, y: -9, height: 18, width: 18, r: 17});
});
});

});
Loading