1
0
Fork 0

GraphViewer: Fixed tests for UI

This commit is contained in:
Michael Hackstein 2013-08-06 15:16:10 +02:00
parent 389a3c7950
commit 4da94ff62f
3 changed files with 45 additions and 26 deletions

View File

@ -58,6 +58,7 @@ function GraphViewer(svg, width, height, adapterConfig, config) {
nodeShaper, nodeShaper,
edgeShaper, edgeShaper,
layouter, layouter,
zoomManager,
graphContainer, graphContainer,
nodeContainer, nodeContainer,
edgeContainer, edgeContainer,
@ -95,7 +96,7 @@ function GraphViewer(svg, width, height, adapterConfig, config) {
parseZoomConfig = function(config) { parseZoomConfig = function(config) {
if (config) { if (config) {
self.zoomManager = new ZoomManager(width, height, svg, zoomManager = new ZoomManager(width, height, svg,
graphContainer, nodeShaper, edgeShaper, graphContainer, nodeShaper, edgeShaper,
{}, nodeLimitCallBack); {}, nodeLimitCallBack);
} }
@ -162,14 +163,14 @@ function GraphViewer(svg, width, height, adapterConfig, config) {
parseConfig(config || {}); parseConfig(config || {});
self.start = function() { this.start = function() {
layouter.stop(); layouter.stop();
nodeShaper.drawNodes(nodes); nodeShaper.drawNodes(nodes);
edgeShaper.drawEdges(edges); edgeShaper.drawEdges(edges);
layouter.start(); layouter.start();
}; };
self.loadGraph = function(nodeId, callback) { this.loadGraph = function(nodeId, callback) {
// loadNode // loadNode
// loadInitialNode // loadInitialNode
adapter.loadInitialNode(nodeId, function (node) { adapter.loadInitialNode(nodeId, function (node) {
@ -185,7 +186,7 @@ function GraphViewer(svg, width, height, adapterConfig, config) {
}); });
}; };
self.loadGraphWithAttributeValue = function(attribute, value, callback) { this.loadGraphWithAttributeValue = function(attribute, value, callback) {
// loadNodeFromTreeByAttributeValue // loadNodeFromTreeByAttributeValue
adapter.loadInitialNodeByAttributeValue(attribute, value, function (node) { adapter.loadInitialNodeByAttributeValue(attribute, value, function (node) {
if (node.errorCode) { if (node.errorCode) {
@ -200,7 +201,7 @@ function GraphViewer(svg, width, height, adapterConfig, config) {
}); });
}; };
self.dispatcherConfig = { this.dispatcherConfig = {
expand: { expand: {
edges: edges, edges: edges,
nodes: nodes, nodes: nodes,
@ -220,8 +221,9 @@ function GraphViewer(svg, width, height, adapterConfig, config) {
adapter: adapter adapter: adapter
} }
}; };
self.adapter = adapter; this.adapter = adapter;
self.nodeShaper = nodeShaper; this.nodeShaper = nodeShaper;
self.edgeShaper = edgeShaper; this.edgeShaper = edgeShaper;
self.layouter = layouter; this.layouter = layouter;
} this.zoomManager = zoomManager;
}

View File

@ -47,7 +47,7 @@ var uiMatchers = uiMatchers || {};
toBeOfClass: function(name) { toBeOfClass: function(name) {
var el = $(this.actual); var el = $(this.actual);
this.message = function() { this.message = function() {
return "Expected " + el.className + " to contain " + name; return "Expected \"" + el.attr("class") + "\" to contain " + name;
}; };
return el.hasClass(name); return el.hasClass(name);
}, },

View File

@ -60,6 +60,12 @@
r.getCollections = function(callback) { r.getCollections = function(callback) {
callback(["nodes"], ["edges"]); callback(["nodes"], ["edges"]);
}; };
r.getGraphs = function(callback) {
callback(["graph"]);
};
r.getAttributeExamples = function(callback) {
callback(["name", "type"]);
};
r.getPrioList = function() { r.getPrioList = function() {
return []; return [];
}; };
@ -67,9 +73,13 @@
}; };
//Mock for ZoomManager //Mock for ZoomManager
if (window.ZoomManager === undefined) { if (window.ZoomManager === undefined) {
window.ZoomManager = {}; window.ZoomManager = {
getMinimalZoomFactor: function() {
return 0.16;
}
};
} }
spyOn(window, "ZoomManager"); spyOn(window, "ZoomManager").andCallThrough();
div = document.createElement("div"); div = document.createElement("div");
div.id = "contentDiv"; div.id = "contentDiv";
div.style.width = "200px"; div.style.width = "200px";
@ -187,12 +197,13 @@
expect($(barSelector + " #loadnode").length).toEqual(1); expect($(barSelector + " #loadnode").length).toEqual(1);
expect(attrfield).toBeTag("input"); expect(attrfield).toBeTag("input");
expect(attrfield.type).toEqual("text"); expect(attrfield.type).toEqual("text");
expect(attrfield.className).toEqual("input-mini searchByAttribute"); expect(attrfield).toBeOfClass("input");
expect(attrfield.placeholder).toEqual("key"); expect(attrfield.placeholder).toEqual("Attribute");
expect(valfield).toBeTag("input"); expect(valfield).toBeTag("input");
expect(valfield.type).toEqual("text"); expect(valfield.type).toEqual("text");
expect(valfield.className).toEqual("searchInput"); expect(valfield).toBeOfClass("searchInput");
expect(valfield.placeholder).toEqual("value"); expect(valfield).toBeOfClass("input-xlarge");
expect(valfield.placeholder).toEqual("Value");
expect(btn).toBeTag("img"); expect(btn).toBeTag("img");
expect(btn.className).toEqual("searchSubmit"); expect(btn.className).toEqual("searchSubmit");
}); });
@ -261,7 +272,8 @@
it('should have the same layout as the web interface', function() { it('should have the same layout as the web interface', function() {
var header = div.children[0], var header = div.children[0],
transHeader = header.firstChild, transHeader = header.firstChild,
searchField = transHeader.children[0], transPH = transHeader.children[0],
searchField = transPH.children[0],
content = div.children[1]; content = div.children[1];
expect(header).toBeTag("ul"); expect(header).toBeTag("ul");
@ -269,15 +281,20 @@
expect(header.className).toEqual("thumbnails2"); expect(header.className).toEqual("thumbnails2");
expect(transHeader).toBeTag("div"); expect(transHeader).toBeTag("div");
expect(transHeader.id).toEqual("transparentHeader"); expect(transHeader.id).toEqual("transparentHeader");
expect(transPH).toBeTag("div");
expect(transPH).toBeOfClass("pull-left");
expect(transPH.id).toEqual("transparentPlaceholder");
expect(searchField).toBeTag("div"); expect(searchField).toBeTag("div");
expect(searchField.id).toEqual("transparentPlaceholder"); expect(searchField).toBeOfClass("pull-left");
expect(searchField.className).toEqual("pull-left"); expect(searchField).toBeOfClass("input-append");
expect(searchField).toBeOfClass("searchByAttribute");
expect(searchField.children[0]).toBeTag("input");
expect(searchField.children[0].id).toEqual("attribute"); expect(searchField.children[0].id).toEqual("attribute");
expect(searchField.children[1]).toBeTag("span"); expect(transPH.children[1]).toBeTag("span");
expect(searchField.children[1].textContent).toEqual("=="); expect(transPH.children[1].textContent).toEqual("==");
expect(searchField.children[2].id).toEqual("value"); expect(transPH.children[2].id).toEqual("value");
expect(searchField.children[3].id).toEqual("loadnode"); expect(transPH.children[3].id).toEqual("loadnode");
}); });
}); });
@ -668,4 +685,4 @@
}); });
}()); }());