From 8622b67d193bd92af9a00e7e6e25a6b1379caca6 Mon Sep 17 00:00:00 2001 From: scottashton Date: Mon, 30 Jun 2014 14:53:13 +0200 Subject: [PATCH 1/2] more tests for graph management --- .../frontend/js/views/graphManagementView.js | 19 +- .../specs/views/graphManagementViewSpec.js | 444 +++++++++++++++++- 2 files changed, 444 insertions(+), 19 deletions(-) diff --git a/js/apps/system/aardvark/frontend/js/views/graphManagementView.js b/js/apps/system/aardvark/frontend/js/views/graphManagementView.js index bd05173f46..c27ef86f11 100644 --- a/js/apps/system/aardvark/frontend/js/views/graphManagementView.js +++ b/js/apps/system/aardvark/frontend/js/views/graphManagementView.js @@ -180,14 +180,12 @@ } } ); - //if no edge definition is left if (edgeDefinitions.length === 0) { $('#s2id_newEdgeDefinitions0 .select2-choices').css("border-color", "red"); return; } - //get current edgeDefs/orphanage var graph = this.collection.findWhere({_key: name}); var currentEdgeDefinitions = graph.get("edgeDefinitions"); @@ -202,7 +200,6 @@ } } ); - //add new orphans editedVertexCollections.forEach( function(vC) { @@ -212,7 +209,6 @@ } ); - //evaluate all new, edited and deleted edge definitions var newEDs = []; var editedEDs = []; @@ -259,7 +255,6 @@ graph.deleteEdgeDefinition(eD); } ); - this.updateGraphManagementView(); window.modalView.hide(); }, @@ -315,6 +310,13 @@ index, edgeDefinitionElements; + if (!name) { + arangoHelper.arangoError( + "A name for the graph has to be provided." + ); + return 0; + } + if (this.collection.findWhere({_key: name})) { arangoHelper.arangoError( "The graph '" + name + "' already exists." @@ -343,12 +345,7 @@ } } ); - if (!name) { - arangoHelper.arangoError( - "A name for the graph has to be provided." - ); - return 0; - } + this.collection.create({ name: name, edgeDefinitions: edgeDefinitions, diff --git a/js/apps/system/aardvark/test/specs/views/graphManagementViewSpec.js b/js/apps/system/aardvark/test/specs/views/graphManagementViewSpec.js index 01c1e84006..ed3849035a 100644 --- a/js/apps/system/aardvark/test/specs/views/graphManagementViewSpec.js +++ b/js/apps/system/aardvark/test/specs/views/graphManagementViewSpec.js @@ -40,6 +40,22 @@ document.body.removeChild(modalDiv); }); + it("should updateGraphManagementView", function () { + + spyOn(view.collection, "fetch").andCallFake(function (a) { + a.success(); + }); + + spyOn(view, "render"); + + view.updateGraphManagementView(); + + expect(view.render).toHaveBeenCalled(); + + + + }); + it("should fetch the graphs on render", function () { spyOn(graphs, "fetch"); view.render(); @@ -426,6 +442,61 @@ }); + it("should search", function () { + + var a = { + val : function () { + return "searchString"; + }, + html: function () { + return ""; + }, + focus: function () { + return ""; + }, + 0 : {setSelectionRange: function () { + return ""; + }} + }; + + var g = { + _key: "blub2", + name: "blub2", + edgeDefinitions: [{ + collection: "blub", + from: ["bla"], + to: ["blob"] + },{ + collection: "blub2", + from: ["bla"], + to: ["blob"] + }], + orphanCollections: [], + get : function (a) { + return g[a] + } + }; + + spyOn(view.collection, "filter").andCallFake(function (a) { + a(g); + return g; + }); + + spyOn(window, "$").andReturn(a); + spyOn(view.template, "render"); + + view.search(); + + expect(view.template.render).toHaveBeenCalledWith({ + graphs : g, + searchString : "searchString" + }); + + + + }); + + it("should create edit graph modal in edit mode", function () { var g = { @@ -476,15 +547,169 @@ }); - /*editGraph : function(e) { - e.stopPropagation(); - this.collection.fetch(); - this.graphToEdit = this.evaluateGraphName($(e.currentTarget).attr("id"), '_settings'); - var graph = this.collection.findWhere({_key: this.graphToEdit}); - this.createEditGraphModal( - graph + + it("should not saveEditedGraph as no defintions are supplied", function () { + + var + a = { + p : "", + setParam : function (p) { + a.p = p; + }, + select2: function () { + if (a.p === "#newVertexCollections") { + return "newVertexCollections"; + } else if (a.p === "#s2id_newEdgeDefinitions1") { + return "collection"; + } else if (a.p === "#s2id_fromCollections1") { + return "fromCollection"; + } else if (a.p === "#s2id_toCollections1") { + return "toCollection"; + } + }, + attr : function () { + if (a.p.indexOf("edgeD") !== -1) { + return "1"; + } + }, + toArray: function () { + if (a.p === "[id^=s2id_newEdgeDefinitions]") { + return ["edgeD1", "edgeD2", "edgeD3"]; + } + }, + css : function () { + + }, + 0 : {value : "name"} + }; + + spyOn(_, "pluck").andCallFake(function (s, b) { + if (s === "newVertexCollections") { + return ["orphan1", "orphan2", "orphan3"]; + } else if (s === "collection") { + return [undefined]; + } else if (s === "fromCollection") { + return ["fromCollection"]; + } else if (s === "toCollection") { + return ["toCollection"]; + } + }); + + spyOn(window, "$").andCallFake(function (x) { + a.setParam(x); + return a; + }); + + spyOn(view, "updateGraphManagementView"); + + view.saveEditedGraph(); + + expect(view.updateGraphManagementView).not.toHaveBeenCalled(); + + + + }); + + it("should saveEditedGraph", function () { + + var + a = { + p : "", + setParam : function (p) { + a.p = p; + }, + select2: function () { + if (a.p === "#newVertexCollections") { + return "newVertexCollections"; + } else if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) { + return a.p.split("#s2id_newEdgeDefinitions")[1]; + } else if (a.p.indexOf("#s2id_fromCollections") !== -1) { + return "fromCollection"; + } else if (a.p.indexOf("#s2id_toCollections") !== -1) { + return "toCollection"; + } + }, + attr : function () { + if (a.p.indexOf("edgeD") !== -1) { + return a.p; + } + }, + toArray: function () { + if (a.p === "[id^=s2id_newEdgeDefinitions]") { + return ["edgeD1", "edgeD2", "edgeD3"]; + } + }, + 0 : {value : "name"} + }; + + spyOn(_, "pluck").andCallFake(function (s, b) { + if (s === "newVertexCollections") { + return ["orphan1", "orphan2", "orphan3"]; + } else if (s.indexOf("edgeD") !== -1) { + return ["collection" + s.split("edgeD")[1] ]; + } else if (s === "fromCollection") { + return ["fromCollection"]; + } else if (s === "toCollection") { + return ["toCollection"]; + } + }); + + spyOn(window, "$").andCallFake(function (x) { + a.setParam(x); + return a; + }); + + var g = { + _key: "blub2", + name: "blub2", + edgeDefinitions: [{ + collection: "blub", + from: ["bla"], + to: ["blob"] + },{ + collection: "collection2", + from: ["bla"], + to: ["blob"] + }], + orphanCollections: ["o1", "o2", "o3"], + get : function (a) { + return g[a] + }, + deleteVertexCollection : function (o) { + g.orphanCollections.splice(g.orphanCollections.indexOf(o), 1); + }, + addVertexCollection : function (o) { + g.orphanCollections.push(o); + }, + addEdgeDefinition : function (o) { + g.edgeDefinitions.push(o); + }, + modifyEdgeDefinition : function (o) { + }, + deleteEdgeDefinition : function (o) { + g.edgeDefinitions.forEach(function (e) { + if (e.collection === o.collection) { + delete edgeDefinitions(e); + } + }); + } + }; + + spyOn(view.collection, "findWhere").andReturn( + g ); - },*/ + + spyOn(view, "updateGraphManagementView"); + spyOn(window.modalView, "hide"); + + view.saveEditedGraph(); + + expect(view.updateGraphManagementView).toHaveBeenCalled(); + expect(window.modalView.hide).toHaveBeenCalled(); + + + + }); it("should create a sorted list of all graphs", function () { var list = $("div.tile h5.collectionName", "#graphManagementThumbnailsIn"); @@ -495,6 +720,209 @@ expect($(list[2]).html()).toEqual(g3._key); }); + it("should not saveCreatedGraph as name already exists", function () { + + var + a = { + p : "", + setParam : function (p) { + a.p = p; + }, + select2: function () { + if (a.p === "#newVertexCollections") { + return "newVertexCollections"; + } else if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) { + return a.p.split("#s2id_newEdgeDefinitions")[1]; + } else if (a.p.indexOf("#s2id_fromCollections") !== -1) { + return "fromCollection"; + } else if (a.p.indexOf("#s2id_toCollections") !== -1) { + return "toCollection"; + } + }, + attr : function () { + if (a.p.indexOf("edgeD") !== -1) { + return a.p; + } + }, + toArray: function () { + if (a.p === "[id^=s2id_newEdgeDefinitions]") { + return ["edgeD1", "edgeD2", "edgeD3"]; + } + }, + val : function () { + return "name"; + } + }; + + spyOn(_, "pluck").andCallFake(function (s, b) { + if (s === "newVertexCollections") { + return ["orphan1", "orphan2", "orphan3"]; + } else if (s.indexOf("edgeD") !== -1) { + return ["collection" + s.split("edgeD")[1] ]; + } else if (s === "fromCollection") { + return ["fromCollection"]; + } else if (s === "toCollection") { + return ["toCollection"]; + } + }); + + spyOn(window, "$").andCallFake(function (x) { + a.setParam(x); + return a; + }); + + var g = { + _key: "name", + name: "name", + edgeDefinitions: [{ + collection: "blub", + from: ["bla"], + to: ["blob"] + },{ + collection: "collection2", + from: ["bla"], + to: ["blob"] + }], + orphanCollections: ["o1", "o2", "o3"], + get : function (a) { + return g[a] + }, + deleteVertexCollection : function (o) { + g.orphanCollections.splice(g.orphanCollections.indexOf(o), 1); + }, + addVertexCollection : function (o) { + g.orphanCollections.push(o); + }, + addEdgeDefinition : function (o) { + g.edgeDefinitions.push(o); + }, + modifyEdgeDefinition : function (o) { + }, + deleteEdgeDefinition : function (o) { + g.edgeDefinitions.forEach(function (e) { + if (e.collection === o.collection) { + delete edgeDefinitions(e); + } + }); + } + }; + + spyOn(view.collection, "findWhere").andReturn( + g + ); + + spyOn(arangoHelper, "arangoError"); + + view.createNewGraph(); + + expect(arangoHelper.arangoError).toHaveBeenCalledWith("The graph '" + "name" + "' already exists."); + + + + }); + + + it("should not saveCreatedGraph as name is missing", function () { + + var + a = { + p : "", + setParam : function (p) { + a.p = p; + }, + select2: function () { + if (a.p === "#newVertexCollections") { + return "newVertexCollections"; + } else if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) { + return a.p.split("#s2id_newEdgeDefinitions")[1]; + } else if (a.p.indexOf("#s2id_fromCollections") !== -1) { + return "fromCollection"; + } else if (a.p.indexOf("#s2id_toCollections") !== -1) { + return "toCollection"; + } + }, + attr : function () { + if (a.p.indexOf("edgeD") !== -1) { + return a.p; + } + }, + toArray: function () { + if (a.p === "[id^=s2id_newEdgeDefinitions]") { + return ["edgeD1", "edgeD2", "edgeD3"]; + } + }, + val : function () { + return undefined; + } + }; + + spyOn(_, "pluck").andCallFake(function (s, b) { + if (s === "newVertexCollections") { + return ["orphan1", "orphan2", "orphan3"]; + } else if (s.indexOf("edgeD") !== -1) { + return ["collection" + s.split("edgeD")[1] ]; + } else if (s === "fromCollection") { + return ["fromCollection"]; + } else if (s === "toCollection") { + return ["toCollection"]; + } + }); + + spyOn(window, "$").andCallFake(function (x) { + a.setParam(x); + return a; + }); + + var g = { + _key: "name", + name: "name", + edgeDefinitions: [{ + collection: "blub", + from: ["bla"], + to: ["blob"] + },{ + collection: "collection2", + from: ["bla"], + to: ["blob"] + }], + orphanCollections: ["o1", "o2", "o3"], + get : function (a) { + return g[a] + }, + deleteVertexCollection : function (o) { + g.orphanCollections.splice(g.orphanCollections.indexOf(o), 1); + }, + addVertexCollection : function (o) { + g.orphanCollections.push(o); + }, + addEdgeDefinition : function (o) { + g.edgeDefinitions.push(o); + }, + modifyEdgeDefinition : function (o) { + }, + deleteEdgeDefinition : function (o) { + g.edgeDefinitions.forEach(function (e) { + if (e.collection === o.collection) { + delete edgeDefinitions(e); + } + }); + } + }; + + spyOn(view.collection, "findWhere").andReturn( + g + ); + + spyOn(arangoHelper, "arangoError"); + + view.createNewGraph(); + + expect(arangoHelper.arangoError).toHaveBeenCalledWith("A name for the graph has to be provided."); + + + + }); + describe("creating a new graph", function () { it("should create a new empty graph", function () { From 320b65033339df36c87dfd0e563d84177f445b4d Mon Sep 17 00:00:00 2001 From: scottashton Date: Mon, 30 Jun 2014 15:12:42 +0200 Subject: [PATCH 2/2] jslinted tests --- .../specs/views/graphManagementViewSpec.js | 253 ++++++++++-------- 1 file changed, 136 insertions(+), 117 deletions(-) diff --git a/js/apps/system/aardvark/test/specs/views/graphManagementViewSpec.js b/js/apps/system/aardvark/test/specs/views/graphManagementViewSpec.js index ed3849035a..8c31db16eb 100644 --- a/js/apps/system/aardvark/test/specs/views/graphManagementViewSpec.js +++ b/js/apps/system/aardvark/test/specs/views/graphManagementViewSpec.js @@ -1,6 +1,6 @@ /*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/ /*global describe, beforeEach, afterEach, it, */ -/*global spyOn, runs, expect, waitsFor*/ +/*global spyOn, runs, expect, waitsFor, arangoHelper*/ /*global GraphManagementView, _, jasmine, $*/ (function () { @@ -128,7 +128,7 @@ return "blabalblub"; }, width : function () { - return 100 + return 100; }, html : function () { @@ -225,8 +225,8 @@ to: ["blob"] }], orphanCollections: [] - }); - var e = { + }), + e = { currentTarget: { id: "blabalblub" }, @@ -276,8 +276,7 @@ to: ["blob"] }], orphanCollections: [] - }); - var e = { + }), e = { currentTarget: { id: "blabalblub" }, @@ -315,7 +314,8 @@ }); - it("should not set to and from for added definition as already in use and has been entered manually", function () { + it("should not set to and from for added definition as already in " + + "use and has been entered manually", function () { view.removedECollList = ["moppel"]; var model = view.collection.create({ _key: "blub2", @@ -326,8 +326,7 @@ to: ["blob"] }], orphanCollections: [] - }); - var e = { + }), e = { currentTarget: { id: "blabalblub" }, @@ -365,7 +364,8 @@ }); - it("should not set to and from for removed definition as already in use and has been entered manually", function () { + it("should not set to and from for removed definition as " + + "already in use and has been entered manually", function () { view.removedECollList = ["moppel"]; var model = view.collection.create({ _key: "blub2", @@ -376,8 +376,7 @@ to: ["blob"] }], orphanCollections: [] - }); - var e = { + }), e = { currentTarget: { id: "blabalblub" }, @@ -406,8 +405,8 @@ view.setFromAndTo(e); expect(e.stopPropagation).toHaveBeenCalled(); - expect(view.removedECollList.indexOf("moppel")).toEqual(-1) - expect(view.eCollList.indexOf("moppel")).not.toEqual(-1) + expect(view.removedECollList.indexOf("moppel")).toEqual(-1); + expect(view.eCollList.indexOf("moppel")).not.toEqual(-1); model.destroy(); @@ -429,14 +428,16 @@ spyOn(window.modalView, "show"); - view.options.collectionCollection.add({name : "NONSYSTEM", isSystem : false, type : "edge"}); - view.options.collectionCollection.add({name : "SYSTEM", isSystem : true, type : 'document'}); + view.options.collectionCollection.add( + {name : "NONSYSTEM", isSystem : false, type : "edge"}); + view.options.collectionCollection.add( + {name : "SYSTEM", isSystem : true, type : 'document'}); view.editGraph(e); expect(e.stopPropagation).toHaveBeenCalled(); - expect(view.removedECollList.length).toEqual(0) - expect(view.eCollList.length).not.toEqual(0) + expect(view.removedECollList.length).toEqual(0); + expect(view.eCollList.length).not.toEqual(0); expect(window.modalView.show).toHaveBeenCalled(); @@ -457,9 +458,7 @@ 0 : {setSelectionRange: function () { return ""; }} - }; - - var g = { + }, g = { _key: "blub2", name: "blub2", edgeDefinitions: [{ @@ -473,7 +472,7 @@ }], orphanCollections: [], get : function (a) { - return g[a] + return g[a]; } }; @@ -513,15 +512,9 @@ }], orphanCollections: [], get : function (a) { - return g[a] + return g[a]; } - }; - - spyOn(view.collection, "findWhere").andReturn( - g - ); - - var e = { + }, e = { currentTarget: { id: "blabalblub" }, @@ -530,18 +523,24 @@ removed : {id : "moppel"} }; + spyOn(view.collection, "findWhere").andReturn( + g + ); + spyOn(e, "stopPropagation"); spyOn(window.modalView, "show"); - view.options.collectionCollection.add({name : "NONSYSTEM", isSystem : false, type : "edge"}); - view.options.collectionCollection.add({name : "SYSTEM", isSystem : true, type : 'document'}); + view.options.collectionCollection.add( + {name : "NONSYSTEM", isSystem : false, type : "edge"}); + view.options.collectionCollection.add( + {name : "SYSTEM", isSystem : true, type : 'document'}); view.editGraph(e); expect(e.stopPropagation).toHaveBeenCalled(); - expect(view.removedECollList.length).toEqual(1) - expect(view.eCollList.length).toEqual(0) + expect(view.removedECollList.length).toEqual(1); + expect(view.eCollList.length).toEqual(0); expect(window.modalView.show).toHaveBeenCalled(); @@ -559,11 +558,14 @@ select2: function () { if (a.p === "#newVertexCollections") { return "newVertexCollections"; - } else if (a.p === "#s2id_newEdgeDefinitions1") { + } + if (a.p === "#s2id_newEdgeDefinitions1") { return "collection"; - } else if (a.p === "#s2id_fromCollections1") { + } + if (a.p === "#s2id_fromCollections1") { return "fromCollection"; - } else if (a.p === "#s2id_toCollections1") { + } + if (a.p === "#s2id_toCollections1") { return "toCollection"; } }, @@ -586,11 +588,14 @@ spyOn(_, "pluck").andCallFake(function (s, b) { if (s === "newVertexCollections") { return ["orphan1", "orphan2", "orphan3"]; - } else if (s === "collection") { + } + if (s === "collection") { return [undefined]; - } else if (s === "fromCollection") { + } + if (s === "fromCollection") { return ["fromCollection"]; - } else if (s === "toCollection") { + } + if (s === "toCollection") { return ["toCollection"]; } }); @@ -621,11 +626,14 @@ select2: function () { if (a.p === "#newVertexCollections") { return "newVertexCollections"; - } else if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) { + } + if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) { return a.p.split("#s2id_newEdgeDefinitions")[1]; - } else if (a.p.indexOf("#s2id_fromCollections") !== -1) { + } + if (a.p.indexOf("#s2id_fromCollections") !== -1) { return "fromCollection"; - } else if (a.p.indexOf("#s2id_toCollections") !== -1) { + } + if (a.p.indexOf("#s2id_toCollections") !== -1) { return "toCollection"; } }, @@ -640,26 +648,7 @@ } }, 0 : {value : "name"} - }; - - spyOn(_, "pluck").andCallFake(function (s, b) { - if (s === "newVertexCollections") { - return ["orphan1", "orphan2", "orphan3"]; - } else if (s.indexOf("edgeD") !== -1) { - return ["collection" + s.split("edgeD")[1] ]; - } else if (s === "fromCollection") { - return ["fromCollection"]; - } else if (s === "toCollection") { - return ["toCollection"]; - } - }); - - spyOn(window, "$").andCallFake(function (x) { - a.setParam(x); - return a; - }); - - var g = { + }, g = { _key: "blub2", name: "blub2", edgeDefinitions: [{ @@ -673,7 +662,7 @@ }], orphanCollections: ["o1", "o2", "o3"], get : function (a) { - return g[a] + return g[a]; }, deleteVertexCollection : function (o) { g.orphanCollections.splice(g.orphanCollections.indexOf(o), 1); @@ -689,12 +678,31 @@ deleteEdgeDefinition : function (o) { g.edgeDefinitions.forEach(function (e) { if (e.collection === o.collection) { - delete edgeDefinitions(e); + delete g.edgeDefinitions[e]; } }); } }; + spyOn(_, "pluck").andCallFake(function (s, b) { + if (s === "newVertexCollections") { + return ["orphan1", "orphan2", "orphan3"]; + } + if (s.indexOf("edgeD") !== -1) { + return ["collection" + s.split("edgeD")[1] ]; + } + if (s === "fromCollection") { + return ["fromCollection"]; + } + if (s === "toCollection") { + return ["toCollection"]; + } + }); + + spyOn(window, "$").andCallFake(function (x) { + a.setParam(x); + return a; + }); spyOn(view.collection, "findWhere").andReturn( g ); @@ -731,11 +739,14 @@ select2: function () { if (a.p === "#newVertexCollections") { return "newVertexCollections"; - } else if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) { + } + if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) { return a.p.split("#s2id_newEdgeDefinitions")[1]; - } else if (a.p.indexOf("#s2id_fromCollections") !== -1) { + } + if (a.p.indexOf("#s2id_fromCollections") !== -1) { return "fromCollection"; - } else if (a.p.indexOf("#s2id_toCollections") !== -1) { + } + if (a.p.indexOf("#s2id_toCollections") !== -1) { return "toCollection"; } }, @@ -752,26 +763,7 @@ val : function () { return "name"; } - }; - - spyOn(_, "pluck").andCallFake(function (s, b) { - if (s === "newVertexCollections") { - return ["orphan1", "orphan2", "orphan3"]; - } else if (s.indexOf("edgeD") !== -1) { - return ["collection" + s.split("edgeD")[1] ]; - } else if (s === "fromCollection") { - return ["fromCollection"]; - } else if (s === "toCollection") { - return ["toCollection"]; - } - }); - - spyOn(window, "$").andCallFake(function (x) { - a.setParam(x); - return a; - }); - - var g = { + }, g = { _key: "name", name: "name", edgeDefinitions: [{ @@ -785,7 +777,7 @@ }], orphanCollections: ["o1", "o2", "o3"], get : function (a) { - return g[a] + return g[a]; }, deleteVertexCollection : function (o) { g.orphanCollections.splice(g.orphanCollections.indexOf(o), 1); @@ -801,12 +793,32 @@ deleteEdgeDefinition : function (o) { g.edgeDefinitions.forEach(function (e) { if (e.collection === o.collection) { - delete edgeDefinitions(e); + delete g.edgeDefinitions[e]; } }); } }; + spyOn(_, "pluck").andCallFake(function (s, b) { + if (s === "newVertexCollections") { + return ["orphan1", "orphan2", "orphan3"]; + } + if (s.indexOf("edgeD") !== -1) { + return ["collection" + s.split("edgeD")[1] ]; + } + if (s === "fromCollection") { + return ["fromCollection"]; + } + if (s === "toCollection") { + return ["toCollection"]; + } + }); + + spyOn(window, "$").andCallFake(function (x) { + a.setParam(x); + return a; + }); + spyOn(view.collection, "findWhere").andReturn( g ); @@ -815,7 +827,8 @@ view.createNewGraph(); - expect(arangoHelper.arangoError).toHaveBeenCalledWith("The graph '" + "name" + "' already exists."); + expect(arangoHelper.arangoError).toHaveBeenCalledWith( + "The graph '" + "name" + "' already exists."); @@ -833,11 +846,14 @@ select2: function () { if (a.p === "#newVertexCollections") { return "newVertexCollections"; - } else if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) { + } + if (a.p.indexOf("#s2id_newEdgeDefinitions") !== -1) { return a.p.split("#s2id_newEdgeDefinitions")[1]; - } else if (a.p.indexOf("#s2id_fromCollections") !== -1) { + } + if (a.p.indexOf("#s2id_fromCollections") !== -1) { return "fromCollection"; - } else if (a.p.indexOf("#s2id_toCollections") !== -1) { + } + if (a.p.indexOf("#s2id_toCollections") !== -1) { return "toCollection"; } }, @@ -854,26 +870,7 @@ val : function () { return undefined; } - }; - - spyOn(_, "pluck").andCallFake(function (s, b) { - if (s === "newVertexCollections") { - return ["orphan1", "orphan2", "orphan3"]; - } else if (s.indexOf("edgeD") !== -1) { - return ["collection" + s.split("edgeD")[1] ]; - } else if (s === "fromCollection") { - return ["fromCollection"]; - } else if (s === "toCollection") { - return ["toCollection"]; - } - }); - - spyOn(window, "$").andCallFake(function (x) { - a.setParam(x); - return a; - }); - - var g = { + }, g = { _key: "name", name: "name", edgeDefinitions: [{ @@ -887,7 +884,7 @@ }], orphanCollections: ["o1", "o2", "o3"], get : function (a) { - return g[a] + return g[a]; }, deleteVertexCollection : function (o) { g.orphanCollections.splice(g.orphanCollections.indexOf(o), 1); @@ -903,12 +900,33 @@ deleteEdgeDefinition : function (o) { g.edgeDefinitions.forEach(function (e) { if (e.collection === o.collection) { - delete edgeDefinitions(e); + delete g.edgeDefinitions[e]; } }); } }; + spyOn(_, "pluck").andCallFake(function (s, b) { + if (s === "newVertexCollections") { + return ["orphan1", "orphan2", "orphan3"]; + } + if (s.indexOf("edgeD") !== -1) { + return ["collection" + s.split("edgeD")[1] ]; + } + if (s === "fromCollection") { + return ["fromCollection"]; + } + if (s === "toCollection") { + return ["toCollection"]; + } + }); + + spyOn(window, "$").andCallFake(function (x) { + a.setParam(x); + return a; + }); + + spyOn(view.collection, "findWhere").andReturn( g ); @@ -917,7 +935,8 @@ view.createNewGraph(); - expect(arangoHelper.arangoError).toHaveBeenCalledWith("A name for the graph has to be provided."); + expect(arangoHelper.arangoError).toHaveBeenCalledWith( + "A name for the graph has to be provided.");