jsPlumb-1.3.3-tests.js 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  1. var _getContextNode = function() {
  2. return $("#container");
  3. };
  4. var assertContextExists = function() {
  5. ok(_getContextNode().length == 1, "context node exists");
  6. };
  7. var assertContextSize = function(elementCount) {
  8. //equals(_getContextNode().children().length - _divs.length, elementCount, 'context has ' + elementCount + ' children');
  9. };
  10. var assertContextEmpty = function() {
  11. equals(_getContextNode().children.length, 0, "context empty");
  12. };
  13. var assertEndpointCount = function(elId, count) {
  14. equals(jsPlumb.getTestHarness().endpointCount(elId), count, elId + " has " + count + (count > 1) ? "endpoints" : "endpoint");
  15. };
  16. var assertConnectionCount = function(endpoint, count) {
  17. equals(endpoint.connections.length, count, "endpoint has " + count + " connections");
  18. };
  19. var assertConnectionByScopeCount = function(scope, count) {
  20. equals(jsPlumb.getTestHarness().connectionCount(scope), count, 'Scope ' + scope + " has " + count + (count > 1) ? "connections" : "connection");
  21. };
  22. var _divs = [];
  23. var _addDiv = function(id) {
  24. var d1 = document.createElement("div");
  25. _getContextNode().append(d1);
  26. d1 = jsPlumb.CurrentLibrary.getElementObject(d1);
  27. jsPlumb.CurrentLibrary.setAttribute(d1, "id", id);
  28. _divs.push(id);
  29. return d1;
  30. };
  31. var _cleanup = function() {
  32. jsPlumb.reset();
  33. jsPlumb.Defaults.Container = null;
  34. for (var i in _divs) {
  35. $("#" + _divs[i]).remove();
  36. }
  37. _divs.splice(0, _divs.length - 1);
  38. };
  39. var testSuite = function(renderMode) {
  40. module("jsPlumb", {teardown: _cleanup});
  41. // setup the container
  42. var container = document.createElement("div");
  43. container.id = "container";
  44. document.body.appendChild(container);
  45. jsPlumb.setRenderMode(renderMode);
  46. test(renderMode + ': findIndex method', function() {
  47. var array = [ 1,2,3, "test", "a string", { 'foo':'bar', 'baz':1 }, { 'ding':'dong' } ];
  48. equals(jsPlumb.getTestHarness().findIndex(array, 1), 0, "find works for integers");
  49. equals(jsPlumb.getTestHarness().findIndex(array, "test"), 3, "find works for strings");
  50. equals(jsPlumb.getTestHarness().findIndex(array, { 'foo':'bar', 'baz':1 }), 5, "find works for objects");
  51. equals(jsPlumb.getTestHarness().findIndex(array, { 'ding':'dong', 'baz':1 }), -1, "find works properly for objects (objects have different length but some same properties)");
  52. });
  53. test(renderMode + ': jsPlumb setup', function() {
  54. ok(jsPlumb, "loaded");
  55. });
  56. test(renderMode + ': getId', function() {
  57. var d10 = _addDiv('d10');
  58. equals(jsPlumb.getTestHarness().getId(d10), "d10");
  59. });
  60. test(renderMode + ': create a simple endpoint', function() {
  61. var d1 = _addDiv("d1");
  62. var e = jsPlumb.addEndpoint($("#d1"), {});
  63. ok(e, 'endpoint exists');
  64. assertEndpointCount("d1", 1);
  65. });
  66. test(renderMode + ': create and remove a simple endpoint', function() {
  67. var d1 = _addDiv("d1");
  68. var ee = jsPlumb.addEndpoint(d1, {uuid:"78978597593"});
  69. ok(ee != null, "endpoint exists");
  70. var e = jsPlumb.getEndpoint("78978597593");
  71. ok(e != null, "the endpoint could be retrieved by UUID");
  72. assertEndpointCount("d1", 1);
  73. assertContextSize(1); // one Endpoint canvas.
  74. jsPlumb.removeEndpoint(d1, ee);
  75. assertEndpointCount("d1", 0);
  76. e = jsPlumb.getEndpoint("78978597593");
  77. equals(e, null, "the endpoint has been deleted");
  78. assertContextSize(0); // no Endpoint canvases.
  79. });
  80. test(renderMode + ': create two simple endpoints, registered using a selector', function() {
  81. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  82. d1.addClass("window");d2.addClass("window");
  83. var endpoints = jsPlumb.addEndpoint($(".window"), {});
  84. equals(endpoints.length, 2, "endpoint added to both windows");
  85. assertEndpointCount("d1", 1);
  86. assertEndpointCount("d2", 1);
  87. });
  88. test(renderMode + ': create two simple endpoints, registered using an array of element ids', function() {
  89. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  90. d1.addClass("window");d2.addClass("window");
  91. var endpoints = jsPlumb.addEndpoint(["d1", "d2"], {});
  92. equals(endpoints.length, 2, "endpoint added to both windows");
  93. assertEndpointCount("d1", 1);
  94. assertEndpointCount("d2", 1);
  95. });
  96. test(renderMode + ': draggable silently ignored when jquery ui not present', function() {
  97. var d1 = _addDiv("d1");
  98. var e = jsPlumb.addEndpoint(d1, {isSource:true});
  99. ok(e, 'endpoint exists');
  100. });
  101. test(renderMode + ': droppable silently ignored when jquery ui not present', function() {
  102. var d1 = _addDiv("d1")
  103. var e = jsPlumb.addEndpoint(d1, {isTarget:true});
  104. ok(e, 'endpoint exists');
  105. });
  106. test(renderMode + ': defaultEndpointMaxConnections', function() {
  107. var d3 = _addDiv("d3"), d4 = _addDiv("d4");
  108. var e3 = jsPlumb.addEndpoint(d3, {isSource:true});
  109. ok(e3.anchor, 'endpoint 3 has an anchor');
  110. var e4 = jsPlumb.addEndpoint(d4, {isSource:true});
  111. assertEndpointCount("d3", 1);
  112. assertEndpointCount("d4", 1);
  113. assertContextSize(2); // one canvas for each of our two endpoints.
  114. ok(!e3.isFull(), "endpoint 3 is not full.");
  115. jsPlumb.connect({source:d3, target:'d4', sourceEndpoint:e3, targetEndpoint:e4});
  116. assertConnectionCount(e3, 1); // we have one connection
  117. jsPlumb.connect({source:d3, target:'d4', sourceEndpoint:e3, targetEndpoint:e4});
  118. assertConnectionCount(e3, 1); // should have refused the connection; default max is 1.
  119. assertContextSize(3); // now we have one more canvas, for the Connection that was accepted.
  120. });
  121. test(renderMode + ': specifiedEndpointMaxConnections', function() {
  122. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  123. var e5 = jsPlumb.addEndpoint(d5, {isSource:true, maxConnections:3});
  124. ok(e5.anchor, 'endpoint 5 has an anchor');
  125. var e6 = jsPlumb.addEndpoint(d6, {isSource:true, maxConnections:2}); // this one has max TWO
  126. assertEndpointCount("d5", 1); assertEndpointCount("d6", 1);
  127. assertContextSize(2);
  128. ok(!e5.isFull(), "endpoint 5 is not full.");
  129. jsPlumb.connect({sourceEndpoint:e5, targetEndpoint:e6});
  130. assertConnectionCount(e5, 1); // we have one connection
  131. assertContextSize(3);
  132. jsPlumb.connect({sourceEndpoint:e5, targetEndpoint:e6});
  133. assertConnectionCount(e5, 2); // two connections
  134. assertContextSize(4);
  135. jsPlumb.connect({sourceEndpoint:e5, targetEndpoint:e6});
  136. assertConnectionCount(e5, 2); // should have refused; max is 2, for d4.
  137. assertContextSize(4);
  138. });
  139. test(renderMode + ': noEndpointMaxConnections', function() {
  140. var d3 = _addDiv("d3"), d4 = _addDiv("d4");
  141. var e3 = jsPlumb.addEndpoint(d3, {isSource:true, maxConnections:-1});
  142. var e4 = jsPlumb.addEndpoint(d4, {isSource:true, maxConnections:-1});
  143. jsPlumb.connect({sourceEndpoint:e3, targetEndpoint:e4});
  144. assertContextSize(3);
  145. assertConnectionCount(e3, 1); // we have one connection
  146. jsPlumb.connect({sourceEndpoint:e3, targetEndpoint:e4});
  147. assertConnectionCount(e3, 2); // we have two. etc (default was one. this proves max is working).
  148. assertContextSize(4);
  149. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  150. var e5 = jsPlumb.addEndpoint(d3, {isSource:true, maxConnections:-1});
  151. jsPlumb.connect({sourceEndpoint:e5, targetEndpoint:e4});
  152. assertConnectionCount(e4, 3);
  153. assertContextSize(6);
  154. });
  155. test(renderMode + ': anchors equal', function() {
  156. var a1 = jsPlumb.makeAnchor(0, 1, 1, 1);
  157. var a2 = jsPlumb.makeAnchor(0, 1, 1, 1);
  158. ok(a1.equals(a2), "anchors are the same");
  159. });
  160. test(renderMode + ': anchors equal with offsets', function() {
  161. var a1 = jsPlumb.makeAnchor(0, 1, 1, 1, 10, 13);
  162. var a2 = jsPlumb.makeAnchor(0, 1, 1, 1, 10, 13);
  163. ok(a1.equals(a2), "anchors are the same");
  164. });
  165. test(renderMode + ': anchors not equal', function() {
  166. var a1 = jsPlumb.makeAnchor(0, 1, 0, 1);
  167. var a2 = jsPlumb.makeAnchor(0, 1, 1, 1);
  168. ok(!a1.equals(a2), "anchors are different");
  169. });
  170. test(renderMode + ': anchor not equal with offsets', function() {
  171. var a1 = jsPlumb.makeAnchor(0, 1, 1, 1, 10, 13);
  172. var a2 = jsPlumb.makeAnchor(0, 1, 1, 1);
  173. ok(!a1.equals(a2), "anchors are different");
  174. });
  175. test(renderMode + ': detach plays nice when no target given', function() {
  176. var d3 = _addDiv("d3"), d4 = _addDiv("d4");
  177. jsPlumb.connect({source:d3, target:d4});
  178. jsPlumb.detach();
  179. });
  180. // issue 81
  181. test(renderMode + ': jsPlumb.detach should fire only one detach event (pass Connection as argument)', function() {
  182. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  183. var conn = jsPlumb.connect({source:d5, target:d6});
  184. var eventCount = 0;
  185. jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  186. jsPlumb.detach(conn);
  187. equals(eventCount, 1);
  188. });
  189. // issue 81
  190. test(renderMode + ': jsPlumb.detach should fire only one detach event (pass Connection as param in argument)', function() {
  191. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  192. var conn = jsPlumb.connect({source:d5, target:d6});
  193. var eventCount = 0;
  194. jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  195. jsPlumb.detach({connection:conn});
  196. equals(eventCount, 1);
  197. });
  198. // issue 81
  199. test(renderMode + ': jsPlumb.detach should fire only one detach event (pass source and targets as strings as arguments in params object)', function() {
  200. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  201. var conn = jsPlumb.connect({source:d5, target:d6});
  202. var eventCount = 0;
  203. jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  204. jsPlumb.detach({source:"d5", target:"d6"});
  205. equals(eventCount, 1);
  206. });
  207. // issue 81
  208. test(renderMode + ': jsPlumb.detach should fire only one detach event (pass source and targets as divs as arguments in params object)', function() {
  209. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  210. var conn = jsPlumb.connect({source:d5, target:d6});
  211. var eventCount = 0;
  212. jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  213. jsPlumb.detach({source:d5, target:d6});
  214. equals(eventCount, 1);
  215. });
  216. // issue 81
  217. test(renderMode + ': jsPlumb.detach should fire only one detach event (pass source and targets as divs as arguments)', function() {
  218. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  219. var conn = jsPlumb.connect({source:d5, target:d6});
  220. var eventCount = 0;
  221. jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  222. jsPlumb.detach(d5, d6);
  223. equals(eventCount, 1);
  224. });
  225. //TODO make sure you run this test with a single detach call, to ensure that
  226. // single detach calls result in the connection being removed. detachEverything can
  227. // just blow away the connectionsByScope array and recreate it.
  228. test(renderMode + ': jsPlumb.getConnections (simple case, default scope)', function() {
  229. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  230. jsPlumb.connect({source:d5, target:d6});
  231. assertContextSize(3);
  232. var c = jsPlumb.getConnections(); // will get all connections in the default scope.
  233. equals(c.length, 1, "there is one connection");
  234. });
  235. test(renderMode + ': jsPlumb.getConnections (simple case, default scope; detach by element id)', function() {
  236. var d5 = _addDiv("d5"), d6 = _addDiv("d6"), d7 = _addDiv("d7");
  237. jsPlumb.connect({source:d5, target:d6});
  238. jsPlumb.connect({source:d6, target:d7});
  239. assertContextSize(6);
  240. var c = jsPlumb.getConnections(); // will get all connections in the default scope
  241. equals(c.length, 2, "there are two connections initially");
  242. jsPlumb.detach('d5', 'd6');
  243. c = jsPlumb.getConnections(); // will get all connections
  244. equals(c.length, 1, "after detaching one, there is now one connection.");
  245. assertContextSize(5);
  246. });
  247. test(renderMode + ': jsPlumb.getConnections (simple case, default scope; detach by element id using params object)', function() {
  248. var d5 = _addDiv("d5"), d6 = _addDiv("d6"), d7 = _addDiv("d7");
  249. jsPlumb.connect({source:d5, target:d6});
  250. jsPlumb.connect({source:d6, target:d7});
  251. assertContextSize(6);
  252. var c = jsPlumb.getConnections(); // will get all connections
  253. equals(c.length, 2, "there are two connections initially");
  254. jsPlumb.detach({source:'d5', target:'d6'});
  255. c = jsPlumb.getConnections(); // will get all connections
  256. equals(c.length, 1, "after detaching one, there is now one connection.");
  257. assertContextSize(5);
  258. });
  259. test(renderMode + ': jsPlumb.getConnections (simple case, default scope; detach by element object)', function() {
  260. var d5 = _addDiv("d5"), d6 = _addDiv("d6"), d7 = _addDiv("d7");
  261. jsPlumb.connect({source:d5, target:d6});
  262. jsPlumb.connect({source:d6, target:d7});
  263. assertContextSize(6);
  264. var c = jsPlumb.getConnections(); // will get all connections
  265. equals(c.length, 2, "there are two connections initially");
  266. jsPlumb.detach(d5, d6);
  267. c = jsPlumb.getConnections(); // will get all connections
  268. equals(c.length, 1, "after detaching one, there is now one connection.");
  269. assertContextSize(5);
  270. });
  271. test(renderMode + ': jsPlumb.getConnections (simple case, default scope; detach by element object using params object)', function() {
  272. var d5 = _addDiv("d5"), d6 = _addDiv("d6"), d7 = _addDiv("d7");
  273. jsPlumb.connect({source:d5, target:d6});
  274. jsPlumb.connect({source:d6, target:d7});
  275. assertContextSize(6);
  276. var c = jsPlumb.getConnections(); // will get all connections
  277. equals(c.length, 2, "there are two connections initially");
  278. jsPlumb.detach({source:d5, target:d6});
  279. c = jsPlumb.getConnections(); // will get all connections
  280. equals(c.length, 1, "after detaching one, there is now one connection.");
  281. assertContextSize(5);
  282. });
  283. test(renderMode + ': jsPlumb.getConnections (simple case, default scope; detach by Connection)', function() {
  284. var d5 = _addDiv("d5"), d6 = _addDiv("d6"), d7 = _addDiv("d7");
  285. var c56 = jsPlumb.connect({source:d5, target:d6});
  286. var c67 = jsPlumb.connect({source:d6, target:d7});
  287. assertContextSize(6);
  288. var c = jsPlumb.getConnections(); // will get all connections
  289. equals(c.length, 2, "there are two connections initially");
  290. jsPlumb.detach(c56);
  291. assertContextSize(5); // check that the connection canvas was removed.
  292. c = jsPlumb.getConnections(); // will get all connections
  293. equals(c.length, 1, "after detaching one, there is now one connection.");
  294. });
  295. test(renderMode + ': jsPlumb.getConnections (scope testScope)', function() {
  296. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  297. jsPlumb.connect({source:d5, target:d6, scope:'testScope'});
  298. var c = jsPlumb.getConnections("testScope"); // will get all connections in testScope
  299. equals(c.length, 1, "there is one connection");
  300. equals(c[0].sourceId, 'd5', "the connection's source is d5");
  301. equals(c[0].targetId, 'd6', "the connection's source is d6");
  302. c = jsPlumb.getConnections(); // will get all connections in default scope; should be none.
  303. equals(c.length, 0, "there are no connections in the default scope");
  304. });
  305. test(renderMode + ': jsPlumb.getAllConnections (filtered by scope)', function() {
  306. var d8 = _addDiv("d8"), d9 = _addDiv("d9"), d10 = _addDiv('d10');
  307. jsPlumb.connect({source:d8, target:d9, scope:'testScope'});
  308. jsPlumb.connect({source:d9, target:d10}); // default scope
  309. var c = jsPlumb.getAllConnections(); // will get all connections
  310. equals(c[jsPlumb.getDefaultScope()].length, 1);
  311. equals(c['testScope'].length, 1);
  312. // now supply a list of scopes
  313. c = jsPlumb.getConnections();
  314. equals(c.length, 1);
  315. c = jsPlumb.getConnections("testScope");
  316. equals(c.length, 1, "there is one connection in 'testScope'");
  317. });
  318. test(renderMode + ': jsPlumb.getConnections (filtered by scope and sourceId)', function() {
  319. var d8 = _addDiv("d8"), d9 = _addDiv("d9"), d10 = _addDiv('d10');
  320. jsPlumb.connect({source:d8, target:d9, scope:'testScope'});
  321. jsPlumb.connect({source:d9, target:d8, scope:'testScope'});
  322. jsPlumb.connect({source:d9, target:d10}); // default scope
  323. var c = jsPlumb.getConnections({scope:'testScope', source:'d8'}); // will get all connections with sourceId 'd8'
  324. equals(c.length, 1, "there is one connection in 'testScope' from d8");
  325. });
  326. test(renderMode + ': jsPlumb.getConnections (filtered by scope, source id and target id)', function() {
  327. var d11 = _addDiv("d11"), d12 = _addDiv("d12"), d13 = _addDiv('d13');
  328. jsPlumb.connect({source:d11, target:d12, scope:'testScope'});
  329. jsPlumb.connect({source:d12, target:d13, scope:'testScope'});
  330. jsPlumb.connect({source:d11, target:d13, scope:'testScope'});
  331. var c = jsPlumb.getConnections({scope:'testScope', source:'d11', target:'d13'});
  332. equals(c.length, 1, "there is one connection from d11 to d13");
  333. });
  334. test(renderMode + ': jsPlumb.getConnections (filtered by a list of scopes)', function() {
  335. var d11 = _addDiv("d11"), d12 = _addDiv("d12"), d13 = _addDiv('d13');
  336. jsPlumb.connect({source:d11, target:d12, scope:'testScope'});
  337. jsPlumb.connect({source:d12, target:d13, scope:'testScope2'});
  338. jsPlumb.connect({source:d11, target:d13, scope:'testScope3'});
  339. var c = jsPlumb.getConnections({scope:['testScope','testScope3']});
  340. equals(c['testScope'].length, 1, 'there is one connection in testScope');
  341. equals(c['testScope3'].length, 1, 'there is one connection in testScope3');
  342. equals(c['testScope2'], null, 'there are no connections in testScope2');
  343. });
  344. test(renderMode + ': jsPlumb.getConnections (filtered by a list of scopes and source ids)', function() {
  345. var d11 = _addDiv("d11"), d12 = _addDiv("d12"), d13 = _addDiv('d13');
  346. jsPlumb.connect({source:d11, target:d12, scope:'testScope'});
  347. jsPlumb.connect({source:d13, target:d12, scope:'testScope'});
  348. jsPlumb.connect({source:d12, target:d13, scope:'testScope2'});
  349. jsPlumb.connect({source:d11, target:d13, scope:'testScope3'});
  350. var c = jsPlumb.getConnections({scope:['testScope','testScope3'], source:['d11']});
  351. equals(c['testScope'].length, 1, 'there is one connection in testScope');
  352. equals(c['testScope3'].length, 1, 'there is one connection in testScope3');
  353. equals(c['testScope2'], null, 'there are no connections in testScope2');
  354. });
  355. test(renderMode + ': jsPlumb.getConnections (filtered by a list of scopes, source ids and target ids)', function() {
  356. jsPlumb.detachEverything();
  357. var d11 = _addDiv("d11"), d12 = _addDiv("d12"), d13 = _addDiv('d13'), d14=_addDiv("d14"), d15=_addDiv("d15");
  358. jsPlumb.connect({source:d11, target:d12, scope:'testScope'});
  359. jsPlumb.connect({source:d13, target:d12, scope:'testScope'});
  360. jsPlumb.connect({source:d11, target:d14, scope:'testScope'});
  361. jsPlumb.connect({source:d11, target:d15, scope:'testScope'});
  362. jsPlumb.connect({source:d12, target:d13, scope:'testScope2'});
  363. jsPlumb.connect({source:d11, target:d13, scope:'testScope3'});
  364. assertContextSize(18);
  365. var c = jsPlumb.getConnections({scope:['testScope','testScope3'], source:['d11'], target:['d14', 'd15']});
  366. equals(c['testScope'].length, 2, 'there are two connections in testScope');
  367. equals(c['testScope3'], null, 'there are no connections in testScope3');
  368. equals(c['testScope2'], null, 'there are no connections in testScope2');
  369. var anEntry = c['testScope'][0];
  370. ok(anEntry.endpoints[0] != null, "Source endpoint is set");
  371. ok(anEntry.endpoints[1] != null, "Target endpoint is set");
  372. equals(anEntry.source.attr("id"), "d11", "Source is div d11");
  373. equals(anEntry.target.attr("id"), "d14", "Target is div d14");
  374. });
  375. test(renderMode + ': getEndpoints, one Endpoint added by addEndpoint, get Endpoints by selector', function() {
  376. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  377. jsPlumb.addEndpoint(d1);
  378. var e = jsPlumb.getEndpoints(d1);
  379. equals(e.length, 1, "there is one endpoint for element d1");
  380. });
  381. test(renderMode + ': getEndpoints, one Endpoint added by addEndpoint, get Endpoints by id', function() {
  382. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  383. jsPlumb.addEndpoint(d1);
  384. var e = jsPlumb.getEndpoints("d1");
  385. equals(e.length, 1, "there is one endpoint for element d1");
  386. });
  387. test(renderMode + ': connection event listeners', function() {
  388. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  389. var returnedParams = null/*, returnedParams2 = null*/;
  390. jsPlumb.bind("jsPlumbConnection", function(params) {
  391. returnedParams = $.extend({}, params);
  392. });
  393. var c = jsPlumb.connect({source:d1, target:d2});
  394. ok(returnedParams != null, "new connection listener event was fired");
  395. ok(returnedParams.connection != null, 'connection is set');
  396. equals(returnedParams.sourceId, "d1", 'sourceid is set');
  397. equals(returnedParams.targetId, "d2", 'targetid is set');
  398. equals(returnedParams.source.attr("id"), "d1", 'source is set');
  399. equals(returnedParams.target.attr("id"), "d2" , 'target is set');
  400. ok(returnedParams.sourceEndpoint != null, "source endpoint is not null");
  401. ok(returnedParams.targetEndpoint != null, "target endpoint is not null");
  402. jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  403. returnedParams = $.extend({}, params);
  404. });
  405. jsPlumb.detach(c);
  406. ok(returnedParams.connection != null, 'connection is set');
  407. //jsPlumb.detachAll("d1");
  408. //ok(returnedParams2 != null, "removed connection listener event was fired");
  409. });
  410. test(renderMode + ': detach event listeners (detach by connection)', function() {
  411. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  412. var returnedParams = null;
  413. jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  414. returnedParams = $.extend({}, params);
  415. });
  416. var conn = jsPlumb.connect({source:d1, target:d2});
  417. jsPlumb.detach(conn);
  418. ok(returnedParams != null, "removed connection listener event was fired");
  419. ok(returnedParams.connection != null, "removed connection listener event passed in connection");
  420. });
  421. test(renderMode + ': detach event listeners (detach by element ids)', function() {
  422. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  423. var returnedParams = null;
  424. jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  425. returnedParams = $.extend({}, params);
  426. });
  427. var conn = jsPlumb.connect({source:d1, target:d2});
  428. jsPlumb.detach("d1","d2");
  429. ok(returnedParams != null, "removed connection listener event was fired");
  430. });
  431. test(renderMode + ': detach event listeners (detach by elements)', function() {
  432. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  433. var returnedParams = null;
  434. jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  435. returnedParams = $.extend({}, params);
  436. });
  437. var conn = jsPlumb.connect({source:d1, target:d2});
  438. jsPlumb.detach(d1,d2);
  439. ok(returnedParams != null, "removed connection listener event was fired");
  440. });
  441. test(renderMode + ': detach event listeners (via Endpoint.detach method)', function() {
  442. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  443. var e1 = jsPlumb.addEndpoint(d1, {});
  444. var e2 = jsPlumb.addEndpoint(d2, {});
  445. var returnedParams = null;
  446. jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  447. returnedParams = $.extend({}, params);
  448. });
  449. var conn = jsPlumb.connect({sourceEndpoint:e1, targetEndpoint:e2});
  450. assertContextSize(3);
  451. e1.detach(conn);
  452. ok(returnedParams != null, "removed connection listener event was fired");
  453. assertContextSize(2);
  454. });
  455. test(renderMode + ': detach event listeners (via Endpoint.detachFrom method)', function() {
  456. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  457. var e1 = jsPlumb.addEndpoint(d1, {});
  458. var e2 = jsPlumb.addEndpoint(d2, {});
  459. var returnedParams = null;
  460. jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  461. returnedParams = $.extend({}, params);
  462. });
  463. jsPlumb.connect({sourceEndpoint:e1, targetEndpoint:e2});
  464. assertContextSize(3);
  465. e1.detachFrom(e2);
  466. ok(returnedParams != null, "removed connection listener event was fired");
  467. assertContextSize(2);
  468. });
  469. test(renderMode + ': detach event listeners (via Endpoint.detachAll method)', function() {
  470. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  471. var e1 = jsPlumb.addEndpoint(d1, {});
  472. var e2 = jsPlumb.addEndpoint(d2, {});
  473. var returnedParams = null;
  474. jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  475. returnedParams = $.extend({}, params);
  476. });
  477. jsPlumb.connect({sourceEndpoint:e1, targetEndpoint:e2});
  478. assertContextSize(3);
  479. e1.detachAll();
  480. ok(returnedParams != null, "removed connection listener event was fired");
  481. assertContextSize(2);
  482. });
  483. test(renderMode + ': detach event listeners (via jsPlumb.deleteEndpoint method)', function() {
  484. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  485. var e1 = jsPlumb.addEndpoint(d1, {});
  486. var e2 = jsPlumb.addEndpoint(d2, {});
  487. var returnedParams = null;
  488. jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  489. returnedParams = $.extend({}, params);
  490. });
  491. jsPlumb.connect({sourceEndpoint:e1, targetEndpoint:e2});
  492. assertContextSize(3);
  493. jsPlumb.deleteEndpoint(e1);
  494. ok(returnedParams != null, "removed connection listener event was fired");
  495. assertContextSize(1);
  496. });
  497. test(renderMode + ': detach event listeners (ensure cleared by jsPlumb.reset)', function() {
  498. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  499. var returnedParams = null;
  500. jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  501. returnedParams = $.extend({}, params);
  502. });
  503. var conn = jsPlumb.connect({source:d1, target:d2});
  504. jsPlumb.detach(d1,d2);
  505. ok(returnedParams != null, "removed connection listener event was fired");
  506. returnedParams = null;
  507. jsPlumb.reset();
  508. var conn = jsPlumb.connect({source:d1, target:d2});
  509. jsPlumb.detach(d1,d2);
  510. ok(returnedParams == null, "connection listener was cleared by jsPlumb.reset()");
  511. });
  512. test(renderMode + ': connection events that throw errors', function() {
  513. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  514. var returnedParams = null, returnedParams2 = null;
  515. jsPlumb.bind("jsPlumbConnection", function(params) {
  516. returnedParams = $.extend({}, params);
  517. throw "oh no!";
  518. });
  519. jsPlumb.connect({source:d1, target:d2});
  520. var d3 = _addDiv("d3"), d4 = _addDiv("d4");
  521. jsPlumb.connect({source:d3, target:d4});
  522. ok(returnedParams != null, "new connection listener event was fired; we threw an error, jsPlumb survived.");
  523. });
  524. test(renderMode + ": Endpoint.detachFrom", function() {
  525. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  526. var e16 = jsPlumb.addEndpoint(d16, {isSource:true});
  527. ok(e16.anchor, 'endpoint 16 has an anchor');
  528. var e17 = jsPlumb.addEndpoint(d17, {isSource:true});
  529. var conn = jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  530. assertConnectionCount(e16, 1);
  531. assertConnectionCount(e17, 1);
  532. assertContextSize(3);
  533. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  534. e16.detachFrom(e17);
  535. assertContextSize(2); // the endpoint canvases should remain
  536. // but the connection should be gone, meaning not registered by jsPlumb and not registered on either Endpoint:
  537. assertConnectionCount(e16, 0);
  538. assertConnectionCount(e17, 0);
  539. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 0);
  540. });
  541. test(renderMode + ": Endpoint.detachFromConnection", function() {
  542. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  543. var e16 = jsPlumb.addEndpoint(d16, {isSource:true});
  544. ok(e16.anchor, 'endpoint 16 has an anchor');
  545. var e17 = jsPlumb.addEndpoint(d17, {isSource:true});
  546. var conn = jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  547. assertConnectionCount(e16, 1);
  548. assertConnectionCount(e17, 1);
  549. assertContextSize(3);
  550. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  551. e16.detachFromConnection(conn);
  552. assertContextSize(3); // all canvases should remain; the connection was not removed.
  553. // but endpoint e16 should have no connections now.
  554. assertConnectionCount(e16, 0);
  555. assertConnectionCount(e17, 1);
  556. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  557. });
  558. test(renderMode + ": Endpoint.detachAll", function() {
  559. var d16 = _addDiv("d16"), d17 = _addDiv("d17"), d18 = _addDiv("d18");
  560. var e16 = jsPlumb.addEndpoint($("#d16"), {isSource:true,maxConnections:-1});
  561. ok(e16.anchor, 'endpoint 16 has an anchor');
  562. var e17 = jsPlumb.addEndpoint($("#d17"), {isSource:true});
  563. var e18 = jsPlumb.addEndpoint($("#d18"), {isSource:true});
  564. jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  565. jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e18});
  566. assertConnectionCount(e16, 2);
  567. assertConnectionCount(e17, 1);
  568. assertConnectionCount(e18, 1);
  569. assertContextSize(5);
  570. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 2);
  571. e16.detachAll();
  572. assertConnectionCount(e16, 0);
  573. assertConnectionCount(e17, 0);
  574. assertContextSize(3);
  575. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 0);
  576. });
  577. test(renderMode + ": Endpoint.detach", function() {
  578. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  579. var e16 = jsPlumb.addEndpoint(d16, {isSource:true});
  580. ok(e16.anchor, 'endpoint 16 has an anchor');
  581. var e17 = jsPlumb.addEndpoint(d17, {isSource:true});
  582. var conn = jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  583. assertConnectionCount(e16, 1);
  584. assertConnectionCount(e17, 1);
  585. assertContextSize(3);
  586. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  587. e16.detach(conn);
  588. assertContextSize(2); // the endpoint canvases should remain
  589. // but the connection should be gone, meaning not registered by jsPlumb and not registered on either Endpoint:
  590. assertConnectionCount(e16, 0);
  591. assertConnectionCount(e17, 0);
  592. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 0);
  593. });
  594. test(renderMode + ": Endpoint.isConnectedTo", function() {
  595. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  596. var e16 = jsPlumb.addEndpoint(d16, {isSource:true});
  597. ok(e16.anchor, 'endpoint 16 has an anchor');
  598. var e17 = jsPlumb.addEndpoint(d17, {isSource:true});
  599. var conn = jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  600. equals(e16.isConnectedTo(e17), true, "e16 and e17 are connected");
  601. });
  602. test(renderMode + ": setting endpoint uuid", function() {
  603. var uuid = "14785937583175927504313";
  604. var d16 = _addDiv("d16"), d17 = _addDiv("d17"), d18 = _addDiv("d18");
  605. var e16 = jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  606. equals(e16.getUuid(), uuid, "endpoint's uuid was set correctly");
  607. });
  608. test(renderMode + ": jsPlumb.getEndpoint (by uuid)", function() {
  609. var uuid = "14785937583175927504313";
  610. var d16 = _addDiv("d16");
  611. var e16 = jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  612. var e = jsPlumb.getEndpoint(uuid);
  613. equals(e.getUuid(), uuid, "retrieved endpoint by uuid");
  614. });
  615. test(renderMode + ": jsPlumb.deleteEndpoint (by uuid, simple case)", function() {
  616. var uuid = "14785937583175927504313";
  617. var d16 = _addDiv("d16");
  618. var e16 = jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  619. var e = jsPlumb.getEndpoint(uuid);
  620. equals(e.getUuid(), uuid, "retrieved endpoint by uuid");
  621. jsPlumb.deleteEndpoint(uuid);
  622. var f = jsPlumb.getEndpoint(uuid);
  623. equals(f, null, "endpoint has been deleted");
  624. var ebe = jsPlumb.getTestHarness().endpointsByElement["d16"];
  625. equals(ebe.length, 0, "no endpoints registered for element d16 anymore");
  626. assertContextSize(0);
  627. });
  628. test(renderMode + ": jsPlumb.deleteEndpoint (by uuid, connections too)", function() {
  629. // create two endpoints (one with a uuid), add them to two divs and then connect them.
  630. var uuid = "14785937583175927504313";
  631. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  632. var e16 = jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  633. var e17 = jsPlumb.addEndpoint(d17, {isSource:true,maxConnections:-1});
  634. jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  635. // check that the connection was ok.
  636. equals(e16.connections.length, 1, "e16 has one connection");
  637. equals(e17.connections.length, 1, "e17 has one connection");
  638. assertContextSize(3);
  639. // delete the endpoint that has a uuid. verify that the endpoint cannot be retrieved and that the connection has been removed, but that
  640. // element d17 still has its Endpoint.
  641. jsPlumb.deleteEndpoint(uuid);
  642. var f = jsPlumb.getEndpoint(uuid);
  643. equals(f, null, "endpoint has been deleted");
  644. equals(e16.connections.length, 0, "e16 has no connections");
  645. equals(e17.connections.length, 0, "e17 has no connections");
  646. var ebe = jsPlumb.getTestHarness().endpointsByElement["d16"];
  647. equals(ebe.length, 0, "no endpoints registered for element d16 anymore");
  648. ebe = jsPlumb.getTestHarness().endpointsByElement["d17"];
  649. equals(ebe.length, 1, "element d17 still has its Endpoint");
  650. assertContextSize(1);
  651. // now delete d17's endpoint and check that it has gone.
  652. jsPlumb.deleteEndpoint(e17);
  653. f = jsPlumb.getEndpoint(e17);
  654. equals(f, null, "endpoint has been deleted");
  655. ebe = jsPlumb.getTestHarness().endpointsByElement["d17"];
  656. equals(ebe.length, 0, "element d17 no longer has any Endpoints");
  657. assertContextSize(0);
  658. });
  659. test(renderMode + ": jsPlumb.deleteEndpoint (by reference, simple case)", function() {
  660. var uuid = "14785937583175927504313";
  661. var d16 = _addDiv("d16");
  662. var e16 = jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  663. var e = jsPlumb.getEndpoint(uuid);
  664. equals(e.getUuid(), uuid, "retrieved endpoint by uuid");
  665. jsPlumb.deleteEndpoint(e16);
  666. var f = jsPlumb.getEndpoint(uuid);
  667. equals(f, null, "endpoint has been deleted");
  668. assertContextSize(0);
  669. });
  670. test(renderMode + ": jsPlumb.deleteEndpoint (by reference, connections too)", function() {
  671. var uuid = "14785937583175927504313";
  672. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  673. var e16 = jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  674. var e17 = jsPlumb.addEndpoint(d17, {isSource:true,maxConnections:-1});
  675. jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  676. equals(e16.connections.length, 1, "e16 has one connection");
  677. equals(e17.connections.length, 1, "e17 has one connection");
  678. assertContextSize(3);
  679. jsPlumb.deleteEndpoint(e16);
  680. var f = jsPlumb.getEndpoint(uuid);
  681. equals(f, null, "endpoint has been deleted");
  682. equals(e16.connections.length, 0, "e16 has no connections");
  683. equals(e17.connections.length, 0, "e17 has no connections");
  684. assertContextSize(1);
  685. });
  686. test(renderMode + ": jsPlumb.deleteEveryEndpoint", function() {
  687. var uuid = "14785937583175927504313";
  688. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  689. var e16 = jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  690. var e17 = jsPlumb.addEndpoint(d17, {isSource:true,maxConnections:-1});
  691. assertContextSize(2);
  692. var e = jsPlumb.getEndpoint(uuid);
  693. equals(e.getUuid(), uuid, "retrieved endpoint by uuid");
  694. jsPlumb.deleteEveryEndpoint();
  695. var f = jsPlumb.getEndpoint(uuid);
  696. equals(f, null, "endpoint e16 has been deleted");
  697. var g = jsPlumb.getEndpoint(e17);
  698. equals(g, null, "endpoint e17 has been deleted");
  699. assertContextSize(0);
  700. });
  701. test(renderMode + ": jsPlumb.deleteEveryEndpoint (connections too)", function() {
  702. var uuid = "14785937583175927504313";
  703. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  704. var e16 = jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  705. var e17 = jsPlumb.addEndpoint(d17, {isSource:true,maxConnections:-1});
  706. jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  707. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  708. assertContextSize(3);
  709. var e = jsPlumb.getEndpoint(uuid);
  710. equals(e.getUuid(), uuid, "retrieved endpoint by uuid");
  711. jsPlumb.deleteEveryEndpoint();
  712. var f = jsPlumb.getEndpoint(uuid);
  713. equals(f, null, "endpoint e16 has been deleted");
  714. var g = jsPlumb.getEndpoint(e17);
  715. equals(g, null, "endpoint e17 has been deleted");
  716. assertContextSize(0); // no canvases. so all connection canvases have been cleaned up too.
  717. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 0);
  718. });
  719. test(renderMode + ": jsPlumb.addEndpoint (simple case)", function() {
  720. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  721. var e16 = jsPlumb.addEndpoint(d16, {anchor:[0,0.5,0,-1]});
  722. var e17 = jsPlumb.addEndpoint(d17, {anchor:"TopCenter"});
  723. assertContextSize(2);
  724. equals(e16.anchor.x, 0);
  725. equals(e16.anchor.y, 0.5);
  726. equals(e17.anchor.x, 0.5);
  727. equals(e17.anchor.y, 0);
  728. });
  729. test(renderMode + ": jsPlumb.addEndpoint (simple case, dynamic anchors)", function() {
  730. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  731. var e16 = jsPlumb.addEndpoint(d16, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  732. var e17 = jsPlumb.addEndpoint(d17, {anchors:["TopCenter", "BottomCenter"]});
  733. assertContextSize(2);
  734. equals(e16.anchor.isDynamic, true, "Endpoint 16 has a dynamic anchor");
  735. equals(e17.anchor.isDynamic, true, "Endpoint 17 has a dynamic anchor");
  736. });
  737. test(renderMode + ": jsPlumb.addEndpoint (simple case, two arg method)", function() {
  738. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  739. var e16 = jsPlumb.addEndpoint(d16, {isSource:true, isTarget:false}, {anchor:[0,0.5,0,-1]});
  740. var e17 = jsPlumb.addEndpoint(d17, {isTarget:true, isSource:false}, {anchor:"TopCenter"});
  741. assertContextSize(2);
  742. equals(e16.anchor.x, 0);
  743. equals(e16.anchor.y, 0.5);
  744. equals(false, e16.isTarget);
  745. equals(true, e16.isSource);
  746. equals(e17.anchor.x, 0.5);
  747. equals(e17.anchor.y, 0);
  748. equals(true, e17.isTarget);
  749. equals(false, e17.isSource);
  750. });
  751. test(renderMode + ": jsPlumb.addEndpoints (simple case)", function() {
  752. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  753. var e16 = jsPlumb.addEndpoints(d16, [{isSource:true, isTarget:false, anchor:[0,0.5,0,-1] }, { isTarget:true, isSource:false, anchor:"TopCenter" }]);
  754. assertContextSize(2);
  755. equals(e16[0].anchor.x, 0);
  756. equals(e16[0].anchor.y, 0.5);
  757. equals(false, e16[0].isTarget);
  758. equals(true, e16[0].isSource);
  759. equals(e16[1].anchor.x, 0.5);
  760. equals(e16[1].anchor.y, 0);
  761. equals(true, e16[1].isTarget);
  762. equals(false, e16[1].isSource);
  763. });
  764. test(renderMode + ": jsPlumb.addEndpoints (with reference params)", function() {
  765. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  766. var refParams = {anchor:"RightMiddle"};
  767. var e16 = jsPlumb.addEndpoints(d16, [{isSource:true, isTarget:false}, { isTarget:true, isSource:false }], refParams);
  768. assertContextSize(2);
  769. equals(e16[0].anchor.x, 1);
  770. equals(e16[0].anchor.y, 0.5);
  771. equals(false, e16[0].isTarget);
  772. equals(true, e16[0].isSource);
  773. equals(e16[1].anchor.x, 1);
  774. equals(e16[1].anchor.y, 0.5);
  775. equals(true, e16[1].isTarget);
  776. equals(false, e16[1].isSource);
  777. });
  778. test(renderMode + ": jsPlumb.addEndpoint (simple case, dynamic anchors, two arg method)", function() {
  779. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  780. var e16 = jsPlumb.addEndpoint(d16, {isSource:true, isTarget:false}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  781. var e17 = jsPlumb.addEndpoint(d17, {isTarget:true, isSource:false}, {anchors:["TopCenter", "BottomCenter"]});
  782. assertContextSize(2);
  783. equals(e16.anchor.isDynamic, true, "Endpoint 16 has a dynamic anchor");
  784. equals(e17.anchor.isDynamic, true, "Endpoint 17 has a dynamic anchor");
  785. });
  786. test(renderMode + ": jsPlumb.makeTarget (simple case)", function() {
  787. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  788. var e16 = jsPlumb.addEndpoint(d16, {isSource:true, isTarget:false}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  789. jsPlumb.makeTarget(d17, { isTarget:true,anchor:"TopCenter" });
  790. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  791. });
  792. test(renderMode + ": jsPlumb.makeTarget (specify two divs in an array)", function() {
  793. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  794. jsPlumb.makeTarget([d16, d17], { isTarget:true,anchor:"TopCenter" });
  795. equals(true, jsPlumb.CurrentLibrary.hasClass(d16, "ui-droppable"));
  796. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  797. });
  798. test(renderMode + ": jsPlumb.makeTarget (specify two divs by id in an array)", function() {
  799. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  800. jsPlumb.makeTarget(["d16", "d17"], { isTarget:true,anchor:"TopCenter" });
  801. equals(true, jsPlumb.CurrentLibrary.hasClass(d16, "ui-droppable"));
  802. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  803. });
  804. test(renderMode + ": jsPlumb.makeTarget (specify divs by selector)", function() {
  805. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  806. d16.addClass("FOO");d17.addClass("FOO");
  807. jsPlumb.makeTarget($(".FOO"), { isTarget:true,anchor:"TopCenter" });
  808. equals(true, jsPlumb.CurrentLibrary.hasClass(d16, "ui-droppable"));
  809. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  810. });
  811. test(renderMode + ': jsPlumb.connect (between two Endpoints)', function() {
  812. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  813. var e = jsPlumb.addEndpoint(d1, {});
  814. var e2 = jsPlumb.addEndpoint(d2, {});
  815. ok(e, 'endpoint e exists');
  816. ok(e2, 'endpoint e2 exists');
  817. assertContextSize(2); // should have a canvas for each endpoint now.
  818. assertEndpointCount("d1", 1);
  819. assertEndpointCount("d2", 1);
  820. jsPlumb.connect({target:'d2', sourceEndpoint:e, targetEndpoint:e2});
  821. assertEndpointCount("d1", 1); // no new endpoint should have been added
  822. assertEndpointCount("d2", 1); // no new endpoint should have been added
  823. assertContextSize(3); // now we should also have a canvas for the connection.
  824. });
  825. test(renderMode + ': jsPlumb.connect (between two Endpoints, and dont supply any parameters to the Endpoints.)', function() {
  826. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  827. var e = jsPlumb.addEndpoint(d1);
  828. var e2 = jsPlumb.addEndpoint(d2);
  829. ok(e, 'endpoint e exists');
  830. ok(e2, 'endpoint e2 exists');
  831. assertContextSize(2); // should have a canvas for each endpoint now.
  832. assertEndpointCount("d1", 1);
  833. assertEndpointCount("d2", 1);
  834. jsPlumb.connect({target:'d2', sourceEndpoint:e, targetEndpoint:e2});
  835. assertEndpointCount("d1", 1); // no new endpoint should have been added
  836. assertEndpointCount("d2", 1); // no new endpoint should have been added
  837. assertContextSize(3); // now we should also have a canvas for the connection.
  838. });
  839. test(renderMode + ': jsPlumb.connect (by endpoint)', function() {
  840. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  841. var e16 = jsPlumb.addEndpoint(d16, {isSource:true});
  842. ok(e16.anchor, 'endpoint 16 has an anchor');
  843. var e17 = jsPlumb.addEndpoint(d17, {isSource:true});
  844. jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  845. assertContextSize(3);
  846. });
  847. test(renderMode + ": jsPlumb.connect (two Endpoints - that have been already added - by UUID)", function() {
  848. var srcEndpointUuid = "14785937583175927504313", dstEndpointUuid = "14785937583175927534325";
  849. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  850. var e1 = jsPlumb.addEndpoint("d16", {isSource:true, maxConnections:-1, uuid:srcEndpointUuid});
  851. var e2 = jsPlumb.addEndpoint("d17", {isSource:true, maxConnections:-1, uuid:dstEndpointUuid});
  852. jsPlumb.connect({ uuids: [ srcEndpointUuid, dstEndpointUuid ] });
  853. assertConnectionCount(e1, 1);
  854. assertConnectionCount(e2, 1);
  855. assertContextSize(3);
  856. });
  857. test(renderMode + ": jsPlumb.connect (two Endpoints - that have not been already added - by UUID)", function() {
  858. var srcEndpointUuid = "14785937583175927504313", dstEndpointUuid = "14785937583175927534325";
  859. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  860. jsPlumb.connect({ uuids: [ srcEndpointUuid, dstEndpointUuid ], source:d16, target:d17 });
  861. assertContextSize(3);
  862. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  863. var e1 = jsPlumb.getEndpoint(srcEndpointUuid);
  864. ok(e1 != null, "endpoint with src uuid added");
  865. ok(e1.canvas != null);
  866. var e2 = jsPlumb.getEndpoint(dstEndpointUuid);
  867. ok(e2 != null, "endpoint with target uuid added");
  868. assertConnectionCount(e1, 1);
  869. assertConnectionCount(e2, 1);
  870. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  871. });
  872. test(renderMode + ": jsPlumb.connect (two Endpoints - that have been already added - by endpoint reference)", function() {
  873. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  874. var e1 = jsPlumb.addEndpoint("d16", {isSource:true, maxConnections:-1});
  875. var e2 = jsPlumb.addEndpoint("d17", {isSource:true, maxConnections:-1});
  876. jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  877. assertContextSize(3);
  878. assertConnectionCount(e1, 1);
  879. assertConnectionCount(e2, 1);
  880. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  881. });
  882. test(renderMode + ": jsPlumb.connect (two elements)", function() {
  883. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  884. jsPlumb.connect({ source:d16, target:d17 });
  885. assertContextSize(3);
  886. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  887. });
  888. test(renderMode + ": jsPlumb.connect (Connector test, straight)", function() {
  889. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  890. var conn = jsPlumb.connect({ source:d16, target:d17, connector:"Straight" });
  891. assertContextSize(3);
  892. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  893. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  894. });
  895. test(renderMode + ": jsPlumb.connect (Connector test, bezier, no params)", function() {
  896. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  897. var conn = jsPlumb.connect({ source:d16, target:d17, connector:"Bezier" });
  898. assertContextSize(3);
  899. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  900. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Bezier, "Bezier connector chosen for connection");
  901. equals(conn.connector.majorAnchor, 150, "Bezier connector chose 150 curviness");
  902. });
  903. test(renderMode + ": jsPlumb.connect (Connector test, bezier, curviness as int)", function() {
  904. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  905. var conn = jsPlumb.connect({ source:d16, target:d17, connector:["Bezier", { curviness:200 }] });
  906. assertContextSize(3);
  907. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  908. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Bezier, "Canvas Bezier connector chosen for connection");
  909. equals(conn.connector.majorAnchor, 200, "Bezier connector chose 200 curviness");
  910. });
  911. /*jsPlumb.setRenderMode(jsPlumb.SVG);
  912. test(renderMode + ": jsPlumb.connect (Connector test, bezier, curviness as int)", function() {
  913. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  914. var conn = jsPlumb.connect({ source:d16, target:d17, connector:["Bezier", 200] });
  915. assertContextSize(3);
  916. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  917. equals(conn.connector.constructor, jsPlumb.Connectors.svg.Bezier, "SVG Bezier connector chosen for connection");
  918. equals(conn.connector.majorAnchor, 200, "Bezier connector chose 200 curviness");
  919. });*/
  920. test(renderMode + ": jsPlumb.connect (Connector test, bezier, curviness as named option)", function() {
  921. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  922. var conn = jsPlumb.connect({ source:d16, target:d17, connector:["Bezier", {curviness:300}] });
  923. assertContextSize(3);
  924. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  925. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Bezier, "Bezier connector chosen for connection");
  926. equals(conn.connector.majorAnchor, 300, "Bezier connector chose 300 curviness");
  927. });
  928. test(renderMode + ": jsPlumb.connect (anchors registered correctly; source and target anchors given, as arrays)", function() {
  929. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  930. var conn = jsPlumb.connect({ source:d16, target:d17, connector:"Straight", anchors:[[0.3,0.3,1,0], [0.7,0.7,0,1]] });
  931. assertContextSize(3);
  932. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  933. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Canvas Straight connector chosen for connection");
  934. equals(0.3, conn.endpoints[0].anchor.x, "source anchor x");
  935. equals(0.3, conn.endpoints[0].anchor.y, "source anchor y");
  936. equals(0.7, conn.endpoints[1].anchor.x, "target anchor x");
  937. equals(0.7, conn.endpoints[1].anchor.y, "target anchor y");
  938. });
  939. test(renderMode + ": jsPlumb.connect (anchors registered correctly; source and target anchors given, as strings)", function() {
  940. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  941. var conn = jsPlumb.connect({ source:d16, target:d17, connector:"Straight", anchors:["LeftMiddle", "RightMiddle"] });
  942. assertContextSize(3);
  943. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  944. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  945. equals(0, conn.endpoints[0].anchor.x, "source anchor x");
  946. equals(0.5, conn.endpoints[0].anchor.y, "source anchor y");
  947. equals(1, conn.endpoints[1].anchor.x, "target anchor x");
  948. equals(0.5, conn.endpoints[1].anchor.y, "target anchor y");
  949. });
  950. test(renderMode + ": jsPlumb.connect (anchors registered correctly; source and target anchors given, as arrays)", function() {
  951. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  952. var conn = jsPlumb.connect({ source:d16, target:d17, connector:"Straight", anchors:[[0.3,0.3,1,0], [0.7,0.7,0,1]] });
  953. assertContextSize(3);
  954. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  955. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  956. equals(0.3, conn.endpoints[0].anchor.x, "source anchor x");
  957. equals(0.3, conn.endpoints[0].anchor.y, "source anchor y");
  958. equals(0.7, conn.endpoints[1].anchor.x, "target anchor x");
  959. equals(0.7, conn.endpoints[1].anchor.y, "target anchor y");
  960. });
  961. test(renderMode + ": jsPlumb.connect (two argument method in which some data is reused across connections)", function() {
  962. var d16 = _addDiv("d16"), d17 = _addDiv("d17"), d18 = _addDiv("d18"), d19 = _addDiv("d19");
  963. var sharedData = { connector:"Straight", anchors:[[0.3,0.3,1,0], [0.7,0.7,0,1]] };
  964. var conn = jsPlumb.connect({ source:d16, target:d17}, sharedData);
  965. var conn2 = jsPlumb.connect({ source:d18, target:d19}, sharedData);
  966. assertContextSize(6);
  967. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 2);
  968. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  969. equals(conn2.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  970. equals(0.3, conn.endpoints[0].anchor.x, "source anchor x");
  971. equals(0.3, conn.endpoints[0].anchor.y, "source anchor y");
  972. equals(0.7, conn.endpoints[1].anchor.x, "target anchor x");
  973. equals(0.7, conn.endpoints[1].anchor.y, "target anchor y");
  974. equals(0.3, conn2.endpoints[0].anchor.x, "source anchor x");
  975. equals(0.3, conn2.endpoints[0].anchor.y, "source anchor y");
  976. equals(0.7, conn2.endpoints[1].anchor.x, "target anchor x");
  977. equals(0.7, conn2.endpoints[1].anchor.y, "target anchor y");
  978. });
  979. test(renderMode + ": jsPlumb.connect (Connector as string test)", function() {
  980. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  981. var conn = jsPlumb.connect({ source:d16, target:d17, connector:"Straight" });
  982. assertContextSize(3);
  983. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  984. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  985. });
  986. test(renderMode + ": jsPlumb.connect (Endpoint test)", function() {
  987. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  988. var conn = jsPlumb.connect({ source:d16, target:d17, endpoint:"Rectangle" });
  989. assertContextSize(3);
  990. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  991. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection source");
  992. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection target");
  993. });
  994. test(renderMode + ": jsPlumb.connect (Endpoint as string test)", function() {
  995. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  996. var conn = jsPlumb.connect({ source:d16, target:d17, endpoint:"Rectangle" });
  997. assertContextSize(3);
  998. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  999. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection source");
  1000. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection target");
  1001. });
  1002. test(renderMode + ": jsPlumb.connect (Endpoints test)", function() {
  1003. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1004. var conn = jsPlumb.connect({ source:d16, target:d17, endpoints:["Rectangle", "Dot" ] });
  1005. assertContextSize(3);
  1006. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1007. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection source");
  1008. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Dot, "Dot endpoint chosen for connection target");
  1009. });
  1010. test(renderMode + ": jsPlumb.connect (Blank Endpoint specified via 'endpoint' param)", function() {
  1011. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1012. var conn = jsPlumb.connect({ source:d16, target:d17, endpoint:"Blank" });
  1013. assertContextSize(3);
  1014. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1015. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Blank, "Blank endpoint chosen for connection source");
  1016. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Blank, "Blank endpoint chosen for connection target");
  1017. });
  1018. test(renderMode + ": jsPlumb.connect (Blank Endpoint specified via 'endpoints' param)", function() {
  1019. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1020. var conn = jsPlumb.connect({ source:d16, target:d17, endpoints:["Blank", "Blank" ] });
  1021. assertContextSize(3);
  1022. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1023. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Blank, "Blank endpoint chosen for connection source");
  1024. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Blank, "Blank endpoint chosen for connection target");
  1025. });
  1026. test(renderMode + ": jsPlumb.connect (Endpoint as string test)", function() {
  1027. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1028. var conn = jsPlumb.connect({ source:d16, target:d17, endpoints:["Rectangle", "Dot" ] });
  1029. assertContextSize(3);
  1030. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1031. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection source");
  1032. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Dot, "Dot endpoint chosen for connection target");
  1033. });
  1034. test(renderMode + ": jsPlumb.connect (by Endpoints, connector test)", function() {
  1035. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1036. var e16 = jsPlumb.addEndpoint(d16, {});
  1037. var e17 = jsPlumb.addEndpoint(d17, {});
  1038. var conn = jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1039. assertContextSize(3);
  1040. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1041. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1042. });
  1043. test(renderMode + ": jsPlumb.connect (by Endpoints, connector as string test)", function() {
  1044. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1045. var e16 = jsPlumb.addEndpoint(d16, {});
  1046. var e17 = jsPlumb.addEndpoint(d17, {});
  1047. var conn = jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1048. assertContextSize(3);
  1049. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1050. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1051. });
  1052. test(renderMode + ": jsPlumb.connect (by Endpoints, anchors as string test)", function() {
  1053. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1054. var a16 = "TopCenter", a17 = "BottomCenter";
  1055. var e16 = jsPlumb.addEndpoint(d16, {anchor:a16});
  1056. var e17 = jsPlumb.addEndpoint(d17, {anchor:a17});
  1057. var conn = jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1058. assertContextSize(3);
  1059. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1060. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1061. equals(e16.anchor.x, 0.5, "endpoint 16 is at top center");equals(e16.anchor.y, 0, "endpoint 16 is at top center");
  1062. equals(e17.anchor.x, 0.5, "endpoint 17 is at bottom center");equals(e17.anchor.y, 1, "endpoint 17 is at bottom center");
  1063. });
  1064. test(renderMode + ": jsPlumb.connect (by Endpoints, endpoints create anchors)", function() {
  1065. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1066. var a16 = [0,0.5,0,-1], a17 = [1,0.0,-1,-1];
  1067. var e16 = jsPlumb.addEndpoint(d16, {anchor:a16});
  1068. var e17 = jsPlumb.addEndpoint(d17, {anchor:a17});
  1069. var conn = jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1070. assertContextSize(3);
  1071. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1072. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1073. equals(e16.anchor.x, a16[0]);equals(e16.anchor.y, a16[1]);
  1074. equals(e17.anchor.x, a17[0]);equals(e17.anchor.y, a17[1]);
  1075. equals(e16.anchor.getOrientation()[0], a16[2]); equals(e16.anchor.getOrientation()[1], a16[3]);
  1076. equals(e17.anchor.getOrientation()[0], a17[2]); equals(e17.anchor.getOrientation()[1], a17[3]);
  1077. });
  1078. test(renderMode + ": jsPlumb.connect (by Endpoints, endpoints create dynamic anchors; anchors specified by 'anchor')", function() {
  1079. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1080. var e16 = jsPlumb.addEndpoint(d16, {anchor:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1081. var e17 = jsPlumb.addEndpoint(d17, {anchor:["TopCenter", "BottomCenter"]});
  1082. var conn = jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1083. assertContextSize(3);
  1084. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1085. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1086. equals(e16.anchor.isDynamic, true, "Endpoint 16 has a dynamic anchor");
  1087. equals(e17.anchor.isDynamic, true, "Endpoint 17 has a dynamic anchor");
  1088. });
  1089. test(renderMode + ": jsPlumb.connect (by Endpoints, endpoints create dynamic anchors; anchors specified by 'anchors')", function() {
  1090. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1091. var e16 = jsPlumb.addEndpoint(d16, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1092. var e17 = jsPlumb.addEndpoint(d17, {anchors:["TopCenter", "BottomCenter"]});
  1093. var conn = jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1094. assertContextSize(3);
  1095. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1096. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1097. equals(e16.anchor.isDynamic, true, "Endpoint 16 has a dynamic anchor");
  1098. equals(e17.anchor.isDynamic, true, "Endpoint 17 has a dynamic anchor");
  1099. });
  1100. test(renderMode + ": jsPlumb.connect (connect by element, default endpoint, supplied dynamic anchors)", function() {
  1101. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1102. var anchors = [ [0.25, 0, 0, -1], [1, 0.25, 1, 0], [0.75, 1, 0, 1], [0, 0.75, -1, 0] ];
  1103. jsPlumb.connect({source:d1, target:d2, dynamicAnchors:anchors}); // auto connect with default endpoint and provided anchors
  1104. assertContextSize(3);
  1105. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1106. assertEndpointCount("d1", 1);assertEndpointCount("d2", 1);
  1107. jsPlumb.detach({source:d1, target:d2});
  1108. assertEndpointCount("d1", 1);assertEndpointCount("d2", 1);
  1109. assertContextSize(2);
  1110. });
  1111. test(renderMode + ": jsPlumb.connect (connect by element, supplied endpoint and dynamic anchors)", function() {
  1112. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1113. var endpoint = { isSource:true };
  1114. var e1 = jsPlumb.addEndpoint(d1, endpoint);
  1115. var e2 = jsPlumb.addEndpoint(d2, endpoint);
  1116. var anchors = [ "TopCenter", "BottomCenter" ];
  1117. jsPlumb.connect({sourceEndpoint:e1, targetEndpoint:e2, dynamicAnchors:anchors});
  1118. assertEndpointCount("d1", 1);assertEndpointCount("d2", 1);
  1119. assertContextSize(3);
  1120. jsPlumb.detach({source:d1, target:d2});
  1121. assertEndpointCount("d1", 1);assertEndpointCount("d2", 1);
  1122. assertContextSize(2);
  1123. });
  1124. test(renderMode + ": jsPlumb.connect (connect by element, supplied endpoints using 'source' and 'target' (this test is identical to the one above apart from the param names), and dynamic anchors)", function() {
  1125. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1126. var endpoint = { isSource:true };
  1127. var e1 = jsPlumb.addEndpoint(d1, endpoint);
  1128. var e2 = jsPlumb.addEndpoint(d2, endpoint);
  1129. var anchors = [ "TopCenter", "BottomCenter" ];
  1130. jsPlumb.connect({source:e1, target:e2, dynamicAnchors:anchors});
  1131. assertEndpointCount("d1", 1);assertEndpointCount("d2", 1);
  1132. assertContextSize(3);
  1133. jsPlumb.detach({source:d1, target:d2});
  1134. assertEndpointCount("d1", 1);assertEndpointCount("d2", 1);
  1135. assertContextSize(2);
  1136. });
  1137. test(renderMode + ": jsPlumb.connect (testing for connection event callback)", function() {
  1138. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1139. var connectCallback = null, detachCallback = null;
  1140. jsPlumb.bind("jsPlumbConnection", function(params) {
  1141. connectCallback = $.extend({}, params);
  1142. });
  1143. jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  1144. detachCallback = $.extend({}, params);
  1145. });
  1146. jsPlumb.connect({source:d1, target:d2}); // auto connect with default endpoint and anchor set
  1147. ok(connectCallback != null, "connect callback was made");
  1148. assertContextSize(3);
  1149. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1150. assertEndpointCount("d1", 1);assertEndpointCount("d2", 1);
  1151. jsPlumb.detach({source:d1, target:d2});
  1152. assertContextSize(2);
  1153. ok(detachCallback != null, "detach callback was made");
  1154. });
  1155. test(renderMode + ": jsPlumb.connect (setting cssClass on Connector)", function() {
  1156. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1157. var c = jsPlumb.connect({source:d1,target:d2,cssClass:"CSS"});
  1158. var has = function(clazz) { return $(c.connector.canvas).hasClass(clazz); };
  1159. ok(has("CSS"), "custom cssClass set correctly");
  1160. ok(has(jsPlumb.connectorClass), "basic connector class set correctly");
  1161. });
  1162. test(renderMode + ": jsPlumb.connect (overlays, long-hand version)", function() {
  1163. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1164. var imageEventListener = function() { };
  1165. var arrowSpec = {width:40,length:40,location:0.7, foldback:0, paintStyle:{lineWidth:1, strokeStyle:"#000000"}};
  1166. var connection1 = jsPlumb.connect({
  1167. source:d1,
  1168. target:d2,
  1169. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1170. overlays : [ ["Label",{label:"CONNECTION 1", location:0.3}],
  1171. ["Arrow",arrowSpec ] ]
  1172. });
  1173. equals(2, connection1.overlays.length);
  1174. equals(jsPlumb.Overlays[renderMode].Label, connection1.overlays[0].constructor);
  1175. equals(jsPlumb.Overlays[renderMode].Arrow, connection1.overlays[1].constructor);
  1176. equals(0.7, connection1.overlays[1].loc);
  1177. equals(40, connection1.overlays[1].width);
  1178. equals(40, connection1.overlays[1].length);
  1179. });
  1180. test(renderMode + ": jsPlumb.connect (overlays, long-hand version, IDs specified)", function() {
  1181. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1182. var imageEventListener = function() { };
  1183. var arrowSpec = {
  1184. width:40,
  1185. length:40,
  1186. location:0.7,
  1187. foldback:0,
  1188. paintStyle:{lineWidth:1, strokeStyle:"#000000"},
  1189. id:"anArrow"
  1190. };
  1191. var connection1 = jsPlumb.connect({
  1192. source:d1,
  1193. target:d2,
  1194. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1195. overlays : [ ["Label",{label:"CONNECTION 1", location:0.3, id:"aLabel"}],
  1196. ["Arrow",arrowSpec ] ]
  1197. });
  1198. equals(2, connection1.overlays.length);
  1199. equals(jsPlumb.Overlays[renderMode].Label, connection1.overlays[0].constructor);
  1200. equals("aLabel", connection1.overlays[0].id);
  1201. equals(jsPlumb.Overlays[renderMode].Arrow, connection1.overlays[1].constructor);
  1202. equals(0.7, connection1.overlays[1].loc);
  1203. equals(40, connection1.overlays[1].width);
  1204. equals(40, connection1.overlays[1].length);
  1205. equals("anArrow", connection1.overlays[1].id);
  1206. });
  1207. test(renderMode + ": jsPlumb.connect (remove single overlay by id)", function() {
  1208. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1209. var arrowSpec = {
  1210. width:40,
  1211. length:40,
  1212. location:0.7,
  1213. foldback:0,
  1214. paintStyle:{lineWidth:1, strokeStyle:"#000000"},
  1215. id:"anArrow"
  1216. };
  1217. var connection1 = jsPlumb.connect({
  1218. source:d1,
  1219. target:d2,
  1220. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1221. overlays : [ ["Label",{label:"CONNECTION 1", location:0.3, id:"aLabel"}],
  1222. ["Arrow",arrowSpec ] ]
  1223. });
  1224. equals(2, connection1.overlays.length);
  1225. connection1.removeOverlay("aLabel");
  1226. equals(1, connection1.overlays.length);
  1227. equals("anArrow", connection1.overlays[0].id);
  1228. });
  1229. test(renderMode + ": jsPlumb.connect (remove multiple overlays by id)", function() {
  1230. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1231. var arrowSpec = {
  1232. width:40,
  1233. length:40,
  1234. location:0.7,
  1235. foldback:0,
  1236. paintStyle:{lineWidth:1, strokeStyle:"#000000"},
  1237. id:"anArrow"
  1238. };
  1239. var connection1 = jsPlumb.connect({
  1240. source:d1,
  1241. target:d2,
  1242. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1243. overlays : [ ["Label",{label:"CONNECTION 1", location:0.3, id:"aLabel"}],
  1244. ["Arrow",arrowSpec ] ]
  1245. });
  1246. equals(2, connection1.overlays.length);
  1247. connection1.removeOverlays("aLabel", "anArrow");
  1248. equals(0, connection1.overlays.length);
  1249. });
  1250. test(renderMode + ": jsPlumb.connect (overlays, short-hand version)", function() {
  1251. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1252. var imageEventListener = function() { };
  1253. var loc = { location:0.7 };
  1254. var arrowSpec = { width:40,length:40, foldback:0, paintStyle:{lineWidth:1, strokeStyle:"#000000"} };
  1255. var connection1 = jsPlumb.connect({
  1256. source:d1,
  1257. target:d2,
  1258. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1259. overlays : [ ["Label", {label:"CONNECTION 1", location:0.3}],
  1260. ["Arrow", arrowSpec, loc] ]
  1261. });
  1262. equals(2, connection1.overlays.length);
  1263. equals(jsPlumb.Overlays[renderMode].Label, connection1.overlays[0].constructor);
  1264. equals(jsPlumb.Overlays[renderMode].Arrow, connection1.overlays[1].constructor);
  1265. equals(0.7, connection1.overlays[1].loc);
  1266. equals(40, connection1.overlays[1].width);
  1267. equals(40, connection1.overlays[1].length);
  1268. });
  1269. test(renderMode + ": jsPlumb.connect (removeAllOverlays)", function() {
  1270. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1271. var imageEventListener = function() { };
  1272. var loc = { location:0.7 };
  1273. var arrowSpec = { width:40,length:40, foldback:0, paintStyle:{lineWidth:1, strokeStyle:"#000000"} };
  1274. var connection1 = jsPlumb.connect({
  1275. source:d1,
  1276. target:d2,
  1277. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1278. overlays : [ ["Label", {label:"CONNECTION 1", location:0.3}],
  1279. ["Arrow", arrowSpec, loc] ]
  1280. });
  1281. equals(2, connection1.overlays.length);
  1282. equals(jsPlumb.Overlays[renderMode].Label, connection1.overlays[0].constructor);
  1283. equals(jsPlumb.Overlays[renderMode].Arrow, connection1.overlays[1].constructor);
  1284. equals(0.7, connection1.overlays[1].loc);
  1285. equals(40, connection1.overlays[1].width);
  1286. equals(40, connection1.overlays[1].length);
  1287. connection1.removeAllOverlays();
  1288. equals(0, connection1.overlays.length);
  1289. });
  1290. test(renderMode + ": jsPlumb.connect, specify arrow overlay using string identifier only", function() {
  1291. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1292. var conn = jsPlumb.connect({source:d1,target:d2,overlays:["Arrow"]});
  1293. equals(jsPlumb.Overlays[renderMode].Arrow, conn.overlays[0].constructor);
  1294. });
  1295. test(renderMode + ": Connection.getOverlay method, existing overlay", function() {
  1296. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1297. var conn = jsPlumb.connect({source:d1,target:d2,overlays:[ [ "Arrow", { id:"arrowOverlay" } ] ] });
  1298. var overlay = conn.getOverlay("arrowOverlay");
  1299. ok(overlay != null);
  1300. });
  1301. test(renderMode + ": Connection.getOverlay method, non-existent overlay", function() {
  1302. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1303. var conn = jsPlumb.connect({source:d1,target:d2,overlays:[ [ "Arrow", { id:"arrowOverlay" } ] ] });
  1304. var overlay = conn.getOverlay("IDONTEXIST");
  1305. ok(overlay == null);
  1306. });
  1307. test(renderMode + ": Overlay.setVisible method", function() {
  1308. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1309. var conn = jsPlumb.connect({source:d1,target:d2,overlays:[ [ "Arrow", { id:"arrowOverlay" } ] ] });
  1310. var overlay = conn.getOverlay("arrowOverlay");
  1311. ok(overlay.isVisible());
  1312. overlay.setVisible(false);
  1313. ok(!overlay.isVisible());
  1314. overlay.setVisible(true);
  1315. ok(overlay.isVisible());
  1316. });
  1317. // this test is for the original detach function; it should stay working after i mess with it
  1318. // a little.
  1319. test(renderMode + ": jsPlumb.detach (by element ids)", function() {
  1320. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1321. var e1 = jsPlumb.addEndpoint(d1);
  1322. var e2 = jsPlumb.addEndpoint(d2);
  1323. var e3 = jsPlumb.addEndpoint(d1);
  1324. var e4 = jsPlumb.addEndpoint(d2);
  1325. jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  1326. jsPlumb.connect({ sourceEndpoint:e3, targetEndpoint:e4 }); // make two connections to be sure this works ;)
  1327. assertConnectionCount(e1, 1);
  1328. assertConnectionCount(e2, 1);
  1329. assertConnectionCount(e3, 1);
  1330. assertConnectionCount(e4, 1);
  1331. jsPlumb.detach("d1", "d2");
  1332. assertConnectionCount(e1, 0);
  1333. assertConnectionCount(e2, 0);
  1334. assertConnectionCount(e3, 0);
  1335. assertConnectionCount(e4, 0);
  1336. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 0);
  1337. });
  1338. // detach is being made to operate more like connect - by taking one argument with a whole
  1339. // bunch of possible params in it. if two args are passed in it will continue working
  1340. // in the old way.
  1341. test(renderMode + ": jsPlumb.detach (params object, using element ids)", function() {
  1342. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1343. var e1 = jsPlumb.addEndpoint(d1);
  1344. var e2 = jsPlumb.addEndpoint(d2);
  1345. jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  1346. assertConnectionCount(e1, 1);
  1347. assertConnectionCount(e2, 1);
  1348. jsPlumb.detach({source:"d1", target:"d2"});
  1349. assertConnectionCount(e1, 0);
  1350. assertConnectionCount(e2, 0);
  1351. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 0);
  1352. });
  1353. test(renderMode + ": jsPlumb.detach (params object, using element objects)", function() {
  1354. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1355. var e1 = jsPlumb.addEndpoint(d1);
  1356. var e2 = jsPlumb.addEndpoint(d2);
  1357. jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  1358. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1359. assertContextSize(3);
  1360. assertConnectionCount(e1, 1);
  1361. assertConnectionCount(e2, 1);
  1362. jsPlumb.detach({source:d1, target:d2});
  1363. assertConnectionCount(e1, 0);
  1364. assertConnectionCount(e2, 0);
  1365. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 0);
  1366. assertContextSize(2);
  1367. });
  1368. test(renderMode + ": jsPlumb.detach (source and target as endpoint UUIDs)", function() {
  1369. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1370. var e1 = jsPlumb.addEndpoint(d1, {uuid:"abcdefg"});
  1371. ok(jsPlumb.getEndpoint("abcdefg") != null, "e1 exists");
  1372. var e2 = jsPlumb.addEndpoint(d2, {uuid:"hijklmn"});
  1373. ok(jsPlumb.getEndpoint("hijklmn") != null, "e2 exists");
  1374. jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  1375. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1376. assertContextSize(3);
  1377. assertConnectionCount(e1, 1);
  1378. assertConnectionCount(e2, 1);
  1379. jsPlumb.detach({uuids:["abcdefg", "hijklmn"]});
  1380. assertConnectionCount(e1, 0);
  1381. assertConnectionCount(e2, 0);
  1382. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 0);
  1383. assertContextSize(2);
  1384. });
  1385. test(renderMode + ": jsPlumb.detach (sourceEndpoint and targetEndpoint supplied)", function() {
  1386. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1387. var e1 = jsPlumb.addEndpoint(d1);
  1388. var e2 = jsPlumb.addEndpoint(d2);
  1389. jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  1390. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 1);
  1391. assertContextSize(3);
  1392. assertConnectionCount(e1, 1);
  1393. assertConnectionCount(e2, 1);
  1394. jsPlumb.detach({ sourceEndpoint:e1, targetEndpoint:e2 });
  1395. assertConnectionCount(e1, 0);
  1396. assertConnectionCount(e2, 0);
  1397. assertConnectionByScopeCount(jsPlumb.getDefaultScope(), 0);
  1398. assertContextSize(2);
  1399. });
  1400. test(renderMode + ": jsPlumb.makeDynamicAnchors (longhand)", function() {
  1401. var anchors = [jsPlumb.makeAnchor(0.2, 0, 0, -1), jsPlumb.makeAnchor(1, 0.2, 1, 0),
  1402. jsPlumb.makeAnchor(0.8, 1, 0, 1), jsPlumb.makeAnchor(0, 0.8, -1, 0) ];
  1403. var dynamicAnchor = jsPlumb.makeDynamicAnchor(anchors);
  1404. var a = dynamicAnchor.getAnchors();
  1405. equals(a.length, 4, "Dynamic Anchors has four anchors");
  1406. for (var i = 0; i < a.length; i++)
  1407. ok(a[i].compute.constructor == Function, "anchor " + i + " well formed");
  1408. });
  1409. test(renderMode + ": jsPlumb.makeDynamicAnchors (shorthand)", function() {
  1410. var anchors = [[0.2, 0, 0, -1], [1, 0.2, 1, 0],
  1411. [0.8, 1, 0, 1], [0, 0.8, -1, 0] ];
  1412. var dynamicAnchor = jsPlumb.makeDynamicAnchor(anchors);
  1413. var a = dynamicAnchor.getAnchors();
  1414. equals(a.length, 4, "Dynamic Anchors has four anchors");
  1415. for (var i = 0; i < a.length; i++)
  1416. ok(a[i].compute.constructor == Function, "anchor " + i + " well formed");
  1417. });
  1418. test(renderMode + ": Connection.isVisible/setVisible", function() {
  1419. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1420. var c1 = jsPlumb.connect({source:d1,target:d2});
  1421. equals(true, c1.isVisible(), "Connection is visible after creation.");
  1422. c1.setVisible(false);
  1423. equals(false, c1.isVisible(), "Connection is not visible after calling setVisible(false).");
  1424. equals($(c1.connector.canvas).css("display"), "none");
  1425. c1.setVisible(true);
  1426. equals(true, c1.isVisible(), "Connection is visible after calling setVisible(true).");
  1427. equals($(c1.connector.canvas).css("display"), "block");
  1428. });
  1429. test(renderMode + ": Endpoint.isVisible/setVisible basic test (no connections)", function() {
  1430. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1431. var e1 = jsPlumb.addEndpoint(d1);
  1432. equals(true, e1.isVisible(), "Endpoint is visible after creation.");
  1433. e1.setVisible(false);
  1434. equals(false, e1.isVisible(), "Endpoint is not visible after calling setVisible(false).");
  1435. equals($(e1.canvas).css("display"), "none");
  1436. e1.setVisible(true);
  1437. equals(true, e1.isVisible(), "Endpoint is visible after calling setVisible(true).");
  1438. equals($(e1.canvas).css("display"), "block");
  1439. });
  1440. test(renderMode + ": Endpoint.isVisible/setVisible (one connection, other Endpoint's visibility should track changes in the source, because it has only this connection.)", function() {
  1441. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1442. var e1 = jsPlumb.addEndpoint(d1), e2 = jsPlumb.addEndpoint(d2);
  1443. equals(true, e1.isVisible(), "Endpoint is visible after creation.");
  1444. var c1 = jsPlumb.connect({source:e1, target:e2});
  1445. e1.setVisible(false);
  1446. equals(false, e1.isVisible(), "Endpoint is not visible after calling setVisible(false).");
  1447. equals(false, e2.isVisible(), "other Endpoint is not visible either.");
  1448. equals(false, c1.isVisible(), "connection between the two is not visible either.");
  1449. e1.setVisible(true);
  1450. equals(true, e1.isVisible(), "Endpoint is visible after calling setVisible(true).");
  1451. equals(true, e2.isVisible(), "other Endpoint is visible too");
  1452. equals(true, c1.isVisible(), "connection between the two is visible too.");
  1453. });
  1454. test(renderMode + ": Endpoint.isVisible/setVisible (one connection, other Endpoint's visibility should not track changes in the source, because it has another connection.)", function() {
  1455. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1456. var e1 = jsPlumb.addEndpoint(d1), e2 = jsPlumb.addEndpoint(d2, { maxConnections:2 }), e3 = jsPlumb.addEndpoint(d3);
  1457. equals(true, e1.isVisible(), "Endpoint is visible after creation.");
  1458. var c1 = jsPlumb.connect({source:e1, target:e2});
  1459. var c2 = jsPlumb.connect({source:e2, target:e3});
  1460. e1.setVisible(false);
  1461. equals(false, e1.isVisible(), "Endpoint is not visible after calling setVisible(false).");
  1462. equals(true, e2.isVisible(), "other Endpoint should still be visible.");
  1463. equals(true, e3.isVisible(), "third Endpoint should still be visible.");
  1464. equals(false, c1.isVisible(), "connection between the two is not visible either.");
  1465. equals(true, c2.isVisible(), "other connection is visible.");
  1466. e1.setVisible(true);
  1467. equals(true, e1.isVisible(), "Endpoint is visible after calling setVisible(true).");
  1468. equals(true, e2.isVisible(), "other Endpoint is visible too");
  1469. equals(true, c1.isVisible(), "connection between the two is visible too.");
  1470. equals(true, c2.isVisible(), "other connection is visible.");
  1471. });
  1472. // tests of the functionality that allows a user to specify that they want elements appended to the document body
  1473. test(renderMode + " jsPlumb.Defaults.Container, specified with a selector", function() {
  1474. jsPlumb.Defaults.Container = $("body");
  1475. equals(0, $("#container")[0].childNodes.length);
  1476. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1477. equals(2, $("#container")[0].childNodes.length); // the divs we added have been added to the 'container' div.
  1478. // but we have told jsPlumb to add its canvas to the body, so this connect call should not add another few elements to the container:
  1479. jsPlumb.connect({source:d1, target:d2});
  1480. equals(2, $("#container")[0].childNodes.length);
  1481. });
  1482. // tests of the functionality that allows a user to specify that they want elements appended to some specific container.
  1483. test(renderMode + " jsPlumb.Defaults.Container, specified with DOM element", function() {
  1484. jsPlumb.Defaults.Container = document.getElementsByTagName("body")[0];
  1485. equals(0, $("#container")[0].childNodes.length);
  1486. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1487. equals(2, $("#container")[0].childNodes.length, "two divs added to the container"); // the divs we added have been added to the 'container' div.
  1488. // but we have told jsPlumb to add its canvas to the body, so this connect call should not add another few elements to the container:
  1489. var bodyElementCount = $("body")[0].childNodes.length;
  1490. jsPlumb.connect({source:d1, target:d2});
  1491. equals(2, $("#container")[0].childNodes.length, "still only two children in container; elements were added to the body by jsPlumb");
  1492. // test to see if 3 elements have been added
  1493. equals(bodyElementCount + 3, $("body")[0].childNodes.length, "3 new elements added to the document body");
  1494. });
  1495. test(renderMode + " container specified to connect call, with a selector", function() {
  1496. equals(0, $("#container")[0].childNodes.length);
  1497. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1498. equals(2, $("#container")[0].childNodes.length); // the divs we added have been added to the 'container' div.
  1499. var bodyElementCount = $("body")[0].childNodes.length;
  1500. // but here we tell jsPlumb to add its elements to the body, so this connect call should not add another few elements to the container:
  1501. jsPlumb.connect({source:d1, target:d2, container:$("body")});
  1502. equals(2, $("#container")[0].childNodes.length);
  1503. equals(bodyElementCount + 3, $("body")[0].childNodes.length, "3 new elements added to the document body");
  1504. });
  1505. test(renderMode + " container specified to connect call, with a string ID", function() {
  1506. equals(0, $("#container")[0].childNodes.length);
  1507. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1508. equals(3, $("#container")[0].childNodes.length, "container has divs we added"); // the divs we added have been added to the 'container' div.
  1509. var d3ElementCount = $("#d3")[0].childNodes.length;
  1510. // but here we tell jsPlumb to add its elements to "d3", so this connect call should not add another few elements to the container:
  1511. jsPlumb.connect({source:d1, target:d2, container:"d3"});
  1512. equals(3, $("#container")[0].childNodes.length, "container still has only the divs we added");
  1513. equals(d3ElementCount + 3, $("#d3")[0].childNodes.length, "3 new elements added to div d3");
  1514. });
  1515. test(renderMode + " container specified to addEndpoint call, with a selector", function() {
  1516. equals(0, $("#container")[0].childNodes.length);
  1517. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1518. equals(2, $("#container")[0].childNodes.length); // the divs we added have been added to the 'container' div.
  1519. var bodyElementCount = $("body")[0].childNodes.length;
  1520. // but here we tell jsPlumb to add its elements to the body, so this connect call should not add another few elements to the container:
  1521. jsPlumb.addEndpoint(d1, {container:$("body")});
  1522. equals(2, $("#container")[0].childNodes.length);
  1523. equals(bodyElementCount + 1, $("body")[0].childNodes.length, "1 new element added to the document body");
  1524. });
  1525. test(renderMode + " container specified to addEndpoint call, with a string ID", function() {
  1526. equals(0, $("#container")[0].childNodes.length);
  1527. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1528. equals(3, $("#container")[0].childNodes.length, "container has divs we added"); // the divs we added have been added to the 'container' div.
  1529. var d3ElementCount = $("#d3")[0].childNodes.length;
  1530. // but here we tell jsPlumb to add its elements to "d3", so this connect call should not add another few elements to the container:
  1531. jsPlumb.addEndpoint(d1, { container:"d3" });
  1532. equals(3, $("#container")[0].childNodes.length, "container still has only the divs we added");
  1533. equals(d3ElementCount + 1, $("#d3")[0].childNodes.length, "1 new element added to div d3");
  1534. });
  1535. test(renderMode + " Connector has 'type' member set", function() {
  1536. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1537. var c = jsPlumb.connect({source:d1, target:d2});
  1538. equals(c.connector.type, "Bezier", "Bezier connector has type set");
  1539. var c2 = jsPlumb.connect({source:d1, target:d2, connector:"Straight"});
  1540. equals(c2.connector.type, "Straight", "Straight connector has type set");
  1541. var c3 = jsPlumb.connect({source:d1, target:d2, connector:"Flowchart"});
  1542. equals(c3.connector.type, "Flowchart", "Flowchart connector has type set");
  1543. });
  1544. test(renderMode + " Endpoints have 'type' member set", function() {
  1545. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1546. var c = jsPlumb.connect({source:d1, target:d2});
  1547. equals(c.endpoints[0].type, "Dot", "Dot endpoint has type set");
  1548. var c2 = jsPlumb.connect({source:d1, target:d2, endpoints:["Rectangle", "Blank"]});
  1549. equals(c2.endpoints[1].type, "Blank", "Blank endpoint has type set");
  1550. equals(c2.endpoints[0].type, "Rectangle", "Rectangle endpoint has type set");
  1551. });
  1552. test(renderMode + " Overlays have 'type' member set", function() {
  1553. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1554. var c = jsPlumb.connect({
  1555. source:d1,
  1556. target:d2,
  1557. overlays:[ "Arrow", "Label", "PlainArrow", "Diamond" ]
  1558. });
  1559. equals(c.overlays[0].type, "Arrow", "Arrow overlay has type set");
  1560. equals(c.overlays[1].type, "Label", "Label overlay has type set");
  1561. equals(c.overlays[2].type, "PlainArrow", "PlainArrow overlay has type set");
  1562. equals(c.overlays[3].type, "Diamond", "Diamond overlay has type set");
  1563. });
  1564. test(renderMode + " jsPlumb.hide, original one-arg version", function() {
  1565. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1566. e = { isSource:true, isTarget:true, maxConnections:-1 },
  1567. e1 = jsPlumb.addEndpoint(d1, e),
  1568. e2 = jsPlumb.addEndpoint(d2, e),
  1569. c1 = jsPlumb.connect({source:e1, target:e2});
  1570. equals(true, c1.isVisible(), "Connection 1 is visible after creation.");
  1571. equals(true, e1.isVisible(), "endpoint 1 is visible after creation.");
  1572. equals(true, e2.isVisible(), "endpoint 2 is visible after creation.");
  1573. jsPlumb.hide(d1);
  1574. equals(false, c1.isVisible(), "Connection 1 is no longer visible.");
  1575. equals(true, e1.isVisible(), "endpoint 1 is still visible.");
  1576. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  1577. jsPlumb.show(d1);
  1578. equals(true, c1.isVisible(), "Connection 1 is visible again.");
  1579. });
  1580. test(renderMode + " jsPlumb.hide, two-arg version, endpoints should also be hidden", function() {
  1581. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1582. e = { isSource:true, isTarget:true, maxConnections:-1 },
  1583. e1 = jsPlumb.addEndpoint(d1, e),
  1584. e2 = jsPlumb.addEndpoint(d2, e),
  1585. c1 = jsPlumb.connect({source:e1, target:e2});
  1586. equals(true, c1.isVisible(), "Connection 1 is visible after creation.");
  1587. equals(true, e1.isVisible(), "endpoint 1 is visible after creation.");
  1588. equals(true, e2.isVisible(), "endpoint 2 is visible after creation.");
  1589. jsPlumb.hide("d1", true);
  1590. equals(false, c1.isVisible(), "Connection 1 is no longer visible.");
  1591. equals(false, e1.isVisible(), "endpoint 1 is no longer visible.");
  1592. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  1593. jsPlumb.show(d1); // now show d1, but do not alter the endpoints. e1 should still be hidden
  1594. equals(true, c1.isVisible(), "Connection 1 is visible again.");
  1595. equals(false, e1.isVisible(), "endpoint 1 is no longer visible.");
  1596. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  1597. });
  1598. test(renderMode + " jsPlumb.show, two-arg version, endpoints should become visible", function() {
  1599. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1600. e = { isSource:true, isTarget:true, maxConnections:-1 },
  1601. e1 = jsPlumb.addEndpoint(d1, e),
  1602. e2 = jsPlumb.addEndpoint(d2, e),
  1603. c1 = jsPlumb.connect({source:e1, target:e2});
  1604. jsPlumb.hide("d1", true);
  1605. equals(false, c1.isVisible(), "Connection 1 is no longer visible.");
  1606. equals(false, e1.isVisible(), "endpoint 1 is no longer visible.");
  1607. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  1608. jsPlumb.show(d1, true); // now show d1, and alter the endpoints. e1 should be visible.
  1609. equals(true, c1.isVisible(), "Connection 1 is visible again.");
  1610. equals(true, e1.isVisible(), "endpoint 1 is visible again.");
  1611. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  1612. });
  1613. test(renderMode + " jsPlumb.show, two-arg version, endpoints should become visible, but not all connections, because some other endpoints are not visible.", function() {
  1614. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3"),
  1615. e = { isSource:true, isTarget:true, maxConnections:-1 },
  1616. e1 = jsPlumb.addEndpoint(d1, e),
  1617. e11 = jsPlumb.addEndpoint(d1, e),
  1618. e2 = jsPlumb.addEndpoint(d2, e),
  1619. e3 = jsPlumb.addEndpoint(d3, e),
  1620. c1 = jsPlumb.connect({source:e1, target:e2});
  1621. c2 = jsPlumb.connect({source:e11, target:e3});
  1622. // we now have d1 connected to both d3 and d2. we'll hide d1, and everything on d1 should be hidden.
  1623. jsPlumb.hide("d1", true);
  1624. equals(false, c1.isVisible(), "connection 1 is no longer visible.");
  1625. equals(false, c2.isVisible(), "connection 2 is no longer visible.");
  1626. equals(false, e1.isVisible(), "endpoint 1 is no longer visible.");
  1627. equals(false, e11.isVisible(), "endpoint 1 is no longer visible.");
  1628. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  1629. equals(true, e3.isVisible(), "endpoint 3 is still visible.");
  1630. // now, we will also hide d3. making d1 visible again should NOT result in c2 becoming visible, because the other endpoint
  1631. // for c2 is e3, which is not visible.
  1632. jsPlumb.hide(d3, true);
  1633. equals(false, e3.isVisible(), "endpoint 3 is no longer visible.");
  1634. jsPlumb.show(d1, true); // now show d1, and alter the endpoints. e1 should be visible, c1 should be visible, but c2 should not.
  1635. equals(true, c1.isVisible(), "Connection 1 is visible again.");
  1636. equals(false, c2.isVisible(), "Connection 2 is not visible.");
  1637. equals(true, e1.isVisible(), "endpoint 1 is visible again.");
  1638. equals(true, e11.isVisible(), "endpoint 11 is visible again.");
  1639. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  1640. equals(false, e3.isVisible(), "endpoint 3 is still not visible.");
  1641. });
  1642. /*
  1643. test(renderMode + " jsPlumb.hide, two-arg version, endpoints should also be hidden", function() {
  1644. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1645. e = { isSource:true, isTarget:true, maxConnections:-1 },
  1646. e1 = jsPlumb.addEndpoint(d1, e),
  1647. e2 = jsPlumb.addEndpoint(d2, e),
  1648. c1 = jsPlumb.connect({source:e1, target:e2});
  1649. equals(true, c1.isVisible(), "Connection 1 is visible after creation.");
  1650. equals(true, e1.isVisible(), "endpoint 1 is visible after creation.");
  1651. equals(true, e2.isVisible(), "endpoint 2 is visible after creation.");
  1652. jsPlumb.hide("d1", true);
  1653. equals(false, c1.isVisible(), "Connection 1 is no longer visible.");
  1654. equals(false, e1.isVisible(), "endpoint 1 is no longer visible.");
  1655. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  1656. });
  1657. /**
  1658. * leave this test at the bottom!
  1659. */
  1660. test(renderMode + ': unload test', function() {
  1661. jsPlumb.unload();
  1662. var contextNode = $("._jsPlumb_context");
  1663. ok(contextNode.length == 0, 'context node unloaded');
  1664. });
  1665. };