From 192e75716e55cf7ef9a52fd05be3543b8c386bee Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Wed, 10 Apr 2013 11:01:33 +0200 Subject: [PATCH] GraphViewer: There was a minor bug in JSONAdapter. Fixed now --- .../admin/js/graphViewer/graph/JSONAdapter.js | 17 +++---- .../js/graphViewer/graph/eventLibrary.js | 1 - html/admin/js/graphViewer/graphViewer.js | 7 --- .../graphViewer/jasmine_test/runnerAll.html | 1 + .../specEvents/eventDispatcherSpec.js | 27 +++++++++- .../specEvents/eventLibrarySpec.js | 51 +++++++++++++++++++ .../specGraphViewer/graphViewerSpec.js | 2 +- 7 files changed, 85 insertions(+), 21 deletions(-) diff --git a/html/admin/js/graphViewer/graph/JSONAdapter.js b/html/admin/js/graphViewer/graph/JSONAdapter.js index ee62f0a282..bc3a5185ed 100644 --- a/html/admin/js/graphViewer/graph/JSONAdapter.js +++ b/html/admin/js/graphViewer/graph/JSONAdapter.js @@ -97,18 +97,13 @@ function JSONAdapter(jsonPath, nodes, edges, width, height) { }); _.each(n.children, function(c) { var check = findNode(c); - if (check) { - insertEdge(n, check); - self.requestCentralityChildren(check._id, function(c) { - n._centrality = c; - }); - } else { - insertNode(c); - insertEdge(n, c); - self.requestCentralityChildren(c._id, function(c) { - n._centrality = c; - }); + if (!check) { + check = insertNode(c); } + insertEdge(n, check); + self.requestCentralityChildren(check._id, function(c) { + n._centrality = c; + }); }); if (callback) { callback(n); diff --git a/html/admin/js/graphViewer/graph/eventLibrary.js b/html/admin/js/graphViewer/graph/eventLibrary.js index f78232beef..cb80a356ec 100644 --- a/html/admin/js/graphViewer/graph/eventLibrary.js +++ b/html/admin/js/graphViewer/graph/eventLibrary.js @@ -78,7 +78,6 @@ function EventLibrary() { this.Expand = function (config) { self.checkExpandConfig(config); - var edges = config.edges, nodes = config.nodes, startCallback = config.startCallback, diff --git a/html/admin/js/graphViewer/graphViewer.js b/html/admin/js/graphViewer/graphViewer.js index 3312718d4c..7ce2ece958 100644 --- a/html/admin/js/graphViewer/graphViewer.js +++ b/html/admin/js/graphViewer/graphViewer.js @@ -95,13 +95,6 @@ function GraphViewer(svg, width, height, if (checkDefs(conf.expand)) { dispatcher.bind(conf.expand.target, conf.expand.type, dispatcher.events.EXPAND); - dispatcher.bind("nodes", "update", function(node) { - node.selectAll("circle") - .attr("class", function(d) { - return d._expanded ? "expanded" : - d._centrality === 0 ? "single" : "collapsed"; - }); - }); } if (checkDefs(conf.createNode) diff --git a/html/admin/js/graphViewer/jasmine_test/runnerAll.html b/html/admin/js/graphViewer/jasmine_test/runnerAll.html index b21afd57a9..c99e816d2d 100644 --- a/html/admin/js/graphViewer/jasmine_test/runnerAll.html +++ b/html/admin/js/graphViewer/jasmine_test/runnerAll.html @@ -36,6 +36,7 @@ + diff --git a/html/admin/js/graphViewer/jasmine_test/specEvents/eventDispatcherSpec.js b/html/admin/js/graphViewer/jasmine_test/specEvents/eventDispatcherSpec.js index ac96a9eaac..e20582ef66 100644 --- a/html/admin/js/graphViewer/jasmine_test/specEvents/eventDispatcherSpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specEvents/eventDispatcherSpec.js @@ -74,11 +74,14 @@ nodes = []; edges = []; + this.loadNode = function() {}; + spyOn(this, "loadNode"); + expandConfig = { edges: edges, nodes: nodes, startCallback: function() {}, - loadNode: function() {}, + loadNode: this.loadNode, reshapeNode: function() {} }; @@ -419,7 +422,29 @@ describe('checking different events', function() { it('should be able to bind the expand event', function() { + runs(function() { + nodes = [{_id: 1}]; + nodeShaper.drawNodes(nodes); + dispatcher.bind("nodes", "click", dispatcher.events.EXPAND); + helper.simulateMouseEvent("click", "1"); + }); + waitsFor(function() { + return this.loadNode.wasCalled; + }, 1000, "The loadNode function should have been called."); + + runs(function() { + expect(nodes[0]._expanded).toBeTruthy(); + helper.simulateMouseEvent("click", "1"); + }); + + waitsFor(function() { + return !nodes[0]._expanded; + }, 1000, "The loadNode function should have been called."); + + runs(function() { + expect(true).toBeTruthy(); + }); }); it('should be able to bind the drag event', function() { diff --git a/html/admin/js/graphViewer/jasmine_test/specEvents/eventLibrarySpec.js b/html/admin/js/graphViewer/jasmine_test/specEvents/eventLibrarySpec.js index 15d8a14b61..435412bbcd 100644 --- a/html/admin/js/graphViewer/jasmine_test/specEvents/eventLibrarySpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specEvents/eventLibrarySpec.js @@ -162,6 +162,57 @@ expect(reshapedNodes[0]).toEqual(root); }); + it('should not remove referenced nodes on collapsing ', function() { + var root = { + _id: 0, + _expanded: true, + _outboundCounter: 2, + _inboundCounter: 0 + }, + c1 = { + _id: 1, + _outboundCounter: 0, + _inboundCounter: 2 + }, + c2 = { + _id: 2, + _outboundCounter: 1, + _inboundCounter: 0 + }, + c3 = { + _id: 3, + _outboundCounter: 0, + _inboundCounter: 1 + }; + + nodes.push(root); + nodes.push(c1); + nodes.push(c2); + nodes.push(c3); + edges.push({source: root, target: c1}); + edges.push({source: root, target: c3}); + edges.push({source: c2, target: c1}); + + testee = eventLib.Expand(config); + testee(root); + + expect(root._expanded).toBeFalsy(); + expect(started).toEqual(1); + expect(reshaped).toEqual(1); + expect(loaded).toEqual(0); + expect(nodes.length).toEqual(3); + expect(edges.length).toEqual(1); + expect(reshapedNodes.length).toEqual(1); + expect(reshapedNodes[0]).toEqual(root); + + expect(root._outboundCounter).toEqual(0); + expect(c1._inboundCounter).toEqual(1); + expect(c2._outboundCounter).toEqual(1); + }); + + + + describe('setup process', function() { var testConfig = {}; diff --git a/html/admin/js/graphViewer/jasmine_test/specGraphViewer/graphViewerSpec.js b/html/admin/js/graphViewer/jasmine_test/specGraphViewer/graphViewerSpec.js index 80d3059117..36f2d52f42 100644 --- a/html/admin/js/graphViewer/jasmine_test/specGraphViewer/graphViewerSpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specGraphViewer/graphViewerSpec.js @@ -362,7 +362,7 @@ describe("Graph Viewer", function() { // Wait a gentle second for all nodes to expand properly waits(1000); - + runs(function() { clickOnNode(1); clickOnNode(4);