jsPlumb-1.3.6-tests.js 143 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067
  1. // _jsPlumb qunit tests.
  2. QUnit.config.reorder = false;
  3. var _getContextNode = function() {
  4. return $("#container");
  5. };
  6. var assertContextExists = function() {
  7. ok(_getContextNode().length == 1, "context node exists");
  8. };
  9. var assertContextSize = function(elementCount) {
  10. //equals(_getContextNode().children().length - _divs.length, elementCount, 'context has ' + elementCount + ' children');
  11. };
  12. var assertContextEmpty = function() {
  13. equals(_getContextNode().children.length, 0, "context empty");
  14. };
  15. var assertEndpointCount = function(elId, count, _jsPlumb) {
  16. equals(_jsPlumb.getTestHarness().endpointCount(elId), count, elId + " has " + count + (count > 1) ? "endpoints" : "endpoint");
  17. };
  18. var assertConnectionCount = function(endpoint, count) {
  19. equals(endpoint.connections.length, count, "endpoint has " + count + " connections");
  20. };
  21. var assertConnectionByScopeCount = function(scope, count, _jsPlumb) {
  22. equals(_jsPlumb.getTestHarness().connectionCount(scope), count, 'Scope ' + scope + " has " + count + (count > 1) ? "connections" : "connection");
  23. };
  24. var _divs = [];
  25. var _addDiv = function(id, parent) {
  26. var d1 = document.createElement("div");
  27. if (parent) parent.append(d1); else _getContextNode().append(d1);
  28. d1 = jsPlumb.CurrentLibrary.getElementObject(d1);
  29. jsPlumb.CurrentLibrary.setAttribute(d1, "id", id);
  30. _divs.push(id);
  31. return d1;
  32. };
  33. var defaults = null,
  34. _cleanup = function(_jsPlumb) {
  35. _jsPlumb.reset();
  36. _jsPlumb.Defaults = defaults;
  37. for (var i in _divs) {
  38. $("#" + _divs[i]).remove();
  39. }
  40. _divs.splice(0, _divs.length - 1);
  41. $("#container").empty();
  42. };
  43. var testSuite = function(renderMode, _jsPlumb) {
  44. module("jsPlumb", {
  45. teardown: function() {
  46. _cleanup(_jsPlumb);
  47. },
  48. setup:function() {
  49. defaults = jsPlumb.extend({}, _jsPlumb.Defaults);
  50. }
  51. });
  52. // setup the container
  53. var container = document.createElement("div");
  54. container.id = "container";
  55. document.body.appendChild(container);
  56. var jpcl = jsPlumb.CurrentLibrary;
  57. _jsPlumb.setRenderMode(renderMode);
  58. test(renderMode + " : getElementObject", function() {
  59. var e = document.createElement("div");
  60. e.id = "FOO";
  61. document.body.appendChild(e);
  62. var el = jpcl.getElementObject(e);
  63. equals(jpcl.getAttribute(el, "id"), "FOO");
  64. });
  65. test(renderMode + " : getDOMElement", function() {
  66. var e = document.createElement("div");
  67. e.id = "FOO";
  68. document.body.appendChild(e);
  69. var el = jpcl.getElementObject(e);
  70. var e2 = jpcl.getDOMElement(el);
  71. equals(e2.id, "FOO");
  72. });
  73. test(renderMode + ': _jsPlumb setup', function() {
  74. ok(_jsPlumb, "loaded");
  75. });
  76. test(renderMode + ': getId', function() {
  77. var d10 = _addDiv('d10');
  78. equals(_jsPlumb.getTestHarness().getId(d10), "d10");
  79. });
  80. test(renderMode + ': create a simple endpoint', function() {
  81. var d1 = _addDiv("d1");
  82. var e = _jsPlumb.addEndpoint($("#d1"), {});
  83. ok(e, 'endpoint exists');
  84. assertEndpointCount("d1", 1, _jsPlumb);
  85. ok(e.id != null, "endpoint has had an id assigned");
  86. });
  87. test(renderMode + ': create and remove a simple endpoint', function() {
  88. var d1 = _addDiv("d1");
  89. var ee = _jsPlumb.addEndpoint(d1, {uuid:"78978597593"});
  90. ok(ee != null, "endpoint exists");
  91. var e = _jsPlumb.getEndpoint("78978597593");
  92. ok(e != null, "the endpoint could be retrieved by UUID");
  93. ok(e.id != null, "the endpoint has had an id assigned to it");
  94. assertEndpointCount("d1", 1, _jsPlumb);
  95. assertContextSize(1); // one Endpoint canvas.
  96. _jsPlumb.removeEndpoint(d1, ee);
  97. assertEndpointCount("d1", 0, _jsPlumb);
  98. e = _jsPlumb.getEndpoint("78978597593");
  99. equals(e, null, "the endpoint has been deleted");
  100. assertContextSize(0); // no Endpoint canvases.
  101. });
  102. test(renderMode + ': create two simple endpoints, registered using a selector', function() {
  103. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  104. d1.addClass("window");d2.addClass("window");
  105. var endpoints = _jsPlumb.addEndpoint($(".window"), {});
  106. equals(endpoints.length, 2, "endpoint added to both windows");
  107. assertEndpointCount("d1", 1, _jsPlumb);
  108. assertEndpointCount("d2", 1, _jsPlumb);
  109. });
  110. test(renderMode + ': create two simple endpoints, registered using an array of element ids', function() {
  111. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  112. d1.addClass("window");d2.addClass("window");
  113. var endpoints = _jsPlumb.addEndpoint(["d1", "d2"], {});
  114. equals(endpoints.length, 2, "endpoint added to both windows");
  115. assertEndpointCount("d1", 1, _jsPlumb);
  116. assertEndpointCount("d2", 1, _jsPlumb);
  117. });
  118. test(renderMode + ': draggable silently ignored when jquery ui not present', function() {
  119. var d1 = _addDiv("d1");
  120. var e = _jsPlumb.addEndpoint(d1, {isSource:true});
  121. ok(e, 'endpoint exists');
  122. });
  123. test(renderMode + ': droppable silently ignored when jquery ui not present', function() {
  124. var d1 = _addDiv("d1")
  125. var e = _jsPlumb.addEndpoint(d1, {isTarget:true});
  126. ok(e, 'endpoint exists');
  127. });
  128. test(renderMode + ': defaultEndpointMaxConnections', function() {
  129. var d3 = _addDiv("d3"), d4 = _addDiv("d4");
  130. var e3 = _jsPlumb.addEndpoint(d3, {isSource:true});
  131. ok(e3.anchor, 'endpoint 3 has an anchor');
  132. var e4 = _jsPlumb.addEndpoint(d4, {isSource:true});
  133. assertEndpointCount("d3", 1, _jsPlumb);
  134. assertEndpointCount("d4", 1, _jsPlumb);
  135. assertContextSize(2); // one canvas for each of our two endpoints.
  136. ok(!e3.isFull(), "endpoint 3 is not full.");
  137. _jsPlumb.connect({source:d3, target:'d4', sourceEndpoint:e3, targetEndpoint:e4});
  138. assertConnectionCount(e3, 1); // we have one connection
  139. _jsPlumb.connect({source:d3, target:'d4', sourceEndpoint:e3, targetEndpoint:e4});
  140. assertConnectionCount(e3, 1); // should have refused the connection; default max is 1.
  141. assertContextSize(3); // now we have one more canvas, for the Connection that was accepted.
  142. });
  143. test(renderMode + ': specifiedEndpointMaxConnections', function() {
  144. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  145. var e5 = _jsPlumb.addEndpoint(d5, {isSource:true, maxConnections:3});
  146. ok(e5.anchor, 'endpoint 5 has an anchor');
  147. var e6 = _jsPlumb.addEndpoint(d6, {isSource:true, maxConnections:2}); // this one has max TWO
  148. assertEndpointCount("d5", 1, _jsPlumb); assertEndpointCount("d6", 1, _jsPlumb);
  149. assertContextSize(2);
  150. ok(!e5.isFull(), "endpoint 5 is not full.");
  151. _jsPlumb.connect({sourceEndpoint:e5, targetEndpoint:e6});
  152. assertConnectionCount(e5, 1); // we have one connection
  153. assertContextSize(3);
  154. _jsPlumb.connect({sourceEndpoint:e5, targetEndpoint:e6});
  155. assertConnectionCount(e5, 2); // two connections
  156. assertContextSize(4);
  157. _jsPlumb.connect({sourceEndpoint:e5, targetEndpoint:e6});
  158. assertConnectionCount(e5, 2); // should have refused; max is 2, for d4.
  159. assertContextSize(4);
  160. });
  161. test(renderMode + ': noEndpointMaxConnections', function() {
  162. var d3 = _addDiv("d3"), d4 = _addDiv("d4");
  163. var e3 = _jsPlumb.addEndpoint(d3, {isSource:true, maxConnections:-1});
  164. var e4 = _jsPlumb.addEndpoint(d4, {isSource:true, maxConnections:-1});
  165. _jsPlumb.connect({sourceEndpoint:e3, targetEndpoint:e4});
  166. assertContextSize(3);
  167. assertConnectionCount(e3, 1); // we have one connection
  168. _jsPlumb.connect({sourceEndpoint:e3, targetEndpoint:e4});
  169. assertConnectionCount(e3, 2); // we have two. etc (default was one. this proves max is working).
  170. assertContextSize(4);
  171. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  172. var e5 = _jsPlumb.addEndpoint(d3, {isSource:true, maxConnections:-1});
  173. _jsPlumb.connect({sourceEndpoint:e5, targetEndpoint:e4});
  174. assertConnectionCount(e4, 3);
  175. assertContextSize(6);
  176. });
  177. test(renderMode + ': anchors equal', function() {
  178. var a1 = _jsPlumb.makeAnchor([0, 1, 1, 1], null, _jsPlumb);
  179. var a2 = _jsPlumb.makeAnchor([0, 1, 1, 1], null, _jsPlumb);
  180. ok(a1.equals(a2), "anchors are the same");
  181. });
  182. test(renderMode + ': anchors equal with offsets', function() {
  183. var a1 = _jsPlumb.makeAnchor([0, 1, 1, 1, 10, 13], null, _jsPlumb);
  184. var a2 = _jsPlumb.makeAnchor([0, 1, 1, 1, 10, 13], null, _jsPlumb);
  185. ok(a1.equals(a2), "anchors are the same");
  186. });
  187. test(renderMode + ': anchors not equal', function() {
  188. var a1 = _jsPlumb.makeAnchor([0, 1, 0, 1], null, _jsPlumb);
  189. var a2 = _jsPlumb.makeAnchor([0, 1, 1, 1], null, _jsPlumb);
  190. ok(!a1.equals(a2), "anchors are different");
  191. });
  192. test(renderMode + ': anchor not equal with offsets', function() {
  193. var a1 = _jsPlumb.makeAnchor([0, 1, 1, 1, 10, 13], null, _jsPlumb);
  194. var a2 = _jsPlumb.makeAnchor([0, 1, 1, 1], null, _jsPlumb);
  195. ok(!a1.equals(a2), "anchors are different");
  196. });
  197. test(renderMode + ': detach does not fail when no arguments are provided', function() {
  198. var d3 = _addDiv("d3"), d4 = _addDiv("d4");
  199. _jsPlumb.connect({source:d3, target:d4});
  200. _jsPlumb.detach();
  201. });
  202. // test that detach does not fire an event by default
  203. test(renderMode + ': _jsPlumb.detach should fire detach event by default', function() {
  204. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  205. var conn = _jsPlumb.connect({source:d5, target:d6});
  206. var eventCount = 0;
  207. _jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  208. _jsPlumb.detach(conn);
  209. equals(eventCount, 1);
  210. });
  211. // test that detach does not fire an event by default
  212. test(renderMode + ': _jsPlumb.detach should fire detach event by default, using params object', function() {
  213. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  214. var conn = _jsPlumb.connect({source:d5, target:d6});
  215. var eventCount = 0;
  216. _jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  217. _jsPlumb.detach({connection:conn});
  218. equals(eventCount, 1);
  219. });
  220. // test that detach fires an event when instructed to do so
  221. test(renderMode + ': _jsPlumb.detach should not fire detach event when instructed to not do so', function() {
  222. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  223. var conn = _jsPlumb.connect({source:d5, target:d6});
  224. var eventCount = 0;
  225. _jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  226. _jsPlumb.detach(conn, {fireEvent:false});
  227. equals(eventCount, 0);
  228. });
  229. // issue 81
  230. test(renderMode + ': _jsPlumb.detach should fire only one detach event (pass Connection as argument)', function() {
  231. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  232. var conn = _jsPlumb.connect({source:d5, target:d6});
  233. var eventCount = 0;
  234. _jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  235. _jsPlumb.detach(conn);
  236. equals(eventCount, 1);
  237. });
  238. // issue 81
  239. test(renderMode + ': _jsPlumb.detach should fire only one detach event (pass Connection as param in argument)', function() {
  240. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  241. var conn = _jsPlumb.connect({source:d5, target:d6});
  242. var eventCount = 0;
  243. _jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  244. _jsPlumb.detach({connection:conn});
  245. equals(eventCount, 1);
  246. });
  247. // issue 81
  248. test(renderMode + ': detach should fire only one detach event (pass source and targets as strings as arguments in params object)', function() {
  249. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  250. var conn = _jsPlumb.connect({source:d5, target:d6});
  251. var eventCount = 0;
  252. _jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  253. _jsPlumb.detach({source:"d5", target:"d6"});
  254. equals(eventCount, 1);
  255. });
  256. // issue 81
  257. test(renderMode + ': detach should fire only one detach event (pass source and targets as divs as arguments in params object)', function() {
  258. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  259. var conn = _jsPlumb.connect({source:d5, target:d6});
  260. var eventCount = 0;
  261. _jsPlumb.bind("jsPlumbConnectionDetached", function(c) { eventCount++; });
  262. _jsPlumb.detach({source:d5, target:d6, fireEvent:true});
  263. equals(eventCount, 1);
  264. });
  265. //TODO make sure you run this test with a single detach call, to ensure that
  266. // single detach calls result in the connection being removed. detachEveryConnection can
  267. // just blow away the connectionsByScope array and recreate it.
  268. test(renderMode + ': getConnections (simple case, default scope)', function() {
  269. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  270. _jsPlumb.connect({source:d5, target:d6});
  271. assertContextSize(3);
  272. var c = _jsPlumb.getConnections(); // will get all connections in the default scope.
  273. equals(c.length, 1, "there is one connection");
  274. });
  275. test(renderMode + ': getConnections (simple case, default scope; detach by element id using params object)', function() {
  276. var d5 = _addDiv("d5"), d6 = _addDiv("d6"), d7 = _addDiv("d7");
  277. _jsPlumb.connect({source:d5, target:d6});
  278. _jsPlumb.connect({source:d6, target:d7});
  279. assertContextSize(6);
  280. var c = _jsPlumb.getConnections(); // will get all connections
  281. equals(c.length, 2, "there are two connections initially");
  282. _jsPlumb.detach({source:'d5', target:'d6'});
  283. c = _jsPlumb.getConnections(); // will get all connections
  284. equals(c.length, 1, "after detaching one, there is now one connection.");
  285. assertContextSize(5);
  286. });
  287. test(renderMode + ': getConnections (simple case, default scope; detach by id using params object)', function() {
  288. var d5 = _addDiv("d5"), d6 = _addDiv("d6"), d7 = _addDiv("d7");
  289. _jsPlumb.connect({source:d5, target:d6});
  290. _jsPlumb.connect({source:d6, target:d7});
  291. assertContextSize(6);
  292. var c = _jsPlumb.getConnections(); // will get all connections
  293. equals(c.length, 2, "there are two connections initially");
  294. _jsPlumb.detach({source:"d5", target:"d6"});
  295. c = _jsPlumb.getConnections(); // will get all connections
  296. equals(c.length, 1, "after detaching one, there is now one connection.");
  297. assertContextSize(5);
  298. });
  299. test(renderMode + ': getConnections (simple case, default scope; detach by element object using params object)', function() {
  300. var d5 = _addDiv("d5"), d6 = _addDiv("d6"), d7 = _addDiv("d7");
  301. _jsPlumb.connect({source:d5, target:d6});
  302. _jsPlumb.connect({source:d6, target:d7});
  303. assertContextSize(6);
  304. var c = _jsPlumb.getConnections(); // will get all connections
  305. equals(c.length, 2, "there are two connections initially");
  306. _jsPlumb.detach({source:d5, target:d6});
  307. c = _jsPlumb.getConnections(); // will get all connections
  308. equals(c.length, 1, "after detaching one, there is now one connection.");
  309. assertContextSize(5);
  310. });
  311. test(renderMode + ': getConnections (simple case, default scope; detach by Connection)', function() {
  312. var d5 = _addDiv("d5"), d6 = _addDiv("d6"), d7 = _addDiv("d7");
  313. var c56 = _jsPlumb.connect({source:d5, target:d6});
  314. var c67 = _jsPlumb.connect({source:d6, target:d7});
  315. assertContextSize(6);
  316. var c = _jsPlumb.getConnections(); // will get all connections
  317. equals(c.length, 2, "there are two connections initially");
  318. _jsPlumb.detach(c56);
  319. assertContextSize(5); // check that the connection canvas was removed.
  320. c = _jsPlumb.getConnections(); // will get all connections
  321. equals(c.length, 1, "after detaching one, there is now one connection.");
  322. });
  323. // beforeDetach functionality
  324. test(renderMode + ": detach; beforeDetach on connect call returns false", function() {
  325. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  326. var c = _jsPlumb.connect({source:d1, target:d2, beforeDetach:function(conn) { return false; }});
  327. equals(c.endpoints[0].connections.length, 1, "source endpoint has a connection initially");
  328. _jsPlumb.detach(c);
  329. equals(c.endpoints[0].connections.length, 1, "source endpoint has a connection after detach call was denied");
  330. });
  331. test(renderMode + ": detach; beforeDetach on connect call returns true", function() {
  332. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  333. var c = _jsPlumb.connect({source:d1, target:d2, beforeDetach:function(conn) { return true; }});
  334. equals(c.endpoints[0].connections.length, 1, "source endpoint has a connection initially");
  335. _jsPlumb.detach(c);
  336. equals(c.endpoints[0].connections.length, 0, "source endpoint has no connections after detach call was allowed");
  337. });
  338. test(renderMode + ": detach; beforeDetach on connect call throws an exception; we treat it with the contempt it deserves and pretend it said the detach was ok.", function() {
  339. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  340. var c = _jsPlumb.connect({source:d1, target:d2, beforeDetach:function(conn) { throw "i am an example of badly coded beforeDetach, but i don't break jsPlumb "; }});
  341. equals(c.endpoints[0].connections.length, 1, "source endpoint has a connection initially");
  342. _jsPlumb.detach(c);
  343. equals(c.endpoints[0].connections.length, 0, "source endpoint has no connections after detach call was allowed");
  344. });
  345. test(renderMode + ": detach; beforeDetach on addEndpoint call to source Endpoint returns false", function() {
  346. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  347. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true, beforeDetach:function(conn) { return false; } }),
  348. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true });
  349. var c = _jsPlumb.connect({source:e1,target:e2});
  350. equals(c.endpoints[0].connections.length, 1, "source endpoint has a connection initially");
  351. _jsPlumb.detach(c);
  352. equals(c.endpoints[0].connections.length, 1, "source endpoint has a connection after detach call was denied");
  353. });
  354. test(renderMode + ": detach; beforeDetach on addEndpoint call to source Endpoint returns true", function() {
  355. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  356. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true, beforeDetach:function(conn) { return true; } }),
  357. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true });
  358. var c = _jsPlumb.connect({source:e1,target:e2});
  359. equals(c.endpoints[0].connections.length, 1, "source endpoint has a connection initially");
  360. _jsPlumb.detach(c);
  361. equals(c.endpoints[0].connections.length, 0, "source endpoint has no connections after detach call was allowed");
  362. });
  363. test(renderMode + ": Endpoint.detach; beforeDetach on addEndpoint call to source Endpoint returns false; Endpoint.detach returns false too (the UI needs it to)", function() {
  364. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  365. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true, beforeDetach:function(conn) { return false; } }),
  366. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true });
  367. var c = _jsPlumb.connect({source:e1,target:e2});
  368. equals(c.endpoints[0].connections.length, 1, "source endpoint has a connection initially");
  369. var success = e1.detach(c);
  370. equals(c.endpoints[0].connections.length, 1, "source endpoint has a connection after detach call was denied");
  371. ok(!success, "Endpoint reported detach did not execute");
  372. });
  373. test(renderMode + ": _jsPlumb.detach; beforeDetach on addEndpoint call to target Endpoint returns false", function() {
  374. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  375. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true }),
  376. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true, beforeDetach:function(conn) { return false; } });
  377. var c = _jsPlumb.connect({source:e1,target:e2});
  378. equals(c.endpoints[1].connections.length, 1, "target endpoint has a connection initially");
  379. _jsPlumb.detach(c);
  380. equals(c.endpoints[1].connections.length, 1, "target endpoint has a connection after detach call was denied");
  381. });
  382. test(renderMode + ": _jsPlumb.detach; beforeDetach on addEndpoint call to target Endpoint returns false but detach is forced", function() {
  383. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  384. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true }),
  385. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true, beforeDetach:function(conn) { return false; } });
  386. var c = _jsPlumb.connect({source:e1,target:e2});
  387. equals(c.endpoints[1].connections.length, 1, "target endpoint has a connection initially");
  388. _jsPlumb.detach(c, {forceDetach:true});
  389. equals(c.endpoints[0].connections.length, 0, "source endpoint has no connections after detach call was denied but forced anyway");
  390. equals(c.endpoints[1].connections.length, 0, "target endpoint has no connections after detach call was denied but forced anyway");
  391. });
  392. test(renderMode + ": _jsPlumb.detach; beforeDetach on addEndpoint call to target Endpoint returns true", function() {
  393. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  394. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true }),
  395. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true, beforeDetach:function(conn) { return true; } });
  396. var c = _jsPlumb.connect({source:e1,target:e2});
  397. equals(c.endpoints[1].connections.length, 1, "target endpoint has a connection initially");
  398. _jsPlumb.detach(c);
  399. equals(c.endpoints[1].connections.length, 0, "target endpoint has no connections after detach call was allowed");
  400. });
  401. test(renderMode + ": _jsPlumb.detach; beforeDetach bound to _jsPlumb returns false", function() {
  402. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  403. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true }),
  404. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true });
  405. var c = _jsPlumb.connect({source:e1,target:e2});
  406. _jsPlumb.bind("beforeDetach", function(connection) {
  407. ok(connection.sourceId === "d1", "connection is provided and configured with correct source");
  408. ok(connection.targetId === "d2", "connection is provided and configured with correct target");
  409. return false;
  410. });
  411. equals(c.endpoints[1].connections.length, 1, "target endpoint has a connection initially");
  412. _jsPlumb.detach(c);
  413. equals(c.endpoints[1].connections.length, 1, "target endpoint has a connection after detach call was denied");
  414. });
  415. test(renderMode + ": _jsPlumb.detach; beforeDetach bound to _jsPlumb returns true", function() {
  416. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  417. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true }),
  418. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true });
  419. var c = _jsPlumb.connect({source:e1,target:e2});
  420. _jsPlumb.bind("beforeDetach", function(connection) {
  421. ok(connection.sourceId === "d1", "connection is provided and configured with correct source");
  422. ok(connection.targetId === "d2", "connection is provided and configured with correct target");
  423. return true;
  424. });
  425. equals(c.endpoints[1].connections.length, 1, "target endpoint has a connection initially");
  426. _jsPlumb.detach(c);
  427. equals(c.endpoints[1].connections.length, 0, "target endpoint has no connections after detach call was denied");
  428. });
  429. test(renderMode + ": _jsPlumb.detachAllConnections ; beforeDetach on addEndpoint call to target Endpoint returns false but we should detach anyway", function() {
  430. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  431. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true }),
  432. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true, beforeDetach:function(conn) { return false; } });
  433. var c = _jsPlumb.connect({source:e1,target:e2});
  434. equals(c.endpoints[1].connections.length, 1, "target endpoint has a connection initially");
  435. _jsPlumb.detachAllConnections(d1);
  436. equals(c.endpoints[1].connections.length, 0, "target endpoint has no connections after detachAll was called");
  437. });
  438. test(renderMode + ": _jsPlumb.detachEveryConnection ; beforeDetach on addEndpoint call to target Endpoint returns false but we should detach anyway", function() {
  439. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  440. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true }),
  441. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true, beforeDetach:function(conn) { return false; } });
  442. var c = _jsPlumb.connect({source:e1,target:e2});
  443. equals(c.endpoints[1].connections.length, 1, "target endpoint has a connection initially");
  444. _jsPlumb.detachEveryConnection();
  445. equals(c.endpoints[1].connections.length, 0, "target endpoint has no connections after detachEveryConnection was called");
  446. });
  447. test(renderMode + ": Endpoint.detachAll ; beforeDetach on addEndpoint call to target Endpoint returns false but we should detach anyway", function() {
  448. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  449. var e1 = _jsPlumb.addEndpoint(d1, { isSource:true }),
  450. e2 = _jsPlumb.addEndpoint(d2, { isTarget:true, beforeDetach:function(conn) { return false; } });
  451. var c = _jsPlumb.connect({source:e1,target:e2});
  452. equals(c.endpoints[1].connections.length, 1, "target endpoint has a connection initially");
  453. e1.detachAll();
  454. equals(c.endpoints[1].connections.length, 0, "target endpoint has no connections after detachAllConnections was called");
  455. });
  456. // ******** end of beforeDetach tests **************
  457. // detachEveryConnection/detachAllConnections fireEvent overrides tests
  458. test(renderMode + ": _jsPlumb.detachEveryConnection fires events", function() {
  459. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), connCount = 0;
  460. _jsPlumb.bind("jsPlumbConnection", function() { connCount++; });
  461. _jsPlumb.bind("jsPlumbConnectionDetached", function() { connCount--; });
  462. _jsPlumb.connect({source:d1, target:d2});
  463. _jsPlumb.connect({source:d1, target:d2});
  464. equals(connCount, 2, "two connections registered");
  465. _jsPlumb.detachEveryConnection();
  466. equals(connCount, 0, "no connections registered");
  467. });
  468. test(renderMode + ": _jsPlumb.detachEveryConnection doesn't fire events when instructed not to", function() {
  469. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), connCount = 0;
  470. _jsPlumb.bind("jsPlumbConnection", function() { connCount++; });
  471. _jsPlumb.bind("jsPlumbConnectionDetached", function() { connCount--; });
  472. _jsPlumb.connect({source:d1, target:d2});
  473. _jsPlumb.connect({source:d1, target:d2});
  474. equals(connCount, 2, "two connections registered");
  475. _jsPlumb.detachEveryConnection({fireEvent:false});
  476. equals(connCount, 2, "two connections registered");
  477. });
  478. test(renderMode + ": _jsPlumb.detachAllConnections fires events", function() {
  479. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), connCount = 0,
  480. e1 = _jsPlumb.addEndpoint(d1), e2 = _jsPlumb.addEndpoint(d2);
  481. _jsPlumb.bind("jsPlumbConnection", function() { connCount++; });
  482. _jsPlumb.bind("jsPlumbConnectionDetached", function() { connCount--; });
  483. _jsPlumb.connect({source:d1, target:d2});
  484. _jsPlumb.connect({source:d1, target:d2});
  485. equals(connCount, 2, "two connections registered");
  486. _jsPlumb.detachAllConnections("d1");
  487. equals(connCount, 0, "no connections registered");
  488. });
  489. test(renderMode + ": _jsPlumb.detachAllConnections doesn't fire events when instructed not to", function() {
  490. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), connCount = 0,
  491. e1 = _jsPlumb.addEndpoint(d1), e2 = _jsPlumb.addEndpoint(d2);
  492. _jsPlumb.bind("jsPlumbConnection", function() { connCount++; });
  493. _jsPlumb.bind("jsPlumbConnectionDetached", function() { connCount--; });
  494. _jsPlumb.connect({source:d1, target:d2});
  495. _jsPlumb.connect({source:d1, target:d2});
  496. equals(connCount, 2, "two connections registered");
  497. _jsPlumb.detachAllConnections("d1", {fireEvent:false});
  498. equals(connCount, 2, "two connections registered");
  499. });
  500. test(renderMode + ': getConnections (scope testScope)', function() {
  501. var d5 = _addDiv("d5"), d6 = _addDiv("d6");
  502. _jsPlumb.connect({source:d5, target:d6, scope:'testScope'});
  503. var c = _jsPlumb.getConnections("testScope"); // will get all connections in testScope
  504. equals(c.length, 1, "there is one connection");
  505. equals(c[0].sourceId, 'd5', "the connection's source is d5");
  506. equals(c[0].targetId, 'd6', "the connection's source is d6");
  507. c = _jsPlumb.getConnections(); // will get all connections in default scope; should be none.
  508. equals(c.length, 0, "there are no connections in the default scope");
  509. });
  510. test(renderMode + ': _jsPlumb.getAllConnections (filtered by scope)', function() {
  511. var d8 = _addDiv("d8"), d9 = _addDiv("d9"), d10 = _addDiv('d10');
  512. _jsPlumb.connect({source:d8, target:d9, scope:'testScope'});
  513. _jsPlumb.connect({source:d9, target:d10}); // default scope
  514. var c = _jsPlumb.getAllConnections(); // will get all connections
  515. equals(c[_jsPlumb.getDefaultScope()].length, 1);
  516. equals(c['testScope'].length, 1);
  517. // now supply a list of scopes
  518. c = _jsPlumb.getConnections();
  519. equals(c.length, 1);
  520. c = _jsPlumb.getConnections("testScope");
  521. equals(c.length, 1, "there is one connection in 'testScope'");
  522. });
  523. test(renderMode + ': _jsPlumb.getConnections (filtered by scope and sourceId)', function() {
  524. var d8 = _addDiv("d8"), d9 = _addDiv("d9"), d10 = _addDiv('d10');
  525. _jsPlumb.connect({source:d8, target:d9, scope:'testScope'});
  526. _jsPlumb.connect({source:d9, target:d8, scope:'testScope'});
  527. _jsPlumb.connect({source:d9, target:d10}); // default scope
  528. var c = _jsPlumb.getConnections({scope:'testScope', source:'d8'}); // will get all connections with sourceId 'd8'
  529. equals(c.length, 1, "there is one connection in 'testScope' from d8");
  530. });
  531. test(renderMode + ': _jsPlumb.getConnections (filtered by scope, source id and target id)', function() {
  532. var d11 = _addDiv("d11"), d12 = _addDiv("d12"), d13 = _addDiv('d13');
  533. _jsPlumb.connect({source:d11, target:d12, scope:'testScope'});
  534. _jsPlumb.connect({source:d12, target:d13, scope:'testScope'});
  535. _jsPlumb.connect({source:d11, target:d13, scope:'testScope'});
  536. var c = _jsPlumb.getConnections({scope:'testScope', source:'d11', target:'d13'});
  537. equals(c.length, 1, "there is one connection from d11 to d13");
  538. });
  539. test(renderMode + ': _jsPlumb.getConnections (filtered by a list of scopes)', function() {
  540. var d11 = _addDiv("d11"), d12 = _addDiv("d12"), d13 = _addDiv('d13');
  541. _jsPlumb.connect({source:d11, target:d12, scope:'testScope'});
  542. _jsPlumb.connect({source:d12, target:d13, scope:'testScope2'});
  543. _jsPlumb.connect({source:d11, target:d13, scope:'testScope3'});
  544. var c = _jsPlumb.getConnections({scope:['testScope','testScope3']});
  545. equals(c['testScope'].length, 1, 'there is one connection in testScope');
  546. equals(c['testScope3'].length, 1, 'there is one connection in testScope3');
  547. equals(c['testScope2'], null, 'there are no connections in testScope2');
  548. });
  549. test(renderMode + ': _jsPlumb.getConnections (filtered by a list of scopes and source ids)', function() {
  550. var d11 = _addDiv("d11"), d12 = _addDiv("d12"), d13 = _addDiv('d13');
  551. _jsPlumb.connect({source:d11, target:d12, scope:'testScope'});
  552. _jsPlumb.connect({source:d13, target:d12, scope:'testScope'});
  553. _jsPlumb.connect({source:d12, target:d13, scope:'testScope2'});
  554. _jsPlumb.connect({source:d11, target:d13, scope:'testScope3'});
  555. var c = _jsPlumb.getConnections({scope:['testScope','testScope3'], source:['d11']});
  556. equals(c['testScope'].length, 1, 'there is one connection in testScope');
  557. equals(c['testScope3'].length, 1, 'there is one connection in testScope3');
  558. equals(c['testScope2'], null, 'there are no connections in testScope2');
  559. });
  560. test(renderMode + ': _jsPlumb.getConnections (filtered by a list of scopes, source ids and target ids)', function() {
  561. _jsPlumb.detachEveryConnection();
  562. var d11 = _addDiv("d11"), d12 = _addDiv("d12"), d13 = _addDiv('d13'), d14=_addDiv("d14"), d15=_addDiv("d15");
  563. _jsPlumb.connect({source:d11, target:d12, scope:'testScope'});
  564. _jsPlumb.connect({source:d13, target:d12, scope:'testScope'});
  565. _jsPlumb.connect({source:d11, target:d14, scope:'testScope'});
  566. _jsPlumb.connect({source:d11, target:d15, scope:'testScope'});
  567. _jsPlumb.connect({source:d12, target:d13, scope:'testScope2'});
  568. _jsPlumb.connect({source:d11, target:d13, scope:'testScope3'});
  569. assertContextSize(18);
  570. var c = _jsPlumb.getConnections({scope:['testScope','testScope3'], source:['d11'], target:['d14', 'd15']});
  571. equals(c['testScope'].length, 2, 'there are two connections in testScope');
  572. equals(c['testScope3'], null, 'there are no connections in testScope3');
  573. equals(c['testScope2'], null, 'there are no connections in testScope2');
  574. var anEntry = c['testScope'][0];
  575. ok(anEntry.endpoints[0] != null, "Source endpoint is set");
  576. ok(anEntry.endpoints[1] != null, "Target endpoint is set");
  577. equals(anEntry.source.attr("id"), "d11", "Source is div d11");
  578. equals(anEntry.target.attr("id"), "d14", "Target is div d14");
  579. });
  580. test(renderMode + ': getEndpoints, one Endpoint added by addEndpoint, get Endpoints by selector', function() {
  581. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  582. _jsPlumb.addEndpoint(d1);
  583. var e = _jsPlumb.getEndpoints(d1);
  584. equals(e.length, 1, "there is one endpoint for element d1");
  585. });
  586. test(renderMode + ': getEndpoints, one Endpoint added by addEndpoint, get Endpoints by id', function() {
  587. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  588. _jsPlumb.addEndpoint(d1);
  589. var e = _jsPlumb.getEndpoints("d1");
  590. equals(e.length, 1, "there is one endpoint for element d1");
  591. });
  592. test(renderMode + ': connection event listeners', function() {
  593. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  594. var returnedParams = null/*, returnedParams2 = null*/;
  595. _jsPlumb.bind("jsPlumbConnection", function(params) {
  596. returnedParams = $.extend({}, params);
  597. });
  598. var c = _jsPlumb.connect({source:d1, target:d2});
  599. ok(returnedParams != null, "new connection listener event was fired");
  600. ok(returnedParams.connection != null, 'connection is set');
  601. equals(returnedParams.sourceId, "d1", 'sourceid is set');
  602. equals(returnedParams.targetId, "d2", 'targetid is set');
  603. equals(returnedParams.source.attr("id"), "d1", 'source is set');
  604. equals(returnedParams.target.attr("id"), "d2" , 'target is set');
  605. ok(returnedParams.sourceEndpoint != null, "source endpoint is not null");
  606. ok(returnedParams.targetEndpoint != null, "target endpoint is not null");
  607. _jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  608. returnedParams = $.extend({}, params);
  609. });
  610. _jsPlumb.detach(c);
  611. ok(returnedParams.connection != null, 'connection is set');
  612. //_jsPlumb.detachAll("d1");
  613. //ok(returnedParams2 != null, "removed connection listener event was fired");
  614. });
  615. test(renderMode + ': detach event listeners (detach by connection)', function() {
  616. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  617. var returnedParams = null;
  618. _jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  619. returnedParams = $.extend({}, params);
  620. });
  621. var conn = _jsPlumb.connect({source:d1, target:d2});
  622. _jsPlumb.detach(conn);
  623. ok(returnedParams != null, "removed connection listener event was fired");
  624. ok(returnedParams.connection != null, "removed connection listener event passed in connection");
  625. });
  626. test(renderMode + ': detach event listeners (detach by element ids)', function() {
  627. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  628. var returnedParams = null;
  629. _jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  630. returnedParams = $.extend({}, params);
  631. });
  632. var conn = _jsPlumb.connect({source:d1, target:d2});
  633. _jsPlumb.detach({source:"d1",target:"d2"});
  634. ok(returnedParams != null, "removed connection listener event was fired");
  635. });
  636. test(renderMode + ': detach event listeners (detach by elements)', function() {
  637. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  638. var returnedParams = null;
  639. _jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  640. returnedParams = $.extend({}, params);
  641. });
  642. var conn = _jsPlumb.connect({source:d1, target:d2});
  643. _jsPlumb.detach({source:d1,target:d2});
  644. ok(returnedParams != null, "removed connection listener event was fired");
  645. });
  646. test(renderMode + ': detach event listeners (via Endpoint.detach method)', function() {
  647. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  648. var e1 = _jsPlumb.addEndpoint(d1, {});
  649. var e2 = _jsPlumb.addEndpoint(d2, {});
  650. var returnedParams = null;
  651. _jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  652. returnedParams = $.extend({}, params);
  653. });
  654. var conn = _jsPlumb.connect({sourceEndpoint:e1, targetEndpoint:e2});
  655. assertContextSize(3);
  656. e1.detach(conn);
  657. ok(returnedParams != null, "removed connection listener event was fired");
  658. assertContextSize(2);
  659. });
  660. test(renderMode + ': detach event listeners (via Endpoint.detachFrom method)', function() {
  661. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  662. var e1 = _jsPlumb.addEndpoint(d1, {});
  663. var e2 = _jsPlumb.addEndpoint(d2, {});
  664. var returnedParams = null;
  665. _jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  666. returnedParams = $.extend({}, params);
  667. });
  668. _jsPlumb.connect({sourceEndpoint:e1, targetEndpoint:e2});
  669. assertContextSize(3);
  670. e1.detachFrom(e2);
  671. ok(returnedParams != null, "removed connection listener event was fired");
  672. assertContextSize(2);
  673. });
  674. test(renderMode + ': detach event listeners (via Endpoint.detachAll method)', function() {
  675. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  676. var e1 = _jsPlumb.addEndpoint(d1, {});
  677. var e2 = _jsPlumb.addEndpoint(d2, {});
  678. var returnedParams = null;
  679. _jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  680. returnedParams = $.extend({}, params);
  681. });
  682. _jsPlumb.connect({sourceEndpoint:e1, targetEndpoint:e2});
  683. assertContextSize(3);
  684. e1.detachAll();
  685. ok(returnedParams != null, "removed connection listener event was fired");
  686. assertContextSize(2);
  687. });
  688. test(renderMode + ': detach event listeners (via _jsPlumb.deleteEndpoint method)', function() {
  689. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  690. var e1 = _jsPlumb.addEndpoint(d1, {});
  691. var e2 = _jsPlumb.addEndpoint(d2, {});
  692. var returnedParams = null;
  693. _jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  694. returnedParams = $.extend({}, params);
  695. });
  696. _jsPlumb.connect({sourceEndpoint:e1, targetEndpoint:e2});
  697. assertContextSize(3);
  698. _jsPlumb.deleteEndpoint(e1);
  699. ok(returnedParams != null, "removed connection listener event was fired");
  700. assertContextSize(1);
  701. });
  702. test(renderMode + ': detach event listeners (ensure cleared by _jsPlumb.reset)', function() {
  703. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  704. var returnedParams = null;
  705. _jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  706. returnedParams = $.extend({}, params);
  707. });
  708. var conn = _jsPlumb.connect({source:d1, target:d2});
  709. _jsPlumb.detach({source:d1,target:d2, fireEvent:true});
  710. ok(returnedParams != null, "removed connection listener event was fired");
  711. returnedParams = null;
  712. _jsPlumb.reset();
  713. var conn = _jsPlumb.connect({source:d1, target:d2});
  714. _jsPlumb.detach(d1,d2);
  715. ok(returnedParams == null, "connection listener was cleared by _jsPlumb.reset()");
  716. });
  717. test(renderMode + ': connection events that throw errors', function() {
  718. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  719. var returnedParams = null, returnedParams2 = null;
  720. _jsPlumb.bind("jsPlumbConnection", function(params) {
  721. returnedParams = $.extend({}, params);
  722. throw "oh no!";
  723. });
  724. _jsPlumb.connect({source:d1, target:d2});
  725. var d3 = _addDiv("d3"), d4 = _addDiv("d4");
  726. _jsPlumb.connect({source:d3, target:d4});
  727. ok(returnedParams != null, "new connection listener event was fired; we threw an error, _jsPlumb survived.");
  728. });
  729. test(renderMode + ": Endpoint.detachFrom", function() {
  730. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  731. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true});
  732. ok(e16.anchor, 'endpoint 16 has an anchor');
  733. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true});
  734. var conn = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  735. assertConnectionCount(e16, 1);
  736. assertConnectionCount(e17, 1);
  737. assertContextSize(3);
  738. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  739. e16.detachFrom(e17);
  740. assertContextSize(2); // the endpoint canvases should remain
  741. // but the connection should be gone, meaning not registered by _jsPlumb and not registered on either Endpoint:
  742. assertConnectionCount(e16, 0);
  743. assertConnectionCount(e17, 0);
  744. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 0, _jsPlumb);
  745. });
  746. test(renderMode + ": Endpoint.detachFromConnection", function() {
  747. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  748. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true});
  749. ok(e16.anchor, 'endpoint 16 has an anchor');
  750. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true});
  751. var conn = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  752. assertConnectionCount(e16, 1);
  753. assertConnectionCount(e17, 1);
  754. assertContextSize(3);
  755. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  756. e16.detachFromConnection(conn);
  757. assertContextSize(3); // all canvases should remain; the connection was not removed.
  758. // but endpoint e16 should have no connections now.
  759. assertConnectionCount(e16, 0);
  760. assertConnectionCount(e17, 1);
  761. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  762. });
  763. test(renderMode + ": Endpoint.detachAll", function() {
  764. var d16 = _addDiv("d16"), d17 = _addDiv("d17"), d18 = _addDiv("d18");
  765. var e16 = _jsPlumb.addEndpoint($("#d16"), {isSource:true,maxConnections:-1});
  766. ok(e16.anchor, 'endpoint 16 has an anchor');
  767. var e17 = _jsPlumb.addEndpoint($("#d17"), {isSource:true});
  768. var e18 = _jsPlumb.addEndpoint($("#d18"), {isSource:true});
  769. _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  770. _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e18});
  771. assertConnectionCount(e16, 2);
  772. assertConnectionCount(e17, 1);
  773. assertConnectionCount(e18, 1);
  774. assertContextSize(5);
  775. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 2, _jsPlumb);
  776. e16.detachAll();
  777. assertConnectionCount(e16, 0);
  778. assertConnectionCount(e17, 0);
  779. assertContextSize(3);
  780. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 0, _jsPlumb);
  781. });
  782. test(renderMode + ": Endpoint.detach", function() {
  783. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  784. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true});
  785. ok(e16.anchor, 'endpoint 16 has an anchor');
  786. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true});
  787. var conn = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  788. assertConnectionCount(e16, 1);
  789. assertConnectionCount(e17, 1);
  790. assertContextSize(3);
  791. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  792. e16.detach(conn);
  793. assertContextSize(2); // the endpoint canvases should remain
  794. // but the connection should be gone, meaning not registered by _jsPlumb and not registered on either Endpoint:
  795. assertConnectionCount(e16, 0);
  796. assertConnectionCount(e17, 0);
  797. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 0, _jsPlumb);
  798. });
  799. test(renderMode + ": Endpoint.isConnectedTo", function() {
  800. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  801. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true});
  802. ok(e16.anchor, 'endpoint 16 has an anchor');
  803. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true});
  804. var conn = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  805. equals(e16.isConnectedTo(e17), true, "e16 and e17 are connected");
  806. });
  807. test(renderMode + ": setting endpoint uuid", function() {
  808. var uuid = "14785937583175927504313";
  809. var d16 = _addDiv("d16"), d17 = _addDiv("d17"), d18 = _addDiv("d18");
  810. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  811. equals(e16.getUuid(), uuid, "endpoint's uuid was set correctly");
  812. });
  813. test(renderMode + ": _jsPlumb.getEndpoint (by uuid)", function() {
  814. var uuid = "14785937583175927504313";
  815. var d16 = _addDiv("d16");
  816. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  817. var e = _jsPlumb.getEndpoint(uuid);
  818. equals(e.getUuid(), uuid, "retrieved endpoint by uuid");
  819. });
  820. test(renderMode + ": _jsPlumb.deleteEndpoint (by uuid, simple case)", function() {
  821. var uuid = "14785937583175927504313";
  822. var d16 = _addDiv("d16");
  823. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  824. var e = _jsPlumb.getEndpoint(uuid);
  825. equals(e.getUuid(), uuid, "retrieved endpoint by uuid");
  826. _jsPlumb.deleteEndpoint(uuid);
  827. var f = _jsPlumb.getEndpoint(uuid);
  828. equals(f, null, "endpoint has been deleted");
  829. var ebe = _jsPlumb.getTestHarness().endpointsByElement["d16"];
  830. equals(ebe.length, 0, "no endpoints registered for element d16 anymore");
  831. assertContextSize(0);
  832. });
  833. test(renderMode + ": _jsPlumb.deleteEndpoint (by uuid, connections too)", function() {
  834. // create two endpoints (one with a uuid), add them to two divs and then connect them.
  835. var uuid = "14785937583175927504313";
  836. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  837. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  838. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true,maxConnections:-1});
  839. _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  840. // check that the connection was ok.
  841. equals(e16.connections.length, 1, "e16 has one connection");
  842. equals(e17.connections.length, 1, "e17 has one connection");
  843. assertContextSize(3);
  844. // delete the endpoint that has a uuid. verify that the endpoint cannot be retrieved and that the connection has been removed, but that
  845. // element d17 still has its Endpoint.
  846. _jsPlumb.deleteEndpoint(uuid);
  847. var f = _jsPlumb.getEndpoint(uuid);
  848. equals(f, null, "endpoint has been deleted");
  849. equals(e16.connections.length, 0, "e16 has no connections");
  850. equals(e17.connections.length, 0, "e17 has no connections");
  851. var ebe = _jsPlumb.getTestHarness().endpointsByElement["d16"];
  852. equals(ebe.length, 0, "no endpoints registered for element d16 anymore");
  853. ebe = _jsPlumb.getTestHarness().endpointsByElement["d17"];
  854. equals(ebe.length, 1, "element d17 still has its Endpoint");
  855. assertContextSize(1);
  856. // now delete d17's endpoint and check that it has gone.
  857. _jsPlumb.deleteEndpoint(e17);
  858. f = _jsPlumb.getEndpoint(e17);
  859. equals(f, null, "endpoint has been deleted");
  860. ebe = _jsPlumb.getTestHarness().endpointsByElement["d17"];
  861. equals(ebe.length, 0, "element d17 no longer has any Endpoints");
  862. assertContextSize(0);
  863. });
  864. test(renderMode + ": _jsPlumb.deleteEndpoint (by reference, simple case)", function() {
  865. var uuid = "14785937583175927504313";
  866. var d16 = _addDiv("d16");
  867. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  868. var e = _jsPlumb.getEndpoint(uuid);
  869. equals(e.getUuid(), uuid, "retrieved endpoint by uuid");
  870. _jsPlumb.deleteEndpoint(e16);
  871. var f = _jsPlumb.getEndpoint(uuid);
  872. equals(f, null, "endpoint has been deleted");
  873. assertContextSize(0);
  874. });
  875. test(renderMode + ": _jsPlumb.deleteEndpoint (by reference, connections too)", function() {
  876. var uuid = "14785937583175927504313";
  877. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  878. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  879. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true,maxConnections:-1});
  880. _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  881. equals(e16.connections.length, 1, "e16 has one connection");
  882. equals(e17.connections.length, 1, "e17 has one connection");
  883. assertContextSize(3);
  884. _jsPlumb.deleteEndpoint(e16);
  885. var f = _jsPlumb.getEndpoint(uuid);
  886. equals(f, null, "endpoint has been deleted");
  887. equals(e16.connections.length, 0, "e16 has no connections");
  888. equals(e17.connections.length, 0, "e17 has no connections");
  889. assertContextSize(1);
  890. });
  891. test(renderMode + ": _jsPlumb.deleteEveryEndpoint", function() {
  892. var uuid = "14785937583175927504313";
  893. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  894. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  895. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true,maxConnections:-1});
  896. assertContextSize(2);
  897. var e = _jsPlumb.getEndpoint(uuid);
  898. equals(e.getUuid(), uuid, "retrieved endpoint by uuid");
  899. _jsPlumb.deleteEveryEndpoint();
  900. var f = _jsPlumb.getEndpoint(uuid);
  901. equals(f, null, "endpoint e16 has been deleted");
  902. var g = _jsPlumb.getEndpoint(e17);
  903. equals(g, null, "endpoint e17 has been deleted");
  904. assertContextSize(0);
  905. });
  906. test(renderMode + ": _jsPlumb.deleteEveryEndpoint (connections too)", function() {
  907. var uuid = "14785937583175927504313";
  908. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  909. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true,maxConnections:-1, uuid:uuid});
  910. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true,maxConnections:-1});
  911. _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  912. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  913. assertContextSize(3);
  914. var e = _jsPlumb.getEndpoint(uuid);
  915. equals(e.getUuid(), uuid, "retrieved endpoint by uuid");
  916. _jsPlumb.deleteEveryEndpoint();
  917. var f = _jsPlumb.getEndpoint(uuid);
  918. equals(f, null, "endpoint e16 has been deleted");
  919. var g = _jsPlumb.getEndpoint(e17);
  920. equals(g, null, "endpoint e17 has been deleted");
  921. assertContextSize(0); // no canvases. so all connection canvases have been cleaned up too.
  922. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 0, _jsPlumb);
  923. });
  924. test(renderMode + ": _jsPlumb.addEndpoint (simple case)", function() {
  925. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  926. var e16 = _jsPlumb.addEndpoint(d16, {anchor:[0,0.5,0,-1]});
  927. var e17 = _jsPlumb.addEndpoint(d17, {anchor:"TopCenter"});
  928. assertContextSize(2);
  929. equals(e16.anchor.x, 0);
  930. equals(e16.anchor.y, 0.5);
  931. equals(e17.anchor.x, 0.5);
  932. equals(e17.anchor.y, 0);
  933. });
  934. test(renderMode + ": _jsPlumb.addEndpoint (tooltip)", function() {
  935. var d16 = _addDiv("d16"), d17 = _addDiv("d17"),
  936. e16 = _jsPlumb.addEndpoint(d16, {tooltip:"FOO"}),
  937. e17 = _jsPlumb.addEndpoint(d17, {tooltip:"BAZ"});
  938. assertContextSize(2);
  939. equals(e16.canvas.getAttribute("title"), "FOO");
  940. equals(e17.canvas.getAttribute("title"), "BAZ");
  941. });
  942. test(renderMode + ": _jsPlumb.addEndpoint (simple case, dynamic anchors)", function() {
  943. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  944. var e16 = _jsPlumb.addEndpoint(d16, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  945. var e17 = _jsPlumb.addEndpoint(d17, {anchors:["TopCenter", "BottomCenter"]});
  946. assertContextSize(2);
  947. equals(e16.anchor.isDynamic, true, "Endpoint 16 has a dynamic anchor");
  948. equals(e17.anchor.isDynamic, true, "Endpoint 17 has a dynamic anchor");
  949. });
  950. test(renderMode + ": _jsPlumb.addEndpoint (simple case, two arg method)", function() {
  951. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  952. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true, isTarget:false}, {anchor:[0,0.5,0,-1]});
  953. var e17 = _jsPlumb.addEndpoint(d17, {isTarget:true, isSource:false}, {anchor:"TopCenter"});
  954. assertContextSize(2);
  955. equals(e16.anchor.x, 0);
  956. equals(e16.anchor.y, 0.5);
  957. equals(false, e16.isTarget);
  958. equals(true, e16.isSource);
  959. equals(e17.anchor.x, 0.5);
  960. equals(e17.anchor.y, 0);
  961. equals(true, e17.isTarget);
  962. equals(false, e17.isSource);
  963. });
  964. test(renderMode + ": _jsPlumb.addEndpoints (simple case)", function() {
  965. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  966. var e16 = _jsPlumb.addEndpoints(d16, [{isSource:true, isTarget:false, anchor:[0,0.5,0,-1] }, { isTarget:true, isSource:false, anchor:"TopCenter" }]);
  967. assertContextSize(2);
  968. equals(e16[0].anchor.x, 0);
  969. equals(e16[0].anchor.y, 0.5);
  970. equals(false, e16[0].isTarget);
  971. equals(true, e16[0].isSource);
  972. equals(e16[1].anchor.x, 0.5);
  973. equals(e16[1].anchor.y, 0);
  974. equals(true, e16[1].isTarget);
  975. equals(false, e16[1].isSource);
  976. });
  977. test(renderMode + ": _jsPlumb.addEndpoints (with reference params)", function() {
  978. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  979. var refParams = {anchor:"RightMiddle"};
  980. var e16 = _jsPlumb.addEndpoints(d16, [{isSource:true, isTarget:false}, { isTarget:true, isSource:false }], refParams);
  981. assertContextSize(2);
  982. equals(e16[0].anchor.x, 1);
  983. equals(e16[0].anchor.y, 0.5);
  984. equals(false, e16[0].isTarget);
  985. equals(true, e16[0].isSource);
  986. equals(e16[1].anchor.x, 1);
  987. equals(e16[1].anchor.y, 0.5);
  988. equals(true, e16[1].isTarget);
  989. equals(false, e16[1].isSource);
  990. });
  991. test(renderMode + ": _jsPlumb.addEndpoint (simple case, dynamic anchors, two arg method)", function() {
  992. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  993. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true, isTarget:false}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  994. var e17 = _jsPlumb.addEndpoint(d17, {isTarget:true, isSource:false}, {anchors:["TopCenter", "BottomCenter"]});
  995. assertContextSize(2);
  996. equals(e16.anchor.isDynamic, true, "Endpoint 16 has a dynamic anchor");
  997. equals(e17.anchor.isDynamic, true, "Endpoint 17 has a dynamic anchor");
  998. });
  999. test(renderMode + ": _jsPlumb.addEndpoints (default overlays)", function() {
  1000. _jsPlumb.Defaults.Overlays = [
  1001. [ "Label", { id:"label" } ]
  1002. ];
  1003. var d16 = _addDiv("d16"), d17 = _addDiv("d17"),
  1004. e1 = _jsPlumb.addEndpoint(d16),
  1005. e2 = _jsPlumb.addEndpoint(d17);
  1006. ok(e1.getOverlay("label") != null, "endpoint 1 has overlay from defaults");
  1007. });
  1008. test(renderMode + ": _jsPlumb.addEndpoints (default overlays)", function() {
  1009. _jsPlumb.Defaults.Overlays = [
  1010. [ "Label", { id:"label" } ]
  1011. ];
  1012. var d16 = _addDiv("d16"), d17 = _addDiv("d17"),
  1013. e1 = _jsPlumb.addEndpoint(d16, {
  1014. overlays:[
  1015. ["Label", { id:"label2", location:[ 0.5, 1 ] } ]
  1016. ]
  1017. }),
  1018. e2 = _jsPlumb.addEndpoint(d17);
  1019. ok(e1.getOverlay("label") != null, "endpoint 1 has overlay from defaults");
  1020. ok(e1.getOverlay("label2") != null, "endpoint 1 has overlay from addEndpoint call");
  1021. });
  1022. test(renderMode + ": _jsPlumb.addEndpoints (end point set label)", function() {
  1023. var d16 = _addDiv("d16"), d17 = _addDiv("d17"),
  1024. e1 = _jsPlumb.addEndpoint(d16),
  1025. e2 = _jsPlumb.addEndpoint(d17);
  1026. e1.setLabel("FOO");
  1027. equals(e1.getLabel(), "FOO", "endpoint's label is correct");
  1028. });
  1029. test(renderMode + ": _jsPlumb.addEndpoints (end point set label in constructor, as string)", function() {
  1030. var d16 = _addDiv("d16"), d17 = _addDiv("d17"),
  1031. e1 = _jsPlumb.addEndpoint(d16, {label:"FOO"}),
  1032. e2 = _jsPlumb.addEndpoint(d17);
  1033. equals(e1.getLabel(), "FOO", "endpoint's label is correct");
  1034. });
  1035. test(renderMode + ": _jsPlumb.addEndpoints (end point set label in constructor, as function)", function() {
  1036. var d16 = _addDiv("d16"), d17 = _addDiv("d17"),
  1037. e1 = _jsPlumb.addEndpoint(d16, {label:function() { return "BAZ"; }, labelLocation:0.1}),
  1038. e2 = _jsPlumb.addEndpoint(d17);
  1039. equals(e1.getLabel()(), "BAZ", "endpoint's label is correct");
  1040. equals(e1.getLabelOverlay().getLocation(), 0.1, "endpoint's label's location is correct");
  1041. });
  1042. test(renderMode + ": _jsPlumb.makeTarget (simple case)", function() {
  1043. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1044. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true, isTarget:false}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1045. _jsPlumb.makeTarget(d17, { isTarget:true,anchor:"TopCenter" });
  1046. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  1047. });
  1048. test(renderMode + ": _jsPlumb.makeTarget (specify two divs in an array)", function() {
  1049. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1050. _jsPlumb.makeTarget([d16, d17], { isTarget:true,anchor:"TopCenter" });
  1051. equals(true, jsPlumb.CurrentLibrary.hasClass(d16, "ui-droppable"));
  1052. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  1053. });
  1054. test(renderMode + ": _jsPlumb.makeTarget (specify two divs by id in an array)", function() {
  1055. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1056. _jsPlumb.makeTarget(["d16", "d17"], { isTarget:true,anchor:"TopCenter" });
  1057. equals(true, jsPlumb.CurrentLibrary.hasClass(d16, "ui-droppable"));
  1058. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  1059. });
  1060. test(renderMode + ": _jsPlumb.makeTarget (specify divs by selector)", function() {
  1061. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1062. d16.addClass("FOO");d17.addClass("FOO");
  1063. _jsPlumb.makeTarget($(".FOO"), { isTarget:true,anchor:"TopCenter" });
  1064. equals(true, jsPlumb.CurrentLibrary.hasClass(d16, "ui-droppable"));
  1065. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  1066. });
  1067. test(renderMode + ": _jsPlumb.connect after makeTarget (simple case)", function() {
  1068. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1069. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true, isTarget:false}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1070. _jsPlumb.makeTarget(d17, { isTarget:true,anchor:"LeftMiddle" }); // give it a non-default anchor, we will check this below.
  1071. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  1072. _jsPlumb.connect({source:e16, target:"d17"});
  1073. assertEndpointCount("d16", 1, _jsPlumb);
  1074. assertEndpointCount("d17", 1, _jsPlumb);
  1075. var e = _jsPlumb.getEndpoints("d17");
  1076. equals(e.length, 1, "d17 has one endpoint");
  1077. equals(e[0].anchor.x, 0, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1078. equals(e[0].anchor.y, 0.5, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1079. });
  1080. test(renderMode + ": _jsPlumb.connect after makeTarget (simple case, two connect calls)", function() {
  1081. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1082. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true, isTarget:false, maxConnections:-1}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1083. _jsPlumb.makeTarget(d17, { isTarget:true,anchor:"LeftMiddle" }); // give it a non-default anchor, we will check this below.
  1084. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  1085. _jsPlumb.connect({source:e16, target:"d17"});
  1086. _jsPlumb.connect({source:e16, target:"d17"});
  1087. assertEndpointCount("d16", 1, _jsPlumb);
  1088. assertEndpointCount("d17", 2, _jsPlumb);
  1089. var e = _jsPlumb.getEndpoints("d17");
  1090. equals(e[0].anchor.x, 0, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1091. equals(e[0].anchor.y, 0.5, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1092. });
  1093. test(renderMode + ": _jsPlumb.connect after makeTarget (simple case, two connect calls, uniqueEndpoint set)", function() {
  1094. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1095. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true, isTarget:false, maxConnections:-1}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1096. _jsPlumb.makeTarget(d17, { isTarget:true, anchor:"LeftMiddle", uniqueEndpoint:true, maxConnections:-1 }); // give it a non-default anchor, we will check this below.
  1097. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  1098. _jsPlumb.connect({source:e16, target:"d17"});
  1099. _jsPlumb.connect({source:e16, target:"d17"});
  1100. assertEndpointCount("d16", 1, _jsPlumb);
  1101. assertEndpointCount("d17", 1, _jsPlumb);
  1102. var e = _jsPlumb.getEndpoints("d17");
  1103. equals(e[0].anchor.x, 0, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1104. equals(e[0].anchor.y, 0.5, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1105. equals(e[0].connections.length, 2, "endpoint on d17 has two connections");
  1106. });
  1107. test(renderMode + ": _jsPlumb.connect after makeTarget (newConnection:true specified)", function() {
  1108. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1109. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true, isTarget:false}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1110. _jsPlumb.makeTarget(d17, { isTarget:true,anchor:"LeftMiddle" }); // give it a non-default anchor, we will check this below.
  1111. equals(true, jsPlumb.CurrentLibrary.hasClass(d17, "ui-droppable"));
  1112. _jsPlumb.connect({source:e16, target:"d17", newConnection:true});
  1113. assertEndpointCount("d16", 1, _jsPlumb);
  1114. assertEndpointCount("d17", 1, _jsPlumb);
  1115. var e = _jsPlumb.getEndpoints("d17");
  1116. equals(e[0].anchor.x, 0.5, "anchor is BottomCenter"); //here we should be seeing the default anchor
  1117. equals(e[0].anchor.y, 1, "anchor is BottomCenter"); //here we should be seeing the default anchor
  1118. });
  1119. // jsPlumb.connect, after makeSource has been called on some element
  1120. test(renderMode + ": _jsPlumb.connect after makeSource (simple case)", function() {
  1121. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1122. var e16 = _jsPlumb.addEndpoint(d16, {isSource:false, isTarget:true}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1123. _jsPlumb.makeSource(d17, { isSource:true,anchor:"LeftMiddle" }); // give it a non-default anchor, we will check this below.
  1124. _jsPlumb.connect({source:"d17", target:e16});
  1125. assertEndpointCount("d16", 1, _jsPlumb);
  1126. assertEndpointCount("d17", 1, _jsPlumb);
  1127. var e = _jsPlumb.getEndpoints("d17");
  1128. equals(e[0].anchor.x, 0, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1129. equals(e[0].anchor.y, 0.5, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1130. });
  1131. test(renderMode + ": _jsPlumb.connect after makeSource (simple case, two connect calls)", function() {
  1132. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1133. var e16 = _jsPlumb.addEndpoint(d16, {isSource:false, isTarget:true, maxConnections:-1}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1134. _jsPlumb.makeSource(d17, { isSource:true,anchor:"LeftMiddle" }); // give it a non-default anchor, we will check this below.
  1135. _jsPlumb.connect({source:"d17", target:e16});
  1136. _jsPlumb.connect({source:"d17", target:e16});
  1137. assertEndpointCount("d16", 1, _jsPlumb);
  1138. assertEndpointCount("d17", 2, _jsPlumb);
  1139. var e = _jsPlumb.getEndpoints("d17");
  1140. equals(e[0].anchor.x, 0, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1141. equals(e[0].anchor.y, 0.5, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1142. });
  1143. test(renderMode + ": _jsPlumb.connect after makeTarget (simple case, two connect calls, uniqueEndpoint set)", function() {
  1144. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1145. var e16 = _jsPlumb.addEndpoint(d16, {isSource:false, isTarget:true, maxConnections:-1}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1146. _jsPlumb.makeSource(d17, { isSource:true, anchor:"LeftMiddle", uniqueEndpoint:true, maxConnections:-1 }); // give it a non-default anchor, we will check this below.
  1147. _jsPlumb.connect({source:"d17", target:e16});
  1148. _jsPlumb.connect({source:"d17", target:e16});
  1149. assertEndpointCount("d16", 1, _jsPlumb);
  1150. assertEndpointCount("d17", 1, _jsPlumb);
  1151. var e = _jsPlumb.getEndpoints("d17");
  1152. equals(e[0].anchor.x, 0, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1153. equals(e[0].anchor.y, 0.5, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1154. equals(e[0].connections.length, 2, "endpoint on d17 has two connections");
  1155. });
  1156. test(renderMode + ": _jsPlumb.connect after makeTarget (newConnection:true specified)", function() {
  1157. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1158. var e16 = _jsPlumb.addEndpoint(d16, {isSource:false, isTarget:true}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1159. _jsPlumb.makeSource(d17, { isSource:true,anchor:"LeftMiddle" }); // give it a non-default anchor, we will check this below.
  1160. _jsPlumb.connect({source:"d17", target:e16, newConnection:true});
  1161. assertEndpointCount("d16", 1, _jsPlumb);
  1162. assertEndpointCount("d17", 1, _jsPlumb);
  1163. var e = _jsPlumb.getEndpoints("d17");
  1164. equals(e[0].anchor.x, 0.5, "anchor is BottomCenter"); //here we should be seeing the default anchor
  1165. equals(e[0].anchor.y, 1, "anchor is BottomCenter"); //here we should be seeing the default anchor
  1166. });
  1167. test(renderMode + ": _jsPlumb.connect after makeSource on child; wth parent set (parent should be recognised)", function() {
  1168. var d16 = _addDiv("d16"), d17 = _addDiv("d17"), d18 = _addDiv("d18", d17);
  1169. var e16 = _jsPlumb.addEndpoint(d16, {isSource:false, isTarget:true}, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1170. _jsPlumb.makeSource(d18, { isSource:true,anchor:"LeftMiddle", parent:d17 }); // give it a non-default anchor, we will check this below.
  1171. _jsPlumb.connect({source:"d17", target:e16});
  1172. assertEndpointCount("d16", 1, _jsPlumb);
  1173. assertEndpointCount("d17", 1, _jsPlumb);
  1174. assertEndpointCount("d18", 0, _jsPlumb);
  1175. var e = _jsPlumb.getEndpoints("d17");
  1176. equals(e[0].anchor.x, 0, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1177. equals(e[0].anchor.y, 0.5, "anchor is LeftMiddle"); //here we should be seeing the anchor we setup via makeTarget
  1178. });
  1179. // ***********************************************
  1180. test(renderMode + ': _jsPlumb.connect (between two Endpoints)', function() {
  1181. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1182. var e = _jsPlumb.addEndpoint(d1, {});
  1183. var e2 = _jsPlumb.addEndpoint(d2, {});
  1184. ok(e, 'endpoint e exists');
  1185. ok(e2, 'endpoint e2 exists');
  1186. assertContextSize(2); // should have a canvas for each endpoint now.
  1187. assertEndpointCount("d1", 1, _jsPlumb);
  1188. assertEndpointCount("d2", 1, _jsPlumb);
  1189. var c = _jsPlumb.connect({target:'d2', sourceEndpoint:e, targetEndpoint:e2});
  1190. assertEndpointCount("d1", 1, _jsPlumb); // no new endpoint should have been added
  1191. assertEndpointCount("d2", 1, _jsPlumb); // no new endpoint should have been added
  1192. assertContextSize(3); // now we should also have a canvas for the connection.
  1193. ok(c.id != null, "connection has had an id assigned");
  1194. });
  1195. test(renderMode + ': _jsPlumb.connect (Endpoint connectorTooltip parameter)', function() {
  1196. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1197. var e = _jsPlumb.addEndpoint(d1, {connectorTooltip:"FOO"});
  1198. var e2 = _jsPlumb.addEndpoint(d2, {});
  1199. var c = _jsPlumb.connect({target:'d2', sourceEndpoint:e, targetEndpoint:e2});
  1200. equals(c.connector.canvas.getAttribute("title"), "FOO", "connector canvas has label attribute set");
  1201. });
  1202. test(renderMode + ': _jsPlumb.connect (tooltip parameter)', function() {
  1203. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1204. var e = _jsPlumb.addEndpoint(d1, {});
  1205. var e2 = _jsPlumb.addEndpoint(d2, {});
  1206. var c = _jsPlumb.connect({target:'d2', sourceEndpoint:e, targetEndpoint:e2, tooltip:"FOO"});
  1207. equals(c.connector.canvas.getAttribute("title"), "FOO", "connector canvas has label attribute set");
  1208. });
  1209. test(renderMode + ': _jsPlumb.connect (between two Endpoints, and dont supply any parameters to the Endpoints.)', function() {
  1210. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1211. var e = _jsPlumb.addEndpoint(d1);
  1212. var e2 = _jsPlumb.addEndpoint(d2);
  1213. ok(e, 'endpoint e exists');
  1214. ok(e2, 'endpoint e2 exists');
  1215. assertContextSize(2); // should have a canvas for each endpoint now.
  1216. assertEndpointCount("d1", 1, _jsPlumb);
  1217. assertEndpointCount("d2", 1, _jsPlumb);
  1218. _jsPlumb.connect({target:'d2', sourceEndpoint:e, targetEndpoint:e2});
  1219. assertEndpointCount("d1", 1, _jsPlumb); // no new endpoint should have been added
  1220. assertEndpointCount("d2", 1, _jsPlumb); // no new endpoint should have been added
  1221. assertContextSize(3); // now we should also have a canvas for the connection.
  1222. });
  1223. test(renderMode + " : _jsPlumb.connect, passing 'anchors' array" ,function() {
  1224. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1225. c = _jsPlumb.connect({source:d1, target:d2, anchors:["LeftMiddle", "RightMiddle"]});
  1226. equals(c.endpoints[0].anchor.x, 0, "source anchor is at x=0");
  1227. equals(c.endpoints[0].anchor.y, 0.5, "source anchor is at y=0.5");
  1228. equals(c.endpoints[1].anchor.x, 1, "target anchor is at x=1");
  1229. equals(c.endpoints[1].anchor.y, 0.5, "target anchor is at y=0.5");
  1230. });
  1231. test(renderMode + ': _jsPlumb.connect (by endpoint)', function() {
  1232. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1233. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true});
  1234. ok(e16.anchor, 'endpoint 16 has an anchor');
  1235. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true});
  1236. _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  1237. assertContextSize(3);
  1238. });
  1239. test(renderMode + ': _jsPlumb.connect (cost)', function() {
  1240. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1241. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true});
  1242. ok(e16.anchor, 'endpoint 16 has an anchor');
  1243. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true});
  1244. var c = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17, cost:567});
  1245. assertContextSize(3);
  1246. equals(c.getCost(), 567, "connection cost is 567");
  1247. });
  1248. test(renderMode + ': _jsPlumb.connect (default cost)', function() {
  1249. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1250. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true});
  1251. ok(e16.anchor, 'endpoint 16 has an anchor');
  1252. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true});
  1253. var c = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  1254. assertContextSize(3);
  1255. equals(c.getCost(), undefined, "default connection cost is 1");
  1256. });
  1257. test(renderMode + ': _jsPlumb.connect (set cost)', function() {
  1258. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1259. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true});
  1260. ok(e16.anchor, 'endpoint 16 has an anchor');
  1261. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true});
  1262. var c = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  1263. assertContextSize(3);
  1264. equals(c.getCost(), undefined, "default connection cost is 1");
  1265. c.setCost(8989);
  1266. equals(c.getCost(), 8989, "connection cost is 8989");
  1267. });
  1268. test(renderMode + ': _jsPlumb.connect two endpoints (connectionCost)', function() {
  1269. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1270. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true, connectionCost:567});
  1271. ok(e16.anchor, 'endpoint 16 has an anchor');
  1272. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true});
  1273. var c = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  1274. assertContextSize(3);
  1275. equals(c.getCost(), 567, "connection cost is 567");
  1276. });
  1277. test(renderMode + ': _jsPlumb.connect two endpoints (change connectionCost)', function() {
  1278. var d16 = _addDiv("d16"), d17 = _addDiv("d17"),
  1279. e16 = _jsPlumb.addEndpoint(d16, {isSource:true, connectionCost:567, maxConnections:-1}),
  1280. e17 = _jsPlumb.addEndpoint(d17, {isSource:true, maxConnections:-1});
  1281. c = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  1282. assertContextSize(3);
  1283. equals(c.getCost(), 567, "connection cost is 567");
  1284. e16.setConnectionCost(23);
  1285. var c2 = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  1286. equals(c2.getCost(), 23, "connection cost is 23 after change on endpoint");
  1287. });
  1288. test(renderMode + ': _jsPlumb.connect (default bidirectional)', function() {
  1289. var d16 = _addDiv("d16"), d17 = _addDiv("d17"),
  1290. e16 = _jsPlumb.addEndpoint(d16, {isSource:true}),
  1291. e17 = _jsPlumb.addEndpoint(d17, {isSource:true}),
  1292. c = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  1293. assertContextSize(3);
  1294. equals(c.isBidirectional(), true, "default connection is bidirectional");
  1295. });
  1296. test(renderMode + ': _jsPlumb.connect (bidirectional false)', function() {
  1297. var d16 = _addDiv("d16"), d17 = _addDiv("d17"),
  1298. e16 = _jsPlumb.addEndpoint(d16, {isSource:true}),
  1299. e17 = _jsPlumb.addEndpoint(d17, {isSource:true}),
  1300. c = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17, bidirectional:false});
  1301. assertContextSize(3);
  1302. equals(c.isBidirectional(), false, "connection is not bidirectional");
  1303. });
  1304. test(renderMode + ': _jsPlumb.connect two endpoints (connectionsBidirectional)', function() {
  1305. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1306. var e16 = _jsPlumb.addEndpoint(d16, {isSource:true, connectionsBidirectional:true, maxConnections:-1});
  1307. ok(e16.anchor, 'endpoint 16 has an anchor');
  1308. var e17 = _jsPlumb.addEndpoint(d17, {isSource:true, maxConnections:-1});
  1309. var c = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  1310. assertContextSize(3);
  1311. equals(c.isBidirectional(), true, "connection is bidrectional");
  1312. });
  1313. test(renderMode + ': _jsPlumb.connect two endpoints (change connectionsBidirectional)', function() {
  1314. var d16 = _addDiv("d16"), d17 = _addDiv("d17"),
  1315. e16 = _jsPlumb.addEndpoint(d16, {isSource:true, connectionsBidirectional:true, maxConnections:-1}),
  1316. e17 = _jsPlumb.addEndpoint(d17, {isSource:true, maxConnections:-1});
  1317. c = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  1318. assertContextSize(3);
  1319. equals(c.isBidirectional(), true, "connection is bidirectional");
  1320. e16.setConnectionsBidirectional(false);
  1321. var c2 = _jsPlumb.connect({sourceEndpoint:e16, targetEndpoint:e17});
  1322. equals(c2.isBidirectional(), false, "connection is not bidirectional");
  1323. });
  1324. test(renderMode + ": _jsPlumb.connect (two Endpoints - that have been already added - by UUID)", function() {
  1325. var srcEndpointUuid = "14785937583175927504313", dstEndpointUuid = "14785937583175927534325";
  1326. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1327. var e1 = _jsPlumb.addEndpoint("d16", {isSource:true, maxConnections:-1, uuid:srcEndpointUuid});
  1328. var e2 = _jsPlumb.addEndpoint("d17", {isSource:true, maxConnections:-1, uuid:dstEndpointUuid});
  1329. _jsPlumb.connect({ uuids: [ srcEndpointUuid, dstEndpointUuid ] });
  1330. assertConnectionCount(e1, 1);
  1331. assertConnectionCount(e2, 1);
  1332. assertContextSize(3);
  1333. });
  1334. test(renderMode + ": _jsPlumb.connect (two Endpoints - that have not been already added - by UUID)", function() {
  1335. var srcEndpointUuid = "14785937583175927504313", dstEndpointUuid = "14785937583175927534325";
  1336. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1337. _jsPlumb.connect({ uuids: [ srcEndpointUuid, dstEndpointUuid ], source:d16, target:d17 });
  1338. assertContextSize(3);
  1339. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1340. var e1 = _jsPlumb.getEndpoint(srcEndpointUuid);
  1341. ok(e1 != null, "endpoint with src uuid added");
  1342. ok(e1.canvas != null);
  1343. var e2 = _jsPlumb.getEndpoint(dstEndpointUuid);
  1344. ok(e2 != null, "endpoint with target uuid added");
  1345. assertConnectionCount(e1, 1);
  1346. assertConnectionCount(e2, 1);
  1347. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1348. });
  1349. test(renderMode + ": _jsPlumb.connect (two Endpoints - that have been already added - by endpoint reference)", function() {
  1350. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1351. var e1 = _jsPlumb.addEndpoint("d16", {isSource:true, maxConnections:-1});
  1352. var e2 = _jsPlumb.addEndpoint("d17", {isSource:true, maxConnections:-1});
  1353. _jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  1354. assertContextSize(3);
  1355. assertConnectionCount(e1, 1);
  1356. assertConnectionCount(e2, 1);
  1357. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1358. });
  1359. test(renderMode + ": _jsPlumb.connect (two elements)", function() {
  1360. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1361. _jsPlumb.connect({ source:d16, target:d17 });
  1362. assertContextSize(3);
  1363. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1364. });
  1365. test(renderMode + ": _jsPlumb.connect (Connector test, straight)", function() {
  1366. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1367. var conn = _jsPlumb.connect({ source:d16, target:d17, connector:"Straight" });
  1368. assertContextSize(3);
  1369. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1370. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1371. });
  1372. test(renderMode + ": _jsPlumb.connect (Connector test, bezier, no params)", function() {
  1373. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1374. var conn = _jsPlumb.connect({ source:d16, target:d17, connector:"Bezier" });
  1375. assertContextSize(3);
  1376. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1377. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Bezier, "Bezier connector chosen for connection");
  1378. equals(conn.connector.majorAnchor, 150, "Bezier connector chose 150 curviness");
  1379. });
  1380. test(renderMode + ": _jsPlumb.connect (Connector test, bezier, curviness as int)", function() {
  1381. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1382. var conn = _jsPlumb.connect({ source:d16, target:d17, connector:["Bezier", { curviness:200 }] });
  1383. assertContextSize(3);
  1384. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1385. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Bezier, "Canvas Bezier connector chosen for connection");
  1386. equals(conn.connector.majorAnchor, 200, "Bezier connector chose 200 curviness");
  1387. });
  1388. test(renderMode + ": _jsPlumb.connect (Connector test, bezier, curviness as named option)", function() {
  1389. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1390. var conn = _jsPlumb.connect({ source:d16, target:d17, connector:["Bezier", {curviness:300}] });
  1391. assertContextSize(3);
  1392. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1393. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Bezier, "Bezier connector chosen for connection");
  1394. equals(conn.connector.majorAnchor, 300, "Bezier connector chose 300 curviness");
  1395. });
  1396. test(renderMode + ": _jsPlumb.connect (anchors registered correctly; source and target anchors given, as arrays)", function() {
  1397. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1398. var conn = _jsPlumb.connect({ source:d16, target:d17, connector:"Straight", anchors:[[0.3,0.3,1,0], [0.7,0.7,0,1]] });
  1399. assertContextSize(3);
  1400. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1401. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Canvas Straight connector chosen for connection");
  1402. equals(0.3, conn.endpoints[0].anchor.x, "source anchor x");
  1403. equals(0.3, conn.endpoints[0].anchor.y, "source anchor y");
  1404. equals(0.7, conn.endpoints[1].anchor.x, "target anchor x");
  1405. equals(0.7, conn.endpoints[1].anchor.y, "target anchor y");
  1406. });
  1407. test(renderMode + ": _jsPlumb.connect (anchors registered correctly; source and target anchors given, as strings)", function() {
  1408. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1409. var conn = _jsPlumb.connect({ source:d16, target:d17, connector:"Straight", anchors:["LeftMiddle", "RightMiddle"] });
  1410. assertContextSize(3);
  1411. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1412. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1413. equals(0, conn.endpoints[0].anchor.x, "source anchor x");
  1414. equals(0.5, conn.endpoints[0].anchor.y, "source anchor y");
  1415. equals(1, conn.endpoints[1].anchor.x, "target anchor x");
  1416. equals(0.5, conn.endpoints[1].anchor.y, "target anchor y");
  1417. });
  1418. test(renderMode + ": _jsPlumb.connect (anchors registered correctly; source and target anchors given, as arrays)", function() {
  1419. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1420. var conn = _jsPlumb.connect({ source:d16, target:d17, connector:"Straight", anchors:[[0.3,0.3,1,0], [0.7,0.7,0,1]] });
  1421. assertContextSize(3);
  1422. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1423. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1424. equals(0.3, conn.endpoints[0].anchor.x, "source anchor x");
  1425. equals(0.3, conn.endpoints[0].anchor.y, "source anchor y");
  1426. equals(0.7, conn.endpoints[1].anchor.x, "target anchor x");
  1427. equals(0.7, conn.endpoints[1].anchor.y, "target anchor y");
  1428. });
  1429. test(renderMode + ": _jsPlumb.connect (two argument method in which some data is reused across connections)", function() {
  1430. var d16 = _addDiv("d16"), d17 = _addDiv("d17"), d18 = _addDiv("d18"), d19 = _addDiv("d19");
  1431. var sharedData = { connector:"Straight", anchors:[[0.3,0.3,1,0], [0.7,0.7,0,1]] };
  1432. var conn = _jsPlumb.connect({ source:d16, target:d17}, sharedData);
  1433. var conn2 = _jsPlumb.connect({ source:d18, target:d19}, sharedData);
  1434. assertContextSize(6);
  1435. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 2, _jsPlumb);
  1436. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1437. equals(conn2.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1438. equals(0.3, conn.endpoints[0].anchor.x, "source anchor x");
  1439. equals(0.3, conn.endpoints[0].anchor.y, "source anchor y");
  1440. equals(0.7, conn.endpoints[1].anchor.x, "target anchor x");
  1441. equals(0.7, conn.endpoints[1].anchor.y, "target anchor y");
  1442. equals(0.3, conn2.endpoints[0].anchor.x, "source anchor x");
  1443. equals(0.3, conn2.endpoints[0].anchor.y, "source anchor y");
  1444. equals(0.7, conn2.endpoints[1].anchor.x, "target anchor x");
  1445. equals(0.7, conn2.endpoints[1].anchor.y, "target anchor y");
  1446. });
  1447. test(renderMode + ": _jsPlumb.connect (Connector as string test)", function() {
  1448. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1449. var conn = _jsPlumb.connect({ source:d16, target:d17, connector:"Straight" });
  1450. assertContextSize(3);
  1451. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1452. equals(conn.connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1453. });
  1454. test(renderMode + ": _jsPlumb.connect (Endpoint test)", function() {
  1455. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1456. var conn = _jsPlumb.connect({ source:d16, target:d17, endpoint:"Rectangle" });
  1457. assertContextSize(3);
  1458. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1459. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection source");
  1460. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection target");
  1461. });
  1462. test(renderMode + ": _jsPlumb.connect (Endpoint as string test)", function() {
  1463. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1464. var conn = _jsPlumb.connect({ source:d16, target:d17, endpoint:"Rectangle" });
  1465. assertContextSize(3);
  1466. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1467. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection source");
  1468. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection target");
  1469. });
  1470. test(renderMode + ": _jsPlumb.connect (Endpoints test)", function() {
  1471. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1472. var conn = _jsPlumb.connect({ source:d16, target:d17, endpoints:["Rectangle", "Dot" ] });
  1473. assertContextSize(3);
  1474. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1475. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection source");
  1476. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Dot, "Dot endpoint chosen for connection target");
  1477. });
  1478. test(renderMode + ": _jsPlumb.connect (Blank Endpoint specified via 'endpoint' param)", function() {
  1479. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1480. var conn = _jsPlumb.connect({ source:d16, target:d17, endpoint:"Blank" });
  1481. assertContextSize(3);
  1482. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1483. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Blank, "Blank endpoint chosen for connection source");
  1484. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Blank, "Blank endpoint chosen for connection target");
  1485. });
  1486. test(renderMode + ": _jsPlumb.connect (Blank Endpoint specified via 'endpoints' param)", function() {
  1487. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1488. var conn = _jsPlumb.connect({ source:d16, target:d17, endpoints:["Blank", "Blank" ] });
  1489. assertContextSize(3);
  1490. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1491. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Blank, "Blank endpoint chosen for connection source");
  1492. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Blank, "Blank endpoint chosen for connection target");
  1493. });
  1494. test(renderMode + ": _jsPlumb.connect (Endpoint as string test)", function() {
  1495. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1496. var conn = _jsPlumb.connect({ source:d16, target:d17, endpoints:["Rectangle", "Dot" ] });
  1497. assertContextSize(3);
  1498. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1499. equals(conn.endpoints[0].endpoint.constructor, jsPlumb.Endpoints[renderMode].Rectangle, "Rectangle endpoint chosen for connection source");
  1500. equals(conn.endpoints[1].endpoint.constructor, jsPlumb.Endpoints[renderMode].Dot, "Dot endpoint chosen for connection target");
  1501. });
  1502. test(renderMode + ": _jsPlumb.connect (by Endpoints, connector test)", function() {
  1503. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1504. var e16 = _jsPlumb.addEndpoint(d16, {});
  1505. var e17 = _jsPlumb.addEndpoint(d17, {});
  1506. var conn = _jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1507. assertContextSize(3);
  1508. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1509. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1510. });
  1511. test(renderMode + ": _jsPlumb.connect (by Endpoints, connector as string test)", function() {
  1512. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1513. var e16 = _jsPlumb.addEndpoint(d16, {});
  1514. var e17 = _jsPlumb.addEndpoint(d17, {});
  1515. var conn = _jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1516. assertContextSize(3);
  1517. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1518. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1519. });
  1520. test(renderMode + ": _jsPlumb.connect (by Endpoints, anchors as string test)", function() {
  1521. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1522. var a16 = "TopCenter", a17 = "BottomCenter";
  1523. var e16 = _jsPlumb.addEndpoint(d16, {anchor:a16});
  1524. var e17 = _jsPlumb.addEndpoint(d17, {anchor:a17});
  1525. var conn = _jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1526. assertContextSize(3);
  1527. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1528. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1529. equals(e16.anchor.x, 0.5, "endpoint 16 is at top center");equals(e16.anchor.y, 0, "endpoint 16 is at top center");
  1530. equals(e17.anchor.x, 0.5, "endpoint 17 is at bottom center");equals(e17.anchor.y, 1, "endpoint 17 is at bottom center");
  1531. });
  1532. test(renderMode + ": _jsPlumb.connect (by Endpoints, endpoints create anchors)", function() {
  1533. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1534. var a16 = [0,0.5,0,-1], a17 = [1,0.0,-1,-1];
  1535. var e16 = _jsPlumb.addEndpoint(d16, {anchor:a16});
  1536. var e17 = _jsPlumb.addEndpoint(d17, {anchor:a17});
  1537. var conn = _jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1538. assertContextSize(3);
  1539. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1540. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1541. equals(e16.anchor.x, a16[0]);equals(e16.anchor.y, a16[1]);
  1542. equals(e17.anchor.x, a17[0]);equals(e17.anchor.y, a17[1]);
  1543. equals(e16.anchor.getOrientation()[0], a16[2]); equals(e16.anchor.getOrientation()[1], a16[3]);
  1544. equals(e17.anchor.getOrientation()[0], a17[2]); equals(e17.anchor.getOrientation()[1], a17[3]);
  1545. });
  1546. test(renderMode + ": _jsPlumb.connect (by Endpoints, endpoints create dynamic anchors; anchors specified by 'anchor')", function() {
  1547. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1548. var e16 = _jsPlumb.addEndpoint(d16, {anchor:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1549. var e17 = _jsPlumb.addEndpoint(d17, {anchor:["TopCenter", "BottomCenter"]});
  1550. var conn = _jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1551. assertContextSize(3);
  1552. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1553. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1554. equals(e16.anchor.isDynamic, true, "Endpoint 16 has a dynamic anchor");
  1555. equals(e17.anchor.isDynamic, true, "Endpoint 17 has a dynamic anchor");
  1556. });
  1557. test(renderMode + ": _jsPlumb.connect (by Endpoints, endpoints create dynamic anchors; anchors specified by 'anchors')", function() {
  1558. var d16 = _addDiv("d16"), d17 = _addDiv("d17");
  1559. var e16 = _jsPlumb.addEndpoint(d16, {anchors:[[0,0.5,0,-1], [1,0.5,0,1]]});
  1560. var e17 = _jsPlumb.addEndpoint(d17, {anchors:["TopCenter", "BottomCenter"]});
  1561. var conn = _jsPlumb.connect({ sourceEndpoint:e16, targetEndpoint:e17, connector:"Straight" });
  1562. assertContextSize(3);
  1563. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1564. equals(e16.connections[0].connector.constructor, jsPlumb.Connectors[renderMode].Straight, "Straight connector chosen for connection");
  1565. equals(e16.anchor.isDynamic, true, "Endpoint 16 has a dynamic anchor");
  1566. equals(e17.anchor.isDynamic, true, "Endpoint 17 has a dynamic anchor");
  1567. });
  1568. test(renderMode + ": _jsPlumb.connect (connect by element, default endpoint, supplied dynamic anchors)", function() {
  1569. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1570. var anchors = [ [0.25, 0, 0, -1], [1, 0.25, 1, 0], [0.75, 1, 0, 1], [0, 0.75, -1, 0] ];
  1571. _jsPlumb.connect({source:d1, target:d2, dynamicAnchors:anchors}); // auto connect with default endpoint and provided anchors
  1572. assertContextSize(3);
  1573. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1574. assertEndpointCount("d1", 1, _jsPlumb);assertEndpointCount("d2", 1, _jsPlumb);
  1575. _jsPlumb.detach({source:d1, target:d2});
  1576. // this changed in 1.3.5, because auto generated endpoints are now removed by detach. so i added the test below this one
  1577. // to check that the deleteEndpointsOnDetach flag is honoured.
  1578. assertEndpointCount("d1", 0, _jsPlumb);assertEndpointCount("d2", 0, _jsPlumb);
  1579. assertContextSize(2);
  1580. });
  1581. test(renderMode + ": _jsPlumb.connect (connect by element, default endpoint, supplied dynamic anchors, delete on detach false)", function() {
  1582. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1583. var anchors = [ [0.25, 0, 0, -1], [1, 0.25, 1, 0], [0.75, 1, 0, 1], [0, 0.75, -1, 0] ];
  1584. _jsPlumb.connect({
  1585. source:d1,
  1586. target:d2,
  1587. dynamicAnchors:anchors,
  1588. deleteEndpointsOnDetach:false
  1589. }); // auto connect with default endpoint and provided anchors
  1590. assertContextSize(3);
  1591. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1592. assertEndpointCount("d1", 1, _jsPlumb);assertEndpointCount("d2", 1, _jsPlumb);
  1593. _jsPlumb.detach({source:d1, target:d2});
  1594. // this changed in 1.3.5, because auto generated endpoints are now removed by detach. so i added this test
  1595. // to check that the deleteEndpointsOnDetach flag is honoured.
  1596. assertEndpointCount("d1", 1, _jsPlumb);assertEndpointCount("d2", 1, _jsPlumb);
  1597. assertContextSize(2);
  1598. });
  1599. test(renderMode + ": _jsPlumb.connect (connect by element, supplied endpoint and dynamic anchors)", function() {
  1600. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1601. var endpoint = { isSource:true };
  1602. var e1 = _jsPlumb.addEndpoint(d1, endpoint);
  1603. var e2 = _jsPlumb.addEndpoint(d2, endpoint);
  1604. var anchors = [ "TopCenter", "BottomCenter" ];
  1605. _jsPlumb.connect({sourceEndpoint:e1, targetEndpoint:e2, dynamicAnchors:anchors});
  1606. assertEndpointCount("d1", 1, _jsPlumb);assertEndpointCount("d2", 1, _jsPlumb);
  1607. assertContextSize(3);
  1608. _jsPlumb.detach({source:d1, target:d2});
  1609. assertEndpointCount("d1", 1, _jsPlumb);assertEndpointCount("d2", 1, _jsPlumb);
  1610. assertContextSize(2);
  1611. });
  1612. 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() {
  1613. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1614. var endpoint = { isSource:true };
  1615. var e1 = _jsPlumb.addEndpoint(d1, endpoint);
  1616. var e2 = _jsPlumb.addEndpoint(d2, endpoint);
  1617. var anchors = [ "TopCenter", "BottomCenter" ];
  1618. _jsPlumb.connect({source:e1, target:e2, dynamicAnchors:anchors});
  1619. assertEndpointCount("d1", 1, _jsPlumb);assertEndpointCount("d2", 1, _jsPlumb);
  1620. assertContextSize(3);
  1621. _jsPlumb.detach({source:d1, target:d2});
  1622. assertEndpointCount("d1", 1, _jsPlumb);assertEndpointCount("d2", 1, _jsPlumb);
  1623. assertContextSize(2);
  1624. });
  1625. test(renderMode + " detachable parameter defaults to true on _jsPlumb.connect", function() {
  1626. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1627. c = _jsPlumb.connect({source:d1, target:d2});
  1628. equals(c.isDetachable(), true, "connections detachable by default");
  1629. });
  1630. test(renderMode + " detachable parameter set to false on _jsPlumb.connect", function() {
  1631. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1632. c = _jsPlumb.connect({source:d1, target:d2, detachable:false});
  1633. equals(c.isDetachable(), false, "connection detachable");
  1634. });
  1635. test(renderMode + " setDetachable on initially detachable connection", function() {
  1636. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1637. c = _jsPlumb.connect({source:d1, target:d2});
  1638. equals(c.isDetachable(), true, "connection initially detachable");
  1639. c.setDetachable(false);
  1640. equals(c.isDetachable(), false, "connection not detachable");
  1641. });
  1642. test(renderMode + " setDetachable on initially not detachable connection", function() {
  1643. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1644. c = _jsPlumb.connect({source:d1, target:d2, detachable:false });
  1645. equals(c.isDetachable(), false, "connection not initially detachable");
  1646. c.setDetachable(true);
  1647. equals(c.isDetachable(), true, "connection now detachable");
  1648. });
  1649. test(renderMode + " _jsPlumb.Defaults.ConnectionsDetachable", function() {
  1650. _jsPlumb.Defaults.ConnectionsDetachable = false;
  1651. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1652. c = _jsPlumb.connect({source:d1, target:d2});
  1653. equals(c.isDetachable(), false, "connections not detachable by default (overrode the defaults)");
  1654. _jsPlumb.Defaults.ConnectionsDetachable = true;
  1655. });
  1656. test(renderMode + ": _jsPlumb.connect (testing for connection event callback)", function() {
  1657. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1658. var connectCallback = null, detachCallback = null;
  1659. _jsPlumb.bind("jsPlumbConnection", function(params) {
  1660. connectCallback = $.extend({}, params);
  1661. });
  1662. _jsPlumb.bind("jsPlumbConnectionDetached", function(params) {
  1663. detachCallback = $.extend({}, params);
  1664. });
  1665. _jsPlumb.connect({source:d1, target:d2}); // auto connect with default endpoint and anchor set
  1666. ok(connectCallback != null, "connect callback was made");
  1667. assertContextSize(3);
  1668. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  1669. assertEndpointCount("d1", 1, _jsPlumb);assertEndpointCount("d2", 1, _jsPlumb);
  1670. _jsPlumb.detach({source:d1, target:d2});
  1671. assertContextSize(2);
  1672. ok(detachCallback != null, "detach callback was made");
  1673. });
  1674. test(renderMode + ": _jsPlumb.connect (setting cssClass on Connector)", function() {
  1675. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1676. var c = _jsPlumb.connect({source:d1,target:d2,cssClass:"CSS"});
  1677. var has = function(clazz) {
  1678. var cn = c.connector.canvas.className,
  1679. cns = cn.constructor == String ? cn : cn.baseVal;
  1680. return cns.indexOf(clazz) != -1;
  1681. };
  1682. ok(has("CSS"), "custom cssClass set correctly");
  1683. ok(has(_jsPlumb.connectorClass), "basic connector class set correctly");
  1684. });
  1685. test(renderMode + ": _jsPlumb.connect (overlays, long-hand version)", function() {
  1686. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1687. var imageEventListener = function() { };
  1688. var arrowSpec = {width:40,length:40,location:0.7, foldback:0, paintStyle:{lineWidth:1, strokeStyle:"#000000"}};
  1689. var connection1 = _jsPlumb.connect({
  1690. source:d1,
  1691. target:d2,
  1692. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1693. overlays : [ ["Label",{label:"CONNECTION 1", location:0.3}],
  1694. ["Arrow",arrowSpec ] ]
  1695. });
  1696. equals(2, connection1.overlays.length);
  1697. equals(jsPlumb.Overlays[renderMode].Label, connection1.overlays[0].constructor);
  1698. equals(jsPlumb.Overlays[renderMode].Arrow, connection1.overlays[1].constructor);
  1699. equals(0.7, connection1.overlays[1].loc);
  1700. equals(40, connection1.overlays[1].width);
  1701. equals(40, connection1.overlays[1].length);
  1702. });
  1703. test(renderMode + ": _jsPlumb.connect (overlays, long-hand version, IDs specified)", function() {
  1704. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1705. var imageEventListener = function() { };
  1706. var arrowSpec = {
  1707. width:40,
  1708. length:40,
  1709. location:0.7,
  1710. foldback:0,
  1711. paintStyle:{lineWidth:1, strokeStyle:"#000000"},
  1712. id:"anArrow"
  1713. };
  1714. var connection1 = _jsPlumb.connect({
  1715. source:d1,
  1716. target:d2,
  1717. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1718. overlays : [ ["Label",{label:"CONNECTION 1", location:0.3, id:"aLabel"}],
  1719. ["Arrow",arrowSpec ] ]
  1720. });
  1721. equals(2, connection1.overlays.length);
  1722. equals(jsPlumb.Overlays[renderMode].Label, connection1.overlays[0].constructor);
  1723. equals("aLabel", connection1.overlays[0].id);
  1724. equals(jsPlumb.Overlays[renderMode].Arrow, connection1.overlays[1].constructor);
  1725. equals(0.7, connection1.overlays[1].loc);
  1726. equals(40, connection1.overlays[1].width);
  1727. equals(40, connection1.overlays[1].length);
  1728. equals("anArrow", connection1.overlays[1].id);
  1729. });
  1730. test(renderMode + ": _jsPlumb.connect (default overlays)", function() {
  1731. _jsPlumb.Defaults.Overlays = [
  1732. ["Arrow",{ location:0.1, id:"arrow" }]
  1733. ];
  1734. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1735. c = _jsPlumb.connect({source:d1, target:d2});
  1736. ok(c.getOverlay("arrow") != null, "Arrow overlay created from defaults");
  1737. });
  1738. test(renderMode + ": _jsPlumb.connect (default overlays + overlays specified in connect call)", function() {
  1739. _jsPlumb.Defaults.Overlays = [
  1740. ["Arrow",{ location:0.1, id:"arrow" }]
  1741. ];
  1742. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1743. c = _jsPlumb.connect({source:d1, target:d2, overlays:[
  1744. ["Label", {id:"label"}]
  1745. ]});
  1746. ok(c.getOverlay("arrow") != null, "Arrow overlay created from defaults");
  1747. ok(c.getOverlay("label") != null, "Label overlay created from connect call");
  1748. });
  1749. test(renderMode + ": _jsPlumb.connect (default connection overlays)", function() {
  1750. _jsPlumb.Defaults.ConnectionOverlays = [
  1751. ["Arrow",{ location:0.1, id:"arrow" }]
  1752. ];
  1753. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1754. c = _jsPlumb.connect({source:d1, target:d2});
  1755. ok(c.getOverlay("arrow") != null, "Arrow overlay created from defaults");
  1756. });
  1757. test(renderMode + ": _jsPlumb.connect (default connection overlays + overlays specified in connect call)", function() {
  1758. _jsPlumb.Defaults.ConnectionOverlays = [
  1759. ["Arrow",{ location:0.1, id:"arrow" }]
  1760. ];
  1761. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1762. c = _jsPlumb.connect({source:d1, target:d2, overlays:[
  1763. ["Label", {id:"label"}]
  1764. ]});
  1765. ok(c.getOverlay("arrow") != null, "Arrow overlay created from defaults");
  1766. ok(c.getOverlay("label") != null, "Label overlay created from connect call");
  1767. });
  1768. test(renderMode + ": _jsPlumb.connect (default overlays + default connection overlays)", function() {
  1769. _jsPlumb.Defaults.ConnectionOverlays = [
  1770. ["Arrow",{ location:0.1, id:"arrow" }]
  1771. ];
  1772. _jsPlumb.Defaults.Overlays = [
  1773. ["Arrow",{ location:0.1, id:"arrow2" }]
  1774. ];
  1775. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1776. c = _jsPlumb.connect({source:d1, target:d2});
  1777. ok(c.getOverlay("arrow") != null, "Arrow overlay created from defaults");
  1778. ok(c.getOverlay("arrow2") != null, "Arrow overlay created from connection defaults");
  1779. });
  1780. test(renderMode + ": _jsPlumb.connect (default overlays + default connection overlays)", function() {
  1781. _jsPlumb.Defaults.ConnectionOverlays = [
  1782. ["Arrow",{ location:0.1, id:"arrow" }]
  1783. ];
  1784. _jsPlumb.Defaults.Overlays = [
  1785. ["Arrow",{ location:0.1, id:"arrow2" }]
  1786. ];
  1787. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1788. c = _jsPlumb.connect({source:d1, target:d2, overlays:[
  1789. ["Label", {id:"label"}]
  1790. ]});
  1791. ok(c.getOverlay("arrow") != null, "Arrow overlay created from defaults");
  1792. ok(c.getOverlay("arrow2") != null, "Arrow overlay created from connection defaults");
  1793. ok(c.getOverlay("label") != null, "Label overlay created from connect call");
  1794. });
  1795. test(renderMode + ": _jsPlumb.connect (label overlay set using 'label')", function() {
  1796. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1797. c = _jsPlumb.connect({
  1798. source:d1,
  1799. target:d2,
  1800. label:"FOO"
  1801. });
  1802. equals(c.getLabel(), "FOO", "label is set correctly");
  1803. });
  1804. test(renderMode + ": _jsPlumb.connect (set label after construction, with string)", function() {
  1805. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1806. c = _jsPlumb.connect({
  1807. source:d1,
  1808. target:d2});
  1809. c.setLabel("FOO");
  1810. equals(c.getLabel(), "FOO", "label is set correctly");
  1811. });
  1812. test(renderMode + ": _jsPlumb.connect (set label after construction, with function)", function() {
  1813. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1814. c = _jsPlumb.connect({
  1815. source:d1,
  1816. target:d2});
  1817. c.setLabel(function() { return "BAR"; });
  1818. equals(c.getLabel()(), "BAR", "label is set correctly");
  1819. });
  1820. test(renderMode + ": _jsPlumb.connect (set label after construction, with params object)", function() {
  1821. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1822. c = _jsPlumb.connect({
  1823. source:d1,
  1824. target:d2});
  1825. c.setLabel({
  1826. label:"BAZ",
  1827. cssClass:"CLASSY",
  1828. location:0.9
  1829. });
  1830. var lo = c.getLabelOverlay();
  1831. ok(lo != null, "label overlay exists");
  1832. equals(lo.getLabel(), "BAZ", "label overlay has correct value");
  1833. equals(lo.getLocation(), 0.9, "label overlay has correct location");
  1834. });
  1835. test(renderMode + ": _jsPlumb.connect (set label after construction with existing label set, with params object)", function() {
  1836. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1837. c = _jsPlumb.connect({
  1838. source:d1,
  1839. target:d2,
  1840. label:"FOO",
  1841. labelLocation:0.2
  1842. });
  1843. var lo = c.getLabelOverlay();
  1844. equals(lo.getLocation(), 0.2, "label overlay has correct location");
  1845. c.setLabel({
  1846. label:"BAZ",
  1847. cssClass:"CLASSY",
  1848. location:0.9
  1849. });
  1850. ok(lo != null, "label overlay exists");
  1851. equals(lo.getLabel(), "BAZ", "label overlay has correct value");
  1852. equals(lo.getLocation(), 0.9, "label overlay has correct location");
  1853. });
  1854. test(renderMode + ": _jsPlumb.connect (getLabelOverlay, label on connect call)", function() {
  1855. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1856. c = _jsPlumb.connect({
  1857. source:d1,
  1858. target:d2,
  1859. label:"FOO"
  1860. }),
  1861. lo = c.getLabelOverlay();
  1862. ok(lo != null, "label overlay exists");
  1863. equals(lo.getLabel(), "FOO", "label overlay has correct value");
  1864. equals(lo.getLocation(), 0.5, "label overlay has correct location");
  1865. });
  1866. test(renderMode + ": _jsPlumb.connect (getLabelOverlay, label on connect call, location set)", function() {
  1867. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  1868. c = _jsPlumb.connect({
  1869. source:d1,
  1870. target:d2,
  1871. label:"FOO",
  1872. labelLocation:0.2
  1873. }),
  1874. lo = c.getLabelOverlay();
  1875. ok(lo != null, "label overlay exists");
  1876. equals(lo.getLabel(), "FOO", "label overlay has correct value");
  1877. equals(lo.getLocation(), 0.2, "label overlay has correct location");
  1878. });
  1879. test(renderMode + ": _jsPlumb.connect (remove single overlay by id)", function() {
  1880. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1881. var arrowSpec = {
  1882. width:40,
  1883. length:40,
  1884. location:0.7,
  1885. foldback:0,
  1886. paintStyle:{lineWidth:1, strokeStyle:"#000000"},
  1887. id:"anArrow"
  1888. };
  1889. var connection1 = _jsPlumb.connect({
  1890. source:d1,
  1891. target:d2,
  1892. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1893. overlays : [ ["Label",{label:"CONNECTION 1", location:0.3, id:"aLabel"}],
  1894. ["Arrow",arrowSpec ] ]
  1895. });
  1896. equals(2, connection1.overlays.length);
  1897. connection1.removeOverlay("aLabel");
  1898. equals(1, connection1.overlays.length);
  1899. equals("anArrow", connection1.overlays[0].id);
  1900. });
  1901. test(renderMode + ": _jsPlumb.connect (remove multiple overlays by id)", function() {
  1902. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1903. var arrowSpec = {
  1904. width:40,
  1905. length:40,
  1906. location:0.7,
  1907. foldback:0,
  1908. paintStyle:{lineWidth:1, strokeStyle:"#000000"},
  1909. id:"anArrow"
  1910. };
  1911. var connection1 = _jsPlumb.connect({
  1912. source:d1,
  1913. target:d2,
  1914. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1915. overlays : [ ["Label",{label:"CONNECTION 1", location:0.3, id:"aLabel"}],
  1916. ["Arrow",arrowSpec ] ]
  1917. });
  1918. equals(2, connection1.overlays.length);
  1919. connection1.removeOverlays("aLabel", "anArrow");
  1920. equals(0, connection1.overlays.length);
  1921. });
  1922. test(renderMode + ": _jsPlumb.connect (overlays, short-hand version)", function() {
  1923. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1924. var imageEventListener = function() { };
  1925. var loc = { location:0.7 };
  1926. var arrowSpec = { width:40,length:40, foldback:0, paintStyle:{lineWidth:1, strokeStyle:"#000000"} };
  1927. var connection1 = _jsPlumb.connect({
  1928. source:d1,
  1929. target:d2,
  1930. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1931. overlays : [ ["Label", {label:"CONNECTION 1", location:0.3}],
  1932. ["Arrow", arrowSpec, loc] ]
  1933. });
  1934. equals(2, connection1.overlays.length);
  1935. equals(jsPlumb.Overlays[renderMode].Label, connection1.overlays[0].constructor);
  1936. equals(jsPlumb.Overlays[renderMode].Arrow, connection1.overlays[1].constructor);
  1937. equals(0.7, connection1.overlays[1].loc);
  1938. equals(40, connection1.overlays[1].width);
  1939. equals(40, connection1.overlays[1].length);
  1940. });
  1941. test(renderMode + ": _jsPlumb.connect (removeAllOverlays)", function() {
  1942. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1943. var imageEventListener = function() { };
  1944. var loc = { location:0.7 };
  1945. var arrowSpec = { width:40,length:40, foldback:0, paintStyle:{lineWidth:1, strokeStyle:"#000000"} };
  1946. var connection1 = _jsPlumb.connect({
  1947. source:d1,
  1948. target:d2,
  1949. anchors:["BottomCenter", [ 0.75,0,0,-1 ]],
  1950. overlays : [ ["Label", {label:"CONNECTION 1", location:0.3}],
  1951. ["Arrow", arrowSpec, loc] ]
  1952. });
  1953. equals(2, connection1.overlays.length);
  1954. equals(jsPlumb.Overlays[renderMode].Label, connection1.overlays[0].constructor);
  1955. equals(jsPlumb.Overlays[renderMode].Arrow, connection1.overlays[1].constructor);
  1956. equals(0.7, connection1.overlays[1].loc);
  1957. equals(40, connection1.overlays[1].width);
  1958. equals(40, connection1.overlays[1].length);
  1959. connection1.removeAllOverlays();
  1960. equals(0, connection1.overlays.length);
  1961. });
  1962. test(renderMode + ": _jsPlumb.connect, specify arrow overlay using string identifier only", function() {
  1963. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  1964. var conn = _jsPlumb.connect({source:d1,target:d2,overlays:["Arrow"]});
  1965. equals(jsPlumb.Overlays[renderMode].Arrow, conn.overlays[0].constructor);
  1966. });
  1967. test(renderMode + ": Connection.getOverlay method, existing overlay", function() {
  1968. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1969. var conn = _jsPlumb.connect({source:d1,target:d2,overlays:[ [ "Arrow", { id:"arrowOverlay" } ] ] });
  1970. var overlay = conn.getOverlay("arrowOverlay");
  1971. ok(overlay != null);
  1972. });
  1973. test(renderMode + ": Connection.getOverlay method, non-existent overlay", function() {
  1974. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1975. var conn = _jsPlumb.connect({source:d1,target:d2,overlays:[ [ "Arrow", { id:"arrowOverlay" } ] ] });
  1976. var overlay = conn.getOverlay("IDONTEXIST");
  1977. ok(overlay == null);
  1978. });
  1979. test(renderMode + ": Overlay.setVisible method", function() {
  1980. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1981. var conn = _jsPlumb.connect({source:d1,target:d2,overlays:[ [ "Arrow", { id:"arrowOverlay" } ] ] });
  1982. var overlay = conn.getOverlay("arrowOverlay");
  1983. ok(overlay.isVisible());
  1984. overlay.setVisible(false);
  1985. ok(!overlay.isVisible());
  1986. overlay.setVisible(true);
  1987. ok(overlay.isVisible());
  1988. });
  1989. // this test is for the original detach function; it should stay working after i mess with it
  1990. // a little.
  1991. test(renderMode + ": _jsPlumb.detach (by element ids)", function() {
  1992. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  1993. var e1 = _jsPlumb.addEndpoint(d1);
  1994. var e2 = _jsPlumb.addEndpoint(d2);
  1995. var e3 = _jsPlumb.addEndpoint(d1);
  1996. var e4 = _jsPlumb.addEndpoint(d2);
  1997. _jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  1998. _jsPlumb.connect({ sourceEndpoint:e3, targetEndpoint:e4 }); // make two connections to be sure this works ;)
  1999. assertConnectionCount(e1, 1);
  2000. assertConnectionCount(e2, 1);
  2001. assertConnectionCount(e3, 1);
  2002. assertConnectionCount(e4, 1);
  2003. _jsPlumb.detach({source:"d1", target:"d2"});
  2004. assertConnectionCount(e1, 0);
  2005. assertConnectionCount(e2, 0);
  2006. assertConnectionCount(e3, 0);
  2007. assertConnectionCount(e4, 0);
  2008. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 0, _jsPlumb);
  2009. });
  2010. // detach is being made to operate more like connect - by taking one argument with a whole
  2011. // bunch of possible params in it. if two args are passed in it will continue working
  2012. // in the old way.
  2013. test(renderMode + ": _jsPlumb.detach (params object, using element ids)", function() {
  2014. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2015. var e1 = _jsPlumb.addEndpoint(d1);
  2016. var e2 = _jsPlumb.addEndpoint(d2);
  2017. _jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  2018. assertConnectionCount(e1, 1);
  2019. assertConnectionCount(e2, 1);
  2020. _jsPlumb.detach({source:"d1", target:"d2"});
  2021. assertConnectionCount(e1, 0);
  2022. assertConnectionCount(e2, 0);
  2023. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 0, _jsPlumb);
  2024. });
  2025. /*
  2026. test(renderMode + ": _jsPlumb.detach (params object, using target only)", function() {
  2027. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3"),
  2028. e1 = _jsPlumb.addEndpoint(d1, {maxConnections:2}),
  2029. e2 = _jsPlumb.addEndpoint(d2),
  2030. e3 = _jsPlumb.addEndpoint(d3);
  2031. _jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  2032. _jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e3 });
  2033. assertConnectionCount(e1, 2);
  2034. assertConnectionCount(e2, 1);
  2035. assertConnectionCount(e3, 1);
  2036. _jsPlumb.detach({target:"d2"});
  2037. assertConnectionCount(e1, 1);
  2038. assertConnectionCount(e2, 0);
  2039. assertConnectionCount(e3, 1);
  2040. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1);
  2041. });
  2042. */
  2043. test(renderMode + ": _jsPlumb.detach (params object, using element objects)", function() {
  2044. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2045. var e1 = _jsPlumb.addEndpoint(d1);
  2046. var e2 = _jsPlumb.addEndpoint(d2);
  2047. _jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  2048. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  2049. assertContextSize(3);
  2050. assertConnectionCount(e1, 1);
  2051. assertConnectionCount(e2, 1);
  2052. _jsPlumb.detach({source:d1, target:d2});
  2053. assertConnectionCount(e1, 0);
  2054. assertConnectionCount(e2, 0);
  2055. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 0, _jsPlumb);
  2056. assertContextSize(2);
  2057. });
  2058. test(renderMode + ": _jsPlumb.detach (source and target as endpoint UUIDs)", function() {
  2059. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2060. var e1 = _jsPlumb.addEndpoint(d1, {uuid:"abcdefg"});
  2061. ok(_jsPlumb.getEndpoint("abcdefg") != null, "e1 exists");
  2062. var e2 = _jsPlumb.addEndpoint(d2, {uuid:"hijklmn"});
  2063. ok(_jsPlumb.getEndpoint("hijklmn") != null, "e2 exists");
  2064. _jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  2065. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  2066. assertContextSize(3);
  2067. assertConnectionCount(e1, 1);
  2068. assertConnectionCount(e2, 1);
  2069. _jsPlumb.detach({uuids:["abcdefg", "hijklmn"]});
  2070. assertConnectionCount(e1, 0);
  2071. assertConnectionCount(e2, 0);
  2072. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 0, _jsPlumb);
  2073. assertContextSize(2);
  2074. });
  2075. test(renderMode + ": _jsPlumb.detach (sourceEndpoint and targetEndpoint supplied)", function() {
  2076. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2077. var e1 = _jsPlumb.addEndpoint(d1);
  2078. var e2 = _jsPlumb.addEndpoint(d2);
  2079. _jsPlumb.connect({ sourceEndpoint:e1, targetEndpoint:e2 });
  2080. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 1, _jsPlumb);
  2081. assertContextSize(3);
  2082. assertConnectionCount(e1, 1);
  2083. assertConnectionCount(e2, 1);
  2084. _jsPlumb.detach({ sourceEndpoint:e1, targetEndpoint:e2 });
  2085. assertConnectionCount(e1, 0);
  2086. assertConnectionCount(e2, 0);
  2087. assertConnectionByScopeCount(_jsPlumb.getDefaultScope(), 0, _jsPlumb);
  2088. assertContextSize(2);
  2089. });
  2090. test(renderMode + ": _jsPlumb.makeDynamicAnchors (longhand)", function() {
  2091. var anchors = [_jsPlumb.makeAnchor([0.2, 0, 0, -1], null, _jsPlumb), _jsPlumb.makeAnchor([1, 0.2, 1, 0], null, _jsPlumb),
  2092. _jsPlumb.makeAnchor([0.8, 1, 0, 1], null, _jsPlumb), _jsPlumb.makeAnchor([0, 0.8, -1, 0], null, _jsPlumb) ];
  2093. var dynamicAnchor = _jsPlumb.makeDynamicAnchor(anchors);
  2094. var a = dynamicAnchor.getAnchors();
  2095. equals(a.length, 4, "Dynamic Anchors has four anchors");
  2096. for (var i = 0; i < a.length; i++)
  2097. ok(a[i].compute.constructor == Function, "anchor " + i + " well formed");
  2098. });
  2099. test(renderMode + ": _jsPlumb.makeDynamicAnchors (shorthand)", function() {
  2100. var anchors = [[0.2, 0, 0, -1], [1, 0.2, 1, 0],
  2101. [0.8, 1, 0, 1], [0, 0.8, -1, 0] ];
  2102. var dynamicAnchor = _jsPlumb.makeDynamicAnchor(anchors);
  2103. var a = dynamicAnchor.getAnchors();
  2104. equals(a.length, 4, "Dynamic Anchors has four anchors");
  2105. for (var i = 0; i < a.length; i++)
  2106. ok(a[i].compute.constructor == Function, "anchor " + i + " well formed");
  2107. });
  2108. test(renderMode + ": Connection.isVisible/setVisible", function() {
  2109. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2110. var c1 = _jsPlumb.connect({source:d1,target:d2});
  2111. equals(true, c1.isVisible(), "Connection is visible after creation.");
  2112. c1.setVisible(false);
  2113. equals(false, c1.isVisible(), "Connection is not visible after calling setVisible(false).");
  2114. equals($(c1.connector.canvas).css("display"), "none");
  2115. c1.setVisible(true);
  2116. equals(true, c1.isVisible(), "Connection is visible after calling setVisible(true).");
  2117. equals($(c1.connector.canvas).css("display"), "block");
  2118. });
  2119. test(renderMode + ": Endpoint.isVisible/setVisible basic test (no connections)", function() {
  2120. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2121. var e1 = _jsPlumb.addEndpoint(d1);
  2122. equals(true, e1.isVisible(), "Endpoint is visible after creation.");
  2123. e1.setVisible(false);
  2124. equals(false, e1.isVisible(), "Endpoint is not visible after calling setVisible(false).");
  2125. equals($(e1.canvas).css("display"), "none");
  2126. e1.setVisible(true);
  2127. equals(true, e1.isVisible(), "Endpoint is visible after calling setVisible(true).");
  2128. equals($(e1.canvas).css("display"), "block");
  2129. });
  2130. test(renderMode + ": Endpoint.isVisible/setVisible (one connection, other Endpoint's visibility should track changes in the source, because it has only this connection.)", function() {
  2131. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2132. var e1 = _jsPlumb.addEndpoint(d1), e2 = _jsPlumb.addEndpoint(d2);
  2133. equals(true, e1.isVisible(), "Endpoint is visible after creation.");
  2134. var c1 = _jsPlumb.connect({source:e1, target:e2});
  2135. e1.setVisible(false);
  2136. equals(false, e1.isVisible(), "Endpoint is not visible after calling setVisible(false).");
  2137. equals(false, e2.isVisible(), "other Endpoint is not visible either.");
  2138. equals(false, c1.isVisible(), "connection between the two is not visible either.");
  2139. e1.setVisible(true);
  2140. equals(true, e1.isVisible(), "Endpoint is visible after calling setVisible(true).");
  2141. equals(true, e2.isVisible(), "other Endpoint is visible too");
  2142. equals(true, c1.isVisible(), "connection between the two is visible too.");
  2143. });
  2144. test(renderMode + ": Endpoint.isVisible/setVisible (one connection, other Endpoint's visibility should not track changes in the source, because it has another connection.)", function() {
  2145. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  2146. var e1 = _jsPlumb.addEndpoint(d1), e2 = _jsPlumb.addEndpoint(d2, { maxConnections:2 }), e3 = _jsPlumb.addEndpoint(d3);
  2147. equals(true, e1.isVisible(), "Endpoint is visible after creation.");
  2148. var c1 = _jsPlumb.connect({source:e1, target:e2});
  2149. var c2 = _jsPlumb.connect({source:e2, target:e3});
  2150. e1.setVisible(false);
  2151. equals(false, e1.isVisible(), "Endpoint is not visible after calling setVisible(false).");
  2152. equals(true, e2.isVisible(), "other Endpoint should still be visible.");
  2153. equals(true, e3.isVisible(), "third Endpoint should still be visible.");
  2154. equals(false, c1.isVisible(), "connection between the two is not visible either.");
  2155. equals(true, c2.isVisible(), "other connection is visible.");
  2156. e1.setVisible(true);
  2157. equals(true, e1.isVisible(), "Endpoint is visible after calling setVisible(true).");
  2158. equals(true, e2.isVisible(), "other Endpoint is visible too");
  2159. equals(true, c1.isVisible(), "connection between the two is visible too.");
  2160. equals(true, c2.isVisible(), "other connection is visible.");
  2161. });
  2162. // tests of the functionality that allows a user to specify that they want elements appended to the document body
  2163. test(renderMode + " _jsPlumb.Defaults.Container, specified with a selector", function() {
  2164. _jsPlumb.Defaults.Container = $("body");
  2165. equals($("#container")[0].childNodes.length, 0, "container has no nodes");
  2166. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2167. equals($("#container")[0].childNodes.length, 2, "container has two div elements"); // the divs we added have been added to the 'container' div.
  2168. // 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:
  2169. _jsPlumb.connect({source:d1, target:d2});
  2170. equals($("#container")[0].childNodes.length, 2, "container still has two div elements");
  2171. });
  2172. // tests of the functionality that allows a user to specify that they want elements appended to some specific container.
  2173. test(renderMode + " _jsPlumb.Defaults.Container, specified with DOM element", function() {
  2174. _jsPlumb.Defaults.Container = document.getElementsByTagName("body")[0];
  2175. equals(0, $("#container")[0].childNodes.length);
  2176. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2177. equals(2, $("#container")[0].childNodes.length, "two divs added to the container"); // the divs we added have been added to the 'container' div.
  2178. // 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:
  2179. var bodyElementCount = $("body")[0].childNodes.length;
  2180. _jsPlumb.connect({source:d1, target:d2});
  2181. equals(2, $("#container")[0].childNodes.length, "still only two children in container; elements were added to the body by _jsPlumb");
  2182. // test to see if 3 elements have been added
  2183. equals(bodyElementCount + 3, $("body")[0].childNodes.length, "3 new elements added to the document body");
  2184. });
  2185. test(renderMode + " container specified to connect call, with a selector", function() {
  2186. equals(0, $("#container")[0].childNodes.length);
  2187. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2188. equals(2, $("#container")[0].childNodes.length); // the divs we added have been added to the 'container' div.
  2189. var bodyElementCount = $("body")[0].childNodes.length;
  2190. // 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:
  2191. _jsPlumb.connect({source:d1, target:d2, container:$("body")});
  2192. equals(2, $("#container")[0].childNodes.length);
  2193. equals(bodyElementCount + 3, $("body")[0].childNodes.length, "3 new elements added to the document body");
  2194. });
  2195. test(renderMode + " container specified to connect call, with a string ID", function() {
  2196. equals(0, $("#container")[0].childNodes.length);
  2197. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  2198. equals(3, $("#container")[0].childNodes.length, "container has divs we added"); // the divs we added have been added to the 'container' div.
  2199. var d3ElementCount = $("#d3")[0].childNodes.length;
  2200. // but here we tell _jsPlumb to add its elements to "d3", so this connect call should not add another few elements to the container:
  2201. _jsPlumb.connect({source:d1, target:d2, container:"d3"});
  2202. equals(3, $("#container")[0].childNodes.length, "container still has only the divs we added");
  2203. equals(d3ElementCount + 3, $("#d3")[0].childNodes.length, "3 new elements added to div d3");
  2204. });
  2205. test(renderMode + " container specified to addEndpoint call, with a selector", function() {
  2206. equals(0, $("#container")[0].childNodes.length);
  2207. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2208. equals(2, $("#container")[0].childNodes.length); // the divs we added have been added to the 'container' div.
  2209. var bodyElementCount = $("body")[0].childNodes.length;
  2210. // 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:
  2211. _jsPlumb.addEndpoint(d1, {container:$("body")});
  2212. equals(2, $("#container")[0].childNodes.length);
  2213. equals(bodyElementCount + 1, $("body")[0].childNodes.length, "1 new element added to the document body");
  2214. });
  2215. test(renderMode + " container specified to addEndpoint call, with a string ID", function() {
  2216. equals(0, $("#container")[0].childNodes.length);
  2217. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3");
  2218. equals(3, $("#container")[0].childNodes.length, "container has divs we added"); // the divs we added have been added to the 'container' div.
  2219. var d3ElementCount = $("#d3")[0].childNodes.length;
  2220. // but here we tell _jsPlumb to add its elements to "d3", so this connect call should not add another few elements to the container:
  2221. _jsPlumb.addEndpoint(d1, { container:"d3" });
  2222. equals(3, $("#container")[0].childNodes.length, "container still has only the divs we added");
  2223. equals(d3ElementCount + 1, $("#d3")[0].childNodes.length, "1 new element added to div d3");
  2224. });
  2225. test(renderMode + " detachable defaults to true when connection made between two endpoints", function() {
  2226. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  2227. e1 = _jsPlumb.addEndpoint(d1), e2 = _jsPlumb.addEndpoint(d2),
  2228. c = _jsPlumb.connect({source:e1, target:e2});
  2229. equals(c.isDetachable(), true, "connection not detachable");
  2230. });
  2231. test(renderMode + " connection detachable when target endpoint has connectionsDetachable set to true", function() {
  2232. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  2233. e1 = _jsPlumb.addEndpoint(d1), e2 = _jsPlumb.addEndpoint(d2, {connectionsDetachable:true}),
  2234. c = _jsPlumb.connect({source:e1, target:e2});
  2235. equals(c.isDetachable(), true, "connection detachable because connectionsDetachable was set on target endpoint");
  2236. });
  2237. test(renderMode + " connection detachable when source endpoint has connectionsDetachable set to true", function() {
  2238. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  2239. e1 = _jsPlumb.addEndpoint(d1, {connectionsDetachable:true}), e2 = _jsPlumb.addEndpoint(d2),
  2240. c = _jsPlumb.connect({source:e1, target:e2});
  2241. equals(c.isDetachable(), true, "connection detachable because connectionsDetachable was set on source endpoint");
  2242. });
  2243. test(renderMode + " Connector has 'type' member set", function() {
  2244. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2245. var c = _jsPlumb.connect({source:d1, target:d2});
  2246. equals(c.connector.type, "Bezier", "Bezier connector has type set");
  2247. var c2 = _jsPlumb.connect({source:d1, target:d2, connector:"Straight"});
  2248. equals(c2.connector.type, "Straight", "Straight connector has type set");
  2249. var c3 = _jsPlumb.connect({source:d1, target:d2, connector:"Flowchart"});
  2250. equals(c3.connector.type, "Flowchart", "Flowchart connector has type set");
  2251. });
  2252. test(renderMode + " Endpoints have 'type' member set", function() {
  2253. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2254. var c = _jsPlumb.connect({source:d1, target:d2});
  2255. equals(c.endpoints[0].type, "Dot", "Dot endpoint has type set");
  2256. var c2 = _jsPlumb.connect({source:d1, target:d2, endpoints:["Rectangle", "Blank"]});
  2257. equals(c2.endpoints[1].type, "Blank", "Blank endpoint has type set");
  2258. equals(c2.endpoints[0].type, "Rectangle", "Rectangle endpoint has type set");
  2259. });
  2260. test(renderMode + " Overlays have 'type' member set", function() {
  2261. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2262. var c = _jsPlumb.connect({
  2263. source:d1,
  2264. target:d2,
  2265. overlays:[ "Arrow", "Label", "PlainArrow", "Diamond" ]
  2266. });
  2267. equals(c.overlays[0].type, "Arrow", "Arrow overlay has type set");
  2268. equals(c.overlays[1].type, "Label", "Label overlay has type set");
  2269. equals(c.overlays[2].type, "PlainArrow", "PlainArrow overlay has type set");
  2270. equals(c.overlays[3].type, "Diamond", "Diamond overlay has type set");
  2271. });
  2272. test(renderMode + " _jsPlumb.hide, original one-arg version", function() {
  2273. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  2274. e = { isSource:true, isTarget:true, maxConnections:-1 },
  2275. e1 = _jsPlumb.addEndpoint(d1, e),
  2276. e2 = _jsPlumb.addEndpoint(d2, e),
  2277. c1 = _jsPlumb.connect({source:e1, target:e2});
  2278. equals(true, c1.isVisible(), "Connection 1 is visible after creation.");
  2279. equals(true, e1.isVisible(), "endpoint 1 is visible after creation.");
  2280. equals(true, e2.isVisible(), "endpoint 2 is visible after creation.");
  2281. _jsPlumb.hide(d1);
  2282. equals(false, c1.isVisible(), "Connection 1 is no longer visible.");
  2283. equals(true, e1.isVisible(), "endpoint 1 is still visible.");
  2284. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  2285. _jsPlumb.show(d1);
  2286. equals(true, c1.isVisible(), "Connection 1 is visible again.");
  2287. });
  2288. test(renderMode + " _jsPlumb.hide, two-arg version, endpoints should also be hidden", function() {
  2289. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  2290. e = { isSource:true, isTarget:true, maxConnections:-1 },
  2291. e1 = _jsPlumb.addEndpoint(d1, e),
  2292. e2 = _jsPlumb.addEndpoint(d2, e),
  2293. c1 = _jsPlumb.connect({source:e1, target:e2});
  2294. equals(true, c1.isVisible(), "Connection 1 is visible after creation.");
  2295. equals(true, e1.isVisible(), "endpoint 1 is visible after creation.");
  2296. equals(true, e2.isVisible(), "endpoint 2 is visible after creation.");
  2297. _jsPlumb.hide("d1", true);
  2298. equals(false, c1.isVisible(), "Connection 1 is no longer visible.");
  2299. equals(false, e1.isVisible(), "endpoint 1 is no longer visible.");
  2300. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  2301. _jsPlumb.show(d1); // now show d1, but do not alter the endpoints. e1 should still be hidden
  2302. equals(true, c1.isVisible(), "Connection 1 is visible again.");
  2303. equals(false, e1.isVisible(), "endpoint 1 is no longer visible.");
  2304. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  2305. });
  2306. test(renderMode + " _jsPlumb.show, two-arg version, endpoints should become visible", function() {
  2307. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  2308. e = { isSource:true, isTarget:true, maxConnections:-1 },
  2309. e1 = _jsPlumb.addEndpoint(d1, e),
  2310. e2 = _jsPlumb.addEndpoint(d2, e),
  2311. c1 = _jsPlumb.connect({source:e1, target:e2});
  2312. _jsPlumb.hide("d1", true);
  2313. equals(false, c1.isVisible(), "Connection 1 is no longer visible.");
  2314. equals(false, e1.isVisible(), "endpoint 1 is no longer visible.");
  2315. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  2316. _jsPlumb.show(d1, true); // now show d1, and alter the endpoints. e1 should be visible.
  2317. equals(true, c1.isVisible(), "Connection 1 is visible again.");
  2318. equals(true, e1.isVisible(), "endpoint 1 is visible again.");
  2319. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  2320. });
  2321. test(renderMode + " _jsPlumb.show, two-arg version, endpoints should become visible, but not all connections, because some other endpoints are not visible.", function() {
  2322. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), d3 = _addDiv("d3"),
  2323. e = { isSource:true, isTarget:true, maxConnections:-1 },
  2324. e1 = _jsPlumb.addEndpoint(d1, e),
  2325. e11 = _jsPlumb.addEndpoint(d1, e),
  2326. e2 = _jsPlumb.addEndpoint(d2, e),
  2327. e3 = _jsPlumb.addEndpoint(d3, e),
  2328. c1 = _jsPlumb.connect({source:e1, target:e2}),
  2329. c2 = _jsPlumb.connect({source:e11, target:e3});
  2330. // we now have d1 connected to both d3 and d2. we'll hide d1, and everything on d1 should be hidden.
  2331. _jsPlumb.hide("d1", true);
  2332. equals(false, c1.isVisible(), "connection 1 is no longer visible.");
  2333. equals(false, c2.isVisible(), "connection 2 is no longer visible.");
  2334. equals(false, e1.isVisible(), "endpoint 1 is no longer visible.");
  2335. equals(false, e11.isVisible(), "endpoint 1 is no longer visible.");
  2336. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  2337. equals(true, e3.isVisible(), "endpoint 3 is still visible.");
  2338. // now, we will also hide d3. making d1 visible again should NOT result in c2 becoming visible, because the other endpoint
  2339. // for c2 is e3, which is not visible.
  2340. _jsPlumb.hide(d3, true);
  2341. equals(false, e3.isVisible(), "endpoint 3 is no longer visible.");
  2342. _jsPlumb.show(d1, true); // now show d1, and alter the endpoints. e1 should be visible, c1 should be visible, but c2 should not.
  2343. equals(true, c1.isVisible(), "Connection 1 is visible again.");
  2344. equals(false, c2.isVisible(), "Connection 2 is not visible.");
  2345. equals(true, e1.isVisible(), "endpoint 1 is visible again.");
  2346. equals(true, e11.isVisible(), "endpoint 11 is visible again.");
  2347. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  2348. equals(false, e3.isVisible(), "endpoint 3 is still not visible.");
  2349. });
  2350. /*
  2351. test(renderMode + " _jsPlumb.hide, two-arg version, endpoints should also be hidden", function() {
  2352. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  2353. e = { isSource:true, isTarget:true, maxConnections:-1 },
  2354. e1 = _jsPlumb.addEndpoint(d1, e),
  2355. e2 = _jsPlumb.addEndpoint(d2, e),
  2356. c1 = _jsPlumb.connect({source:e1, target:e2});
  2357. equals(true, c1.isVisible(), "Connection 1 is visible after creation.");
  2358. equals(true, e1.isVisible(), "endpoint 1 is visible after creation.");
  2359. equals(true, e2.isVisible(), "endpoint 2 is visible after creation.");
  2360. _jsPlumb.hide("d1", true);
  2361. equals(false, c1.isVisible(), "Connection 1 is no longer visible.");
  2362. equals(false, e1.isVisible(), "endpoint 1 is no longer visible.");
  2363. equals(true, e2.isVisible(), "endpoint 2 is still visible.");
  2364. });
  2365. /**
  2366. * test for issue 132: label leaves its element in the DOM after it has been
  2367. * removed from a connection.
  2368. */
  2369. test(renderMode + " label cleans itself up properly", function() {
  2370. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2371. var c = _jsPlumb.connect({source:d1,target:d2, overlays:[
  2372. [ "Label", {id:"label", cssClass:"foo"}]
  2373. ]});
  2374. ok($(".foo").length == 1, "label element exists in DOM");
  2375. c.removeOverlay("label");
  2376. ok($(".foo").length == 0, "label element does not exist in DOM");
  2377. });
  2378. test(renderMode + " arrow cleans itself up properly", function() {
  2379. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2380. var c = _jsPlumb.connect({source:d1,target:d2, overlays:[
  2381. [ "Arrow", {id:"arrow"}]
  2382. ]});
  2383. ok(c.getOverlay("arrow") != null, "arrow overlay exists");
  2384. c.removeOverlay("arrow");
  2385. ok(c.getOverlay("arrow") == null, "arrow overlay has been removed");
  2386. });
  2387. test(renderMode + " label overlay getElement function", function() {
  2388. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2389. var c = _jsPlumb.connect({source:d1,target:d2, overlays:[
  2390. [ "Label", {id:"label"}]
  2391. ]});
  2392. ok(c.getOverlay("label").getElement() != null, "label overlay exposes element via getElement method");
  2393. });
  2394. test(renderMode + " label overlay provides getLabel and setLabel methods", function() {
  2395. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2396. var c = _jsPlumb.connect({source:d1,target:d2, overlays:[
  2397. [ "Label", {id:"label", label:"foo"}]
  2398. ]});
  2399. var o = c.getOverlay("label"), e = o.getElement();
  2400. ok(e.innerHTML == "foo", "label text is set to original value");
  2401. o.setLabel("baz");
  2402. ok(e.innerHTML == "baz", "label text is set to new value 'baz'");
  2403. ok(o.getLabel() === "baz", "getLabel function works correctly with String");
  2404. // now try functions
  2405. var aFunction = function() { return "aFunction"; };
  2406. o.setLabel(aFunction);
  2407. ok(e.innerHTML == "aFunction", "label text is set to new value from Function");
  2408. ok(o.getLabel() === aFunction, "getLabel function works correctly with Function");
  2409. });
  2410. test(renderMode + " parameters object works for Endpoint", function() {
  2411. var d1 = _addDiv("d1"),
  2412. f = function() { alert("FOO!"); },
  2413. e = _jsPlumb.addEndpoint(d1, {
  2414. isSource:true,
  2415. parameters:{
  2416. "string":"param1",
  2417. "int":4,
  2418. "function":f
  2419. }
  2420. });
  2421. ok(e.getParameter("string") === "param1", "getParameter(String) works correctly");
  2422. ok(e.getParameter("int") === 4, "getParameter(int) works correctly");
  2423. ok(e.getParameter("function") == f, "getParameter(Function) works correctly");
  2424. });
  2425. test(renderMode + " parameters object works for Connection", function() {
  2426. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  2427. f = function() { alert("FOO!"); };
  2428. var c = _jsPlumb.connect({
  2429. source:d1,
  2430. target:d2,
  2431. parameters:{
  2432. "string":"param1",
  2433. "int":4,
  2434. "function":f
  2435. }
  2436. });
  2437. ok(c.getParameter("string") === "param1", "getParameter(String) works correctly");
  2438. ok(c.getParameter("int") === 4, "getParameter(int) works correctly");
  2439. ok(c.getParameter("function") == f, "getParameter(Function) works correctly");
  2440. });
  2441. test(renderMode + " parameters set on Endpoints and Connections are all merged, and merged correctly at that.", function() {
  2442. var d1 = _addDiv("d1"),
  2443. d2 = _addDiv("d2"),
  2444. e = _jsPlumb.addEndpoint(d1, {
  2445. isSource:true,
  2446. parameters:{
  2447. "string":"sourceEndpoint",
  2448. "int":0,
  2449. "function":function() { return "sourceEndpoint"; }
  2450. }
  2451. }),
  2452. e2 = _jsPlumb.addEndpoint(d2, {
  2453. isTarget:true,
  2454. parameters:{
  2455. "int":1,
  2456. "function":function() { return "targetEndpoint"; }
  2457. }
  2458. }),
  2459. c = _jsPlumb.connect({source:e, target:e2, parameters:{
  2460. "function":function() { return "connection"; }
  2461. }});
  2462. ok(c.getParameter("string") === "sourceEndpoint", "getParameter(String) works correctly");
  2463. ok(c.getParameter("int") === 1, "getParameter(int) works correctly");
  2464. ok(c.getParameter("function")() == "connection", "getParameter(Function) works correctly");
  2465. });
  2466. // anchor manager tests. a new and more comprehensive way of managing the paint, introduced in 1.3.5
  2467. test(renderMode + " anchorManager registers standard connection", function() {
  2468. var d1 = _addDiv("d1"), d2 = _addDiv("d2");
  2469. var c = _jsPlumb.connect({source:d1, target:d2});
  2470. equals(_jsPlumb.anchorManager.getConnectionsFor("d1").length, 1);
  2471. equals(_jsPlumb.anchorManager.getEndpointsFor("d1").length, 1);
  2472. equals(_jsPlumb.anchorManager.getConnectionsFor("d2").length, 1);
  2473. equals(_jsPlumb.anchorManager.getEndpointsFor("d2").length, 1);
  2474. var c2 = _jsPlumb.connect({source:d1, target:d2});
  2475. equals(_jsPlumb.anchorManager.getConnectionsFor("d1").length, 2);
  2476. equals(_jsPlumb.anchorManager.getConnectionsFor("d2").length, 2);
  2477. equals(_jsPlumb.anchorManager.getEndpointsFor("d1").length, 2);
  2478. equals(_jsPlumb.anchorManager.getEndpointsFor("d2").length, 2);
  2479. });
  2480. // anchor manager tests. a new and more comprehensive way of managing the paint, introduced in 1.3.5
  2481. test(renderMode + " anchorManager registers dynamic anchor connection, and removes it.", function() {
  2482. var d3 = _addDiv("d3"), d4 = _addDiv("d4");
  2483. var c = _jsPlumb.connect({source:d3, target:d4, anchors:["AutoDefault", "AutoDefault"]});
  2484. equals(_jsPlumb.anchorManager.getConnectionsFor("d3").length, 1);
  2485. var c2 = _jsPlumb.connect({source:d3, target:d4});
  2486. equals(_jsPlumb.anchorManager.getConnectionsFor("d3").length, 2);
  2487. equals(_jsPlumb.anchorManager.getConnectionsFor("d4").length, 2);
  2488. equals(_jsPlumb.anchorManager.getEndpointsFor("d3").length, 2);
  2489. _jsPlumb.detach(c);
  2490. equals(_jsPlumb.anchorManager.getConnectionsFor("d3").length, 1);
  2491. });
  2492. // anchor manager tests. a new and more comprehensive way of managing the paint, introduced in 1.3.5
  2493. test(renderMode + " anchorManager registers continuous anchor connection, and removes it.", function() {
  2494. var d3 = _addDiv("d3"), d4 = _addDiv("d4");
  2495. var c = _jsPlumb.connect({source:d3, target:d4, anchors:["Continuous", "Continuous"]});
  2496. equals(_jsPlumb.anchorManager.getConnectionsFor("d3").length, 1);
  2497. equals(_jsPlumb.anchorManager.getConnectionsFor("d4").length, 1);
  2498. _jsPlumb.detach(c);
  2499. equals(_jsPlumb.anchorManager.getConnectionsFor("d3").length, 0);
  2500. equals(_jsPlumb.anchorManager.getConnectionsFor("d4").length, 0);
  2501. _jsPlumb.reset();
  2502. equals(_jsPlumb.anchorManager.getEndpointsFor("d4"), null);
  2503. });
  2504. // ------------- utility functions - math stuff, mostly --------------------------
  2505. var tolerance = 0.00000005, withinTolerance = function(v1, v2, msg) {
  2506. if (Math.abs(v1 - v2) < tolerance) ok(true, msg + "; expected " + v1 + " and got it");
  2507. else {
  2508. ok(false, msg + "; expected " + v1 + " got " + v2);
  2509. }
  2510. };
  2511. test(renderMode + " jsPlumb.util.gradient, segment 1", function() {
  2512. var p1 = [2,2], p2 = [3,1], m = jsPlumb.util.gradient(p1,p2);
  2513. equals(m, -1, "gradient calculated correctly for simple case");
  2514. });
  2515. test(renderMode + " jsPlumb.util.normal, segment 1", function() {
  2516. var p1 = [2,2], p2 = [3,1], m = jsPlumb.util.normal(p1,p2);
  2517. equals(m, 1, "normal calculated correctly for simple case");
  2518. });
  2519. test(renderMode + " jsPlumb.util.gradient, segment 2", function() {
  2520. var p1 = [2,2], p2 = [3,3], m = jsPlumb.util.gradient(p1,p2);
  2521. equals(m, 1, "gradient calculated correctly for simple case");
  2522. });
  2523. test(renderMode + " jsPlumb.util.normal, segment 2", function() {
  2524. var p1 = [2,2], p2 = [3,3], m = jsPlumb.util.normal(p1,p2);
  2525. equals(m, -1, "normal calculated correctly for simple case");
  2526. });
  2527. test(renderMode + " jsPlumb.util.gradient, segment 3", function() {
  2528. var p1 = [2,2], p2 = [1,3], m = jsPlumb.util.gradient(p1,p2);
  2529. equals(m, -1, "gradient calculated correctly for simple case");
  2530. });
  2531. test(renderMode + " jsPlumb.util.normal, segment 3", function() {
  2532. var p1 = [2,2], p2 = [1,3], m = jsPlumb.util.normal(p1,p2);
  2533. equals(m, 1, "normal calculated correctly for simple case");
  2534. });
  2535. test(renderMode + " jsPlumb.util.gradient, segment 4", function() {
  2536. var p1 = [2,2], p2 = [1,1], m = jsPlumb.util.gradient(p1,p2);
  2537. equals(m, 1, "gradient calculated correctly for simple case");
  2538. });
  2539. test(renderMode + " jsPlumb.util.normal, segment 4", function() {
  2540. var p1 = [2,2], p2 = [1,1], m = jsPlumb.util.normal(p1,p2);
  2541. equals(m, -1, "normal calculated correctly for simple case");
  2542. });
  2543. test(renderMode + "jsPlumb.util.pointOnLine, segment 1", function() {
  2544. var p1 = {x:2,y:2}, p2={x:3, y:1},
  2545. target = jsPlumb.util.pointOnLine(p1, p2, Math.sqrt(2));
  2546. withinTolerance(p2.x, target.x, "x is calculated correctly");
  2547. withinTolerance(p2.y, target.y, "y is calculated correctly");
  2548. });
  2549. test(renderMode + "jsPlumb.util.pointOnLine, segment 2", function() {
  2550. var p1 = {x:2,y:2}, p2={x:3, y:3},
  2551. target = jsPlumb.util.pointOnLine(p1, p2, Math.sqrt(2));
  2552. withinTolerance(p2.x, target.x, "x is calculated correctly");
  2553. withinTolerance(p2.y, target.y, "y is calculated correctly");
  2554. });
  2555. test(renderMode + "jsPlumb.util.pointOnLine, segment 3", function() {
  2556. var p1 = {x:2,y:2}, p2={x:1, y:3},
  2557. target = jsPlumb.util.pointOnLine(p1, p2, Math.sqrt(2));
  2558. withinTolerance(p2.x, target.x, "x is calculated correctly");
  2559. withinTolerance(p2.y, target.y, "y is calculated correctly");
  2560. });
  2561. test(renderMode + "jsPlumb.util.pointOnLine, segment 4", function() {
  2562. var p1 = {x:2,y:2}, p2={x:1, y:1},
  2563. target = jsPlumb.util.pointOnLine(p1, p2, Math.sqrt(2));
  2564. withinTolerance(p2.x, target.x, "x is calculated correctly");
  2565. withinTolerance(p2.y, target.y, "y is calculated correctly");
  2566. });
  2567. test(renderMode + "jsPlumb.util.perpendicularLineTo, segment 1", function() {
  2568. var p1 = {x:2, y:2}, p2={x:3, y:1}, m = jsPlumb.util.gradient(p1, p2),
  2569. l = jsPlumb.util.perpendicularLineTo(p1, p2, 2 * Math.sqrt(2));
  2570. withinTolerance(4, l[0].x, "point 1 x is correct");
  2571. withinTolerance(2, l[0].y, "point 1 y is correct");
  2572. withinTolerance(2, l[1].x, "point 2 x is correct");
  2573. withinTolerance(0, l[1].y, "point 2 y is correct");
  2574. });
  2575. test(renderMode + "jsPlumb.util.perpendicularLineTo, segment 2", function() {
  2576. var p1 = {x:2, y:2}, p2={x:3, y:3}, m = jsPlumb.util.gradient(p1, p2),
  2577. l = jsPlumb.util.perpendicularLineTo(p1, p2, 2 * Math.sqrt(2));
  2578. withinTolerance(4, l[0].x, "point 1 x is correct");
  2579. withinTolerance(2, l[0].y, "point 1 y is correct");
  2580. withinTolerance(2, l[1].x, "point 2 x is correct");
  2581. withinTolerance(4, l[1].y, "point 2 y is correct");
  2582. });
  2583. test(renderMode + "jsPlumb.util.perpendicularLineTo, segment 3", function() {
  2584. var p1 = {x:2, y:2}, p2={x:1, y:3}, m = jsPlumb.util.gradient(p1, p2),
  2585. l = jsPlumb.util.perpendicularLineTo(p1, p2, 2 * Math.sqrt(2));
  2586. withinTolerance(2, l[0].x, "point 1 x is correct");
  2587. withinTolerance(4, l[0].y, "point 1 y is correct");
  2588. withinTolerance(0, l[1].x, "point 2 x is correct");
  2589. withinTolerance(2, l[1].y, "point 2 y is correct");
  2590. });
  2591. test(renderMode + "jsPlumb.util.perpendicularLineTo, segment 4", function() {
  2592. var p1 = {x:2, y:2}, p2={x:1, y:1}, m = jsPlumb.util.gradient(p1, p2),
  2593. l = jsPlumb.util.perpendicularLineTo(p1, p2, 2 * Math.sqrt(2));
  2594. withinTolerance(2, l[0].x, "point 1 x is correct");
  2595. withinTolerance(0, l[0].y, "point 1 y is correct");
  2596. withinTolerance(0, l[1].x, "point 2 x is correct");
  2597. withinTolerance(2, l[1].y, "point 2 y is correct");
  2598. });
  2599. test(renderMode + "jsPlumb.util.setImage on Endpoint", function() {
  2600. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  2601. e = {
  2602. endpoint:[ "Image", { src:"../../img/endpointTest1.png" } ]
  2603. },
  2604. ep = _jsPlumb.addEndpoint(d1, e);
  2605. ep.setImage("../../img/littledot.png");
  2606. });
  2607. test(renderMode + "jsPlumb.util.setImage on Endpoint, with supplied onload", function() {
  2608. var d1 = _addDiv("d1"), d2 = _addDiv("d2"),
  2609. e = {
  2610. endpoint:[ "Image", {
  2611. src:"../../img/endpointTest1.png",
  2612. onload:function(imgEp) {
  2613. equals("../../img/endpointTest1.png", imgEp.img.src);
  2614. }
  2615. } ]
  2616. },
  2617. ep = _jsPlumb.addEndpoint(d1, e);
  2618. ep.setImage("../../img/littledot.png", function(imgEp) {
  2619. equals("../../img/littledot.png", imgEp.img.src);
  2620. });
  2621. });
  2622. test(renderMode + "attach endpoint to table when desired element was td", function() {
  2623. var table = document.createElement("table"),
  2624. tr = document.createElement("tr"),
  2625. td = document.createElement("td");
  2626. table.appendChild(tr); tr.appendChild(td);
  2627. document.body.appendChild(table);
  2628. var ep = _jsPlumb.addEndpoint(td);
  2629. equals(ep.canvas.parentNode.tagName.toLowerCase(), "table");
  2630. });
  2631. // issue 190 - regressions with getInstance. these tests ensure that generated ids are unique across
  2632. // instances.
  2633. test(renderMode + " id clashes between instances", function() {
  2634. var d1 = document.createElement("div"),
  2635. d2 = document.createElement("div"),
  2636. _jsp2 = jsPlumb.getInstance();
  2637. document.body.appendChild(d1);
  2638. document.body.appendChild(d2);
  2639. _jsPlumb.addEndpoint(d1);
  2640. _jsp2.addEndpoint(d2);
  2641. var id1 = d1.getAttribute("id"),
  2642. id2 = d2.getAttribute("id");
  2643. var idx = id1.indexOf("_"), idx2 = id1.lastIndexOf("_"), v1 = id1.substring(idx, idx2);
  2644. var idx3 = id2.indexOf("_"), idx4 = id2.lastIndexOf("_"), v2 = id2.substring(idx3, idx4);
  2645. ok (v1 != v2, "instance versions are different : " + v1 + " : " + v2);
  2646. });
  2647. test(renderMode + " id clashes between instances", function() {
  2648. var d1 = document.createElement("div"),
  2649. d2 = document.createElement("div"),
  2650. _jsp2 = jsPlumb.getInstance();
  2651. document.body.appendChild(d1);
  2652. document.body.appendChild(d2);
  2653. _jsPlumb.addEndpoint(d1);
  2654. _jsPlumb.addEndpoint(d2);
  2655. var id1 = d1.getAttribute("id"),
  2656. id2 = d2.getAttribute("id");
  2657. var idx = id1.indexOf("_"), idx2 = id1.lastIndexOf("_"), v1 = id1.substring(idx, idx2);
  2658. var idx3 = id2.indexOf("_"), idx4 = id2.lastIndexOf("_"), v2 = id2.substring(idx3, idx4);
  2659. ok (v1 == v2, "instance versions are the same : " + v1 + " : " + v2);
  2660. });
  2661. test(renderMode + " importDefaults", function() {
  2662. _jsPlumb.Defaults.Anchors = ["LeftMiddle", "RightMiddle"];
  2663. var d1 = _addDiv("d1"),
  2664. d2 = _addDiv(d2),
  2665. c = _jsPlumb.connect({source:d1, target:d2}),
  2666. e = c.endpoints[0];
  2667. equals(e.anchor.x, 0, "left middle anchor");
  2668. equals(e.anchor.y, 0.5, "left middle anchor");
  2669. _jsPlumb.importDefaults({
  2670. Anchors:["TopLeft", "TopRight"]
  2671. });
  2672. var conn = _jsPlumb.connect({source:d1, target:d2}),
  2673. e1 = conn.endpoints[0], e2 = conn.endpoints[1];
  2674. equals(e1.anchor.x, 0, "top leftanchor");
  2675. equals(e2.anchor.y, 0, "top left anchor");
  2676. equals(e2.anchor.x, 1, "top right anchor");
  2677. equals(e2.anchor.y, 0, "top right anchor");
  2678. });
  2679. test(renderMode + " restoreDefaults", function() {
  2680. _jsPlumb.importDefaults({
  2681. Anchors:["TopLeft", "TopRight"]
  2682. });
  2683. var d1 = _addDiv("d1"), d2 = _addDiv("d2"), conn = _jsPlumb.connect({source:d1, target:d2}),
  2684. e1 = conn.endpoints[0], e2 = conn.endpoints[1];
  2685. equals(e1.anchor.x, 0, "top leftanchor");
  2686. equals(e2.anchor.y, 0, "top left anchor");
  2687. equals(e2.anchor.x, 1, "top right anchor");
  2688. equals(e2.anchor.y, 0, "top right anchor");
  2689. _jsPlumb.restoreDefaults();
  2690. var conn2 = _jsPlumb.connect({source:d1, target:d2}),
  2691. e3 = conn2.endpoints[0], e4 = conn2.endpoints[1];
  2692. equals(e3.anchor.x, 0.5, "bottom center anchor");
  2693. equals(e3.anchor.y, 1, "bottom center anchor");
  2694. equals(e4.anchor.x, 0.5, "bottom center anchor");
  2695. equals(e4.anchor.y, 1, "bottom center anchor");
  2696. });
  2697. /**
  2698. * leave this test at the bottom!
  2699. */
  2700. test(renderMode + ': unload test', function() {
  2701. _jsPlumb.unload();
  2702. var contextNode = $(".__jsPlumb_context");
  2703. ok(contextNode.length == 0, 'context node unloaded');
  2704. });
  2705. };