jsPlumb-1.3.7-tests.js 163 KB

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