From 6c03247b2beb7b6206cb4d72e647aee5637e3b59 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Tue, 2 Apr 2013 08:58:27 +0200 Subject: [PATCH] GraphViewer: Adapted Tests for EdgeShaper, this will be moved to the same interface as NodeShaper --- .../specEdgeShaper/edgeShaperSpec.js | 62 ++++++++++++++++--- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/html/admin/js/graphViewer/jasmine_test/specEdgeShaper/edgeShaperSpec.js b/html/admin/js/graphViewer/jasmine_test/specEdgeShaper/edgeShaperSpec.js index 2b05287590..0e3d1071fd 100644 --- a/html/admin/js/graphViewer/jasmine_test/specEdgeShaper/edgeShaperSpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specEdgeShaper/edgeShaperSpec.js @@ -144,8 +144,11 @@ }, shaper = new EdgeShaper(d3.select("svg")); - shaper.on("click", click); - shaper.drawEdges(edges); + shaper.changeTo({ + actions: { + click: click + } + }); helper.simulateMouseEvent("click", "1-2"); helper.simulateMouseEvent("click", "3-4"); @@ -180,7 +183,11 @@ it('should be able to add a click event to existing edges', function() { expect($("svg .link").length).toEqual(3); - shaper.on("click", click); + shaper.changeTo({ + actions: { + click: click + } + }); helper.simulateMouseEvent("click", "1-2"); helper.simulateMouseEvent("click", "3-4"); expect(clicked[1]).toBeTruthy(); @@ -190,7 +197,11 @@ it('should add a click event to newly arriving edges', function() { - shaper.on("click", click); + shaper.changeTo({ + actions: { + click: click + } + }); edges.push({_id: 4, source: nodes[3], target: nodes[0]}); edges.push({_id: 5, source: nodes[0], target: nodes[2]}); shaper.drawEdges(edges); @@ -206,11 +217,23 @@ }); it('should display each edge exactly once if an event is added', function() { - shaper.on("click", function() {return 0;}); + shaper.changeTo({ + actions: { + click: function() {return 0;} + } + }); expect($("svg .link").length).toEqual(3); - shaper.on("click", function() {return 1;}); + shaper.changeTo({ + actions: { + click: function() {return 0;} + } + }); expect($("svg .link").length).toEqual(3); - shaper.on("click", function() {return 2;}); + shaper.changeTo({ + actions: { + click: function() {return 0;} + } + }); expect($("svg .link").length).toEqual(3); }); }); @@ -289,6 +312,31 @@ expect($("#4-1 text")[0].textContent).toEqual("correct"); }); + it('should be able to switch to another label', function() { + var nodes = [{"_id": 1}, {"_id": 2}], + edges = [ + { + "source": nodes[0], + "target": nodes[1], + "label": "old" + }, + { + "source": nodes[1], + "target": nodes[0], + "new": "new" + } + ]; + shaper.drawEdges(edges); + + expect($("#1-2")[0].textContent).toEqual("old"); + expect($("#2-1")[0].textContent).toEqual(""); + + shaper.changeTo({label: "new"}); + + expect($("#1-2")[0].textContent).toEqual(""); + expect($("#2-1")[0].textContent).toEqual("new"); + }); + }); describe('using a function for labels', function() {