jsPlumb-1.3.0-tests.js 74 KB

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