mirror of https://gitee.com/bigwinds/arangodb
GraphViewer: Added integration testsuite for abstract adapters
This commit is contained in:
parent
0c4237cb23
commit
3e105873a9
|
@ -4,7 +4,7 @@
|
||||||
/*global runs, spyOn, waitsFor, waits */
|
/*global runs, spyOn, waitsFor, waits */
|
||||||
/*global window, eb, loadFixtures, document */
|
/*global window, eb, loadFixtures, document */
|
||||||
/*global $, _, d3*/
|
/*global $, _, d3*/
|
||||||
/*global describeInterface*/
|
/*global describeInterface, describeIntegeration*/
|
||||||
/*global ArangoAdapter*/
|
/*global ArangoAdapter*/
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -45,6 +45,59 @@
|
||||||
edgeCollection: ""
|
edgeCollection: ""
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
describeIntegeration(function() {
|
||||||
|
spyOn($, "ajax").andCallFake(function(req) {
|
||||||
|
var node1 = {_id: 1},
|
||||||
|
node2 = {_id: 2},
|
||||||
|
edge = {_id: "1-2", _from: 1, _to: 2};
|
||||||
|
|
||||||
|
switch(req.type) {
|
||||||
|
case "DELETE":
|
||||||
|
req.success();
|
||||||
|
break;
|
||||||
|
case "POST":
|
||||||
|
if (req.url.match(/_api\/cursor$/)) {
|
||||||
|
req.success({result:
|
||||||
|
[
|
||||||
|
[{
|
||||||
|
vertex: node1,
|
||||||
|
path: {
|
||||||
|
edges: [],
|
||||||
|
vertices: [
|
||||||
|
node1
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
},{
|
||||||
|
vertex: node2,
|
||||||
|
path: {
|
||||||
|
edges: [
|
||||||
|
edge
|
||||||
|
],
|
||||||
|
vertices: [
|
||||||
|
node1,
|
||||||
|
node2
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
]});
|
||||||
|
} else if (req.url.match(/_api\/edge/)) {
|
||||||
|
req.success({_id: "1-2"});
|
||||||
|
} else {
|
||||||
|
req.success({_id: 1});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
req.success();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return new ArangoAdapter([], [], {
|
||||||
|
nodeCollection: "",
|
||||||
|
edgeCollection: ""
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var adapter,
|
var adapter,
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
|
@ -1707,7 +1760,7 @@
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
|
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
|
||||||
/*global it, expect, describe*/
|
/*global it, expect, describe, beforeEach*/
|
||||||
|
/*global spyOn, jasmine, window*/
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -76,7 +77,127 @@ var describeInterface = function (testee) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var describeIntegeration = function(testee) {
|
/**
|
||||||
|
* Expectations on constructor:
|
||||||
|
* loadNode -> Adds {_id: 1} -{_id:"1-2"}-> {_id: 2}
|
||||||
|
* createEdge({source: {_id: 1}, target: {_id: 1}}) -> {_id: "1-2", _from:1, _to:2}
|
||||||
|
* createNode({}) -> {_id: 1}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
var describeIntegeration = function(constructor) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
describe('checking integeration of the abstract adapter', function() {
|
||||||
|
|
||||||
|
var mockedAbstract, testee;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
mockedAbstract = {
|
||||||
|
edges: [],
|
||||||
|
nodes: [],
|
||||||
|
setWidth: function(){},
|
||||||
|
setHeight: function(){},
|
||||||
|
insertNode: function(data){
|
||||||
|
var node = {
|
||||||
|
_data: data,
|
||||||
|
_id: data._id
|
||||||
|
}, i;
|
||||||
|
for (i = 0; i < this.nodes.length; i++) {
|
||||||
|
if (this.nodes[i]._id === node._id) {
|
||||||
|
return this.nodes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.nodes.push(node);
|
||||||
|
return node;
|
||||||
|
},
|
||||||
|
insertEdge: function(){},
|
||||||
|
removeNode: function(){},
|
||||||
|
removeEdge: function(){},
|
||||||
|
removeEdgesForNode: function(){},
|
||||||
|
expandCommunity: function(){},
|
||||||
|
setNodeLimit: function(){},
|
||||||
|
setChildLimit: function(){},
|
||||||
|
checkSizeOfInserted: function(){},
|
||||||
|
checkNodeLimit: function(){}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
spyOn(window, "AbstractAdapter").andCallFake(function(nodes, edges) {
|
||||||
|
mockedAbstract.nodes = nodes;
|
||||||
|
mockedAbstract.edges = edges;
|
||||||
|
return mockedAbstract;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call setNodeLimit on the abstract', function() {
|
||||||
|
spyOn(mockedAbstract, "setNodeLimit");
|
||||||
|
testee = constructor();
|
||||||
|
testee.setNodeLimit(5, function(){});
|
||||||
|
expect(mockedAbstract.setNodeLimit).wasCalledWith(5, jasmine.any(Function));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call setChildLimit on the abstract', function() {
|
||||||
|
spyOn(mockedAbstract, "setChildLimit");
|
||||||
|
testee = constructor();
|
||||||
|
testee.setChildLimit(5);
|
||||||
|
expect(mockedAbstract.setChildLimit).wasCalledWith(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call expandCommunity on the abstract', function() {
|
||||||
|
spyOn(mockedAbstract, "expandCommunity");
|
||||||
|
var comm = {};
|
||||||
|
testee = constructor();
|
||||||
|
testee.expandCommunity(comm);
|
||||||
|
expect(mockedAbstract.expandCommunity).wasCalledWith(comm);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use the abstract to insert objects from loadNode', function() {
|
||||||
|
spyOn(mockedAbstract, "insertNode").andCallThrough();
|
||||||
|
spyOn(mockedAbstract, "insertEdge").andCallThrough();
|
||||||
|
spyOn(mockedAbstract, "checkSizeOfInserted");
|
||||||
|
spyOn(mockedAbstract, "checkNodeLimit");
|
||||||
|
testee = constructor();
|
||||||
|
testee.loadNode(1);
|
||||||
|
expect(mockedAbstract.insertNode).wasCalledWith({_id: 1});
|
||||||
|
expect(mockedAbstract.insertNode).wasCalledWith({_id: 2});
|
||||||
|
expect(mockedAbstract.insertEdge).wasCalledWith({_id: "1-2", _from: 1, _to: 2});
|
||||||
|
expect(mockedAbstract.checkSizeOfInserted).wasCalledWith({2: mockedAbstract.nodes[1]});
|
||||||
|
expect(mockedAbstract.checkNodeLimit).wasCalledWith(mockedAbstract.nodes[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should insert an edge on createEdge', function() {
|
||||||
|
spyOn(mockedAbstract, "insertEdge");
|
||||||
|
testee = constructor();
|
||||||
|
testee.createEdge({source: {_id: 1}, target: {_id: 2}}, function(){});
|
||||||
|
expect(mockedAbstract.insertEdge).wasCalledWith({_id: "1-2", _from: 1, _to: 2});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove an edge on deleteEdge', function() {
|
||||||
|
spyOn(mockedAbstract, "removeEdge");
|
||||||
|
testee = constructor();
|
||||||
|
var edge = {_id: "1-2", _from: 1, _to: 2};
|
||||||
|
testee.deleteEdge(edge);
|
||||||
|
expect(mockedAbstract.removeEdge).wasCalledWith(edge);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should insert a node on createNode', function() {
|
||||||
|
spyOn(mockedAbstract, "insertNode");
|
||||||
|
testee = constructor();
|
||||||
|
testee.createNode({}, function(){});
|
||||||
|
expect(mockedAbstract.insertNode).wasCalledWith({_id: 1});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove a node on deleteNode', function() {
|
||||||
|
spyOn(mockedAbstract, "removeNode");
|
||||||
|
spyOn(mockedAbstract, "removeEdgesForNode");
|
||||||
|
testee = constructor();
|
||||||
|
var node = {_id: 1};
|
||||||
|
testee.deleteNode(node);
|
||||||
|
expect(mockedAbstract.removeEdgesForNode).wasCalledWith(node);
|
||||||
|
expect(mockedAbstract.removeNode).wasCalledWith(node);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue