added test for adjacency

This commit is contained in:
David Kaltschmidt
2015-09-09 18:44:54 +02:00
parent f764e4415e
commit 7eb6b93ee9
2 changed files with 15 additions and 1 deletions

View File

@@ -285,5 +285,19 @@ describe('AppStore', function() {
expect(AppStore.getNodes().toJS()).toEqual({});
});
// adjacency test
it('returns the correct adjacency set for a node', function() {
registeredCallback(ReceiveNodesDeltaAction);
expect(AppStore.getAdjacentNodes().size).toEqual(0);
registeredCallback(ClickNodeAction);
expect(AppStore.getAdjacentNodes().size).toEqual(2);
expect(AppStore.getAdjacentNodes().has('n1')).toBeTruthy();
expect(AppStore.getAdjacentNodes().has('n2')).toBeTruthy();
registeredCallback(HitEscAction)
expect(AppStore.getAdjacentNodes().size).toEqual(0);
});
});

View File

@@ -102,7 +102,7 @@ const AppStore = assign({}, EventEmitter.prototype, {
adjacentNodes = makeSet(nodes.get(selectedNodeId).get('adjacency'));
// fill up set with reverse edges
nodes.forEach(function(node, nodeId) {
if (node.get('adjacency').includes(selectedNodeId)) {
if (node.get('adjacency') && node.get('adjacency').includes(selectedNodeId)) {
adjacentNodes = adjacentNodes.add(nodeId);
}
});