From 7eb6b93ee90f4920957d3e47a060779207bc38ce Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Wed, 9 Sep 2015 18:44:54 +0200 Subject: [PATCH] added test for adjacency --- .../app/scripts/stores/__tests__/app-store-test.js | 14 ++++++++++++++ client/app/scripts/stores/app-store.js | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/client/app/scripts/stores/__tests__/app-store-test.js b/client/app/scripts/stores/__tests__/app-store-test.js index 1fae1e04d..a6011fa5c 100644 --- a/client/app/scripts/stores/__tests__/app-store-test.js +++ b/client/app/scripts/stores/__tests__/app-store-test.js @@ -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); + }); }); \ No newline at end of file diff --git a/client/app/scripts/stores/app-store.js b/client/app/scripts/stores/app-store.js index bc594492d..8745de52a 100644 --- a/client/app/scripts/stores/app-store.js +++ b/client/app/scripts/stores/app-store.js @@ -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); } });