-
Notifications
You must be signed in to change notification settings - Fork 1
/
module.spec.js
1700 lines (1593 loc) · 78.5 KB
/
module.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as pubsub from '../src/components/lib/pubsub.js';
import * as utils from './utils.js';
import {
LAVENDER,
EXPECTED_NODE_MOUSEOVER_REGEX,
TOPOLOGY,
OPTIONS,
TRAFFIC_DATA,
AUTODETECT_TRAFFIC_DATA
} from "./constants.js";
import { signals } from "../src/signals.js";
const PubSub = pubsub.PubSub;
function skip(){
return
}
describe( "Class MapCanvas", () => {
afterEach(function(){
var canvases = document.querySelectorAll("esnet-map-canvas");
canvases.forEach((canvas)=>{
canvas.remove();
})
})
beforeEach(function(){
var elem = document.createElement("esnet-map-canvas");
elem.setAttribute('width', 800);
elem.setAttribute('height', 400);
elem.setAttribute("id", "testing-element");
document.body.appendChild(elem);
elem.setTopology(TOPOLOGY);
elem.setOptions(OPTIONS);
});
it( "should append a esnet-map-canvas element", async () => {
let isInstance = document.querySelector("esnet-map-canvas") instanceof HTMLElement;
expect(isInstance).toBeTruthy();
} );
it( "should have a sidebar child element", async () => {
let isInstance = document.querySelector("esnet-map-canvas").querySelector("esnet-map-side-bar") instanceof HTMLElement;
expect(isInstance).toBeTruthy();
} );
it( "should have an esnet-map-editing-interface child element", async () => {
let isInstance = document.querySelector("esnet-map-canvas").querySelector("esnet-map-editing-interface") instanceof HTMLElement;
expect(isInstance).toBeTruthy();
} );
it( "should call back a defined function when a 'TOPOLOGY_UPDATED' signal fires", async ()=>{
var mapCanvas = document.querySelector("esnet-map-canvas");
var closureVar = null;
mapCanvas.listen(signals.TOPOLOGY_UPDATED, () => { closureVar = "called"; })
mapCanvas.setTopology(null);
expect(closureVar).toEqual("called");
});
it("should have a node vertex around (259, 194) with reference to the esnet-map-canvas's offset", async ()=>{
var map_coords = document.querySelector("esnet-map-canvas").getBoundingClientRect();
// find the first circle in a "g.node". This should be the "A" node from topology
var nodes = document.querySelectorAll("g.node > g.scale-container > circle");
var node_coords = nodes[0].getBoundingClientRect();
// at 800x400 canvas size, we expect the offset (from the esnet-map-canvas top-left) of the first node to be 262, 194
const expected_x = 259;
const expected_y = 194;
expect(expected_x).toBeCloseTo(node_coords.x - map_coords.x, -1) // interactions with ResizeObserver make this coord approximate
expect(expected_y).toEqual(node_coords.y - map_coords.y);
// conversely, if we look for the element at the offset of 262, 194 (plus 4 for its radius), we should find our circle.
var expected_circle = document.elementFromPoint(map_coords.x + expected_x + 4, map_coords.y + expected_y + 4);
expect(expected_circle.tagName).toEqual("circle");
// we bother with all of this work because we'll need to simulate click/drag/etc events on the nodes in other test
});
it("should enter edit mode when we call setEditMode", async ()=>{
var canvas = document.querySelector("esnet-map-canvas");
canvas.setEditMode("edge");
var toolOverlayButton = canvas.editingInterface.shadow.querySelector(".tools-overlay > .button.edit-mode-only");
// using window.getComputedStyle, get the full computed style including cascading upstream styles
var style = window.getComputedStyle(toolOverlayButton);
expect(style.display).toEqual("inline-block");
});
it("should show a tooltip in the sidebar when a user hovers over a node", async () => {
var canvas = document.querySelector("esnet-map-canvas");
var node = document.querySelector("g.node > g.scale-container > circle");
// create a bubbling mouseover event
let mouseoverEvent = new Event('mouseover', { bubbles: true });
// fire the mouseover event on our demonstration node
node.dispatchEvent(mouseoverEvent);
// get the sidebar tooltip text
const sidebarTooltip = canvas.querySelector("#sidebar-tooltip");
// var sidebarTooltipText = sidebarTooltip.innerText;
var sidebarTooltipText = utils.getElementText(sidebarTooltip);
// test that the sidebar tooltip text is as expected
expect(sidebarTooltipText).toMatch(EXPECTED_NODE_MOUSEOVER_REGEX);
});
it("should have an edit mode characterized by edit buttons", async ()=>{
var canvas = document.querySelector("esnet-map-canvas");
canvas.setEditMode("edge");
var toolOverlayButton = canvas.editingInterface.shadow.querySelector(".tools-overlay > .button.edit-mode-only");
// using window.getComputedStyle, get the full computed style including cascading upstream styles
var style = window.getComputedStyle(toolOverlayButton);
expect(style.display).toEqual("inline-block");
});
it("should allow users to change the map layer tileset", async ()=>{
var canvas = document.querySelector("esnet-map-canvas");
var newOptions = JSON.parse(JSON.stringify(canvas.options));
newOptions.tileset['geographic'] = "usgs";
canvas.setOptions(newOptions);
var i=0;
var firstLayerUrl = null;
canvas.leafletMap.eachLayer((layer)=>{
if(i==0) firstLayerUrl = layer._url;
i++;
});
const usgsUrl = 'https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}';
expect(usgsUrl).toEqual(firstLayerUrl);
});
it("should allow users to change the political boundary layer tileset", async ()=>{
var canvas = document.querySelector("esnet-map-canvas");
var newOptions = JSON.parse(JSON.stringify(canvas.options));
newOptions.tileset['boundaries'] = 'toner.boundaries';
canvas.setOptions(newOptions);
var i=0;
var secondLayerUrl = null;
canvas.leafletMap.eachLayer((layer)=>{
if(i==1) secondLayerUrl = layer._url;
i++;
});
const tonerBoundariesUrl = 'https://tiles.stadiamaps.com/tiles/stamen_toner_lines/{z}/{x}/{y}{r}.{ext}';
expect(secondLayerUrl).toEqual(tonerBoundariesUrl);
});
it("should allow users to change the political label layer tileset", async ()=>{
var canvas = document.querySelector("esnet-map-canvas");
var newOptions = JSON.parse(JSON.stringify(canvas.options));
newOptions.tileset['labels'] = 'toner.labels';
canvas.setOptions(newOptions);
var i=0;
var secondLayerUrl = null;
canvas.leafletMap.eachLayer((layer)=>{
if(i==1) secondLayerUrl = layer._url;
i++;
});
const tonerLabelsUrl = 'https://tiles.stadiamaps.com/tiles/stamen_toner_labels/{z}/{x}/{y}{r}.{ext}';
expect(secondLayerUrl).toEqual(tonerLabelsUrl);
});
it("should allow users to 'home' the map by clicking a button", async ()=>{
var canvas = document.querySelector("esnet-map-canvas");
var node = document.querySelector("g.node > g.scale-container > circle");
var originalPosition = node.getBoundingClientRect();
var mouseOrigin = { x: originalPosition.x - 10, y: originalPosition.y - 10 };
// simulate the outcome of a drag event, changing the center and zoom
canvas.leafletMap.setView([75, -101.426], 3);
// verify that the point for the A node has moved N pixels
var afterDragPosition = node.getBoundingClientRect();
expect(afterDragPosition.x).not.toEqual(originalPosition.x);
expect(afterDragPosition.y).not.toEqual(originalPosition.y);
// click the home button
var clickEvent = new Event('click', { bubbles: true })
var home_button = canvas.shadow.querySelector("#home_map")
home_button.dispatchEvent(clickEvent);
// verify that the point for the A node is back at original position (262, 194) w/r/t esnet-map-canvas (0,0)
node = document.querySelector("g.node > g.scale-container > circle");
var afterHomeClickPosition = node.getBoundingClientRect();
expect(afterHomeClickPosition.x).toBeCloseTo(originalPosition.x, -1); // interactions with ResizeObserver make this coord approximate
expect(afterHomeClickPosition.y).toEqual(originalPosition.y);
});
it("should allow users to toggle layers", async ()=>{
var canvas = document.querySelector("esnet-map-canvas");
var node = document.querySelector("g.node > g.scale-container > circle");
var nodeStyle = window.getComputedStyle(node);
// verify that the point for the A node is visible
expect(nodeStyle.display).toEqual("inline");
// click the toggle containing the A node
var newOptions = JSON.parse(JSON.stringify(canvas.options));
newOptions.layers[0]['visible'] = false;
PubSub.publish("updateMapOptions", {options: newOptions, changed: ['layers[0].visible']}, canvas);
// verify that the point for the A node is not visible / not in DOM
node = document.querySelector("g.node > circle");
expect(String(node)).toEqual("null");
});
it("should have an edge edit mode characterized by control points on edges", async ()=>{
// enter editing mode
var canvas = document.querySelector("esnet-map-canvas");
canvas.setEditMode("edge");
// run a query selector for control points
var controlPoints = document.querySelectorAll("circle.control");
// expect a specific count of control points
expect(controlPoints.length).toEqual(9)
});
it("should show a UI for adding a node", async ()=>{
// enter editing mode
var canvas = document.querySelector("esnet-map-canvas");
PubSub.publish("updateEditMode", true, canvas);
// create a click event
var clickEvent = new MouseEvent('click', { bubbles: false })
// fire click event on add node button
var addNodeButton = canvas.editingInterface.shadow.querySelector(".tools-overlay > #add_node");
addNodeButton.dispatchEvent(clickEvent)
// run a query selector for UI elements
var addNodeDialog = canvas.editingInterface.shadow.querySelector("#add_node_dialog");
expect(window.getComputedStyle(addNodeDialog).display).toEqual("block");
});
/*it("should allow users to change the display text for a node", async function(){
// enter editing mode
var canvas = document.querySelector("esnet-map-canvas");
canvas.editingInterface.editMode = true;
// throw the signal for node edit mode
PubSub.publish("toggleNodeEdit", null, canvas);
// create a click event
var clickEvent = new Event('dblclick', { bubbles: true })
// fire double click event on node
var node = document.querySelector("circle.control");
node.dispatchEvent(clickEvent);
// change display text
var addNodeDialog = canvas.editingInterface.shadow.querySelector("#add_node_dialog");
window.getComputedStyle(addNodeDialog).display.should.equal("block");
// set display name value
var display_name = canvas.editingInterface.shadow.querySelector("#node_display_name");
display_name.setAttribute("value", "An Unexpected Value");
// click 'Update Node' button
clickEvent = new Event('click', { bubbles: true });
var button = canvas.editingInterface.shadow.querySelector("#create_node");
button.dispatchEvent(clickEvent);
var addNodeDialog = canvas.editingInterface.shadow.querySelector("#add_node_dialog");
window.getComputedStyle(addNodeDialog).display.should.not.equal("block");
// fire mouseover event for edge
canvas.topology.layer1.nodes[0].meta.display_name.should.equal("An Unexpected Value");
});
/*it("should allow users to change the display icon (as SVG) for a node", ()=>{
// enter editing mode
var canvas = document.querySelector("esnet-map-canvas");
canvas.editingInterface.editMode = true;
// throw the signal for node edit mode
PubSub.publish("toggleNodeEdit", null, canvas);
// create a click event
var clickEvent = new Event('dblclick', { bubbles: true })
// fire double click event on node
var node = document.querySelector("circle.control");
node.dispatchEvent(clickEvent);
// change display text
var addNodeDialog = canvas.editingInterface.shadow.querySelector("#add_node_dialog");
window.getComputedStyle(addNodeDialog).display.should.equal("block");
// set display name value
var svg = canvas.editingInterface.shadow.querySelector("#node_svg");
svg.value = "<rect />";
// click 'Update Node' button
clickEvent = new Event('click', { bubbles: true });
var button = canvas.editingInterface.shadow.querySelector("#create_node");
button.dispatchEvent(clickEvent);
var addNodeDialog = canvas.editingInterface.shadow.querySelector("#add_node_dialog");
window.getComputedStyle(addNodeDialog).display.should.not.equal("block");
// fire mouseover event for edge
canvas.topology.layer1.nodes[0].meta.svg.should.equal("<rect />");
});*/
it("should show a UI for adding an edge", async ()=>{
// enter editing mode
var canvas = document.querySelector("esnet-map-canvas");
PubSub.publish("updateEditMode", true, canvas);
// create a click event
var clickEvent = new Event('click', { bubbles: false })
// fire click event on add edge button
var addNodeButton = canvas.editingInterface.shadow.querySelector(".tools-overlay > #add_edge");
addNodeButton.dispatchEvent(clickEvent)
// run a query selector for UI elements
var addNodeDialog = canvas.editingInterface.shadow.querySelector("#add_edge_dialog");
expect(window.getComputedStyle(addNodeDialog).display).toEqual("block");
});
it("should allow users to add an edge control point on double-click", async ()=>{
// enter editing mode
var canvas = document.querySelector("esnet-map-canvas");
var closureVar = false;
// test that we publish updateMapEdge
canvas.listen(signals.EDGE_UPDATED, (e)=>{ closureVar= true; });
canvas.setEditMode("edge");
// create a (double) click event
var dblClickEvent = new MouseEvent('dblclick', { bubbles: true, clientX: 200, clientY: 200 })
// fire double click event on edge
var controlPointsBefore = document.querySelectorAll("circle.control").length
var path = document.querySelector("path.control");
path.dispatchEvent(dblClickEvent);
var controlPointsAfter = document.querySelectorAll("circle.control").length
expect(controlPointsBefore).not.toEqual(controlPointsAfter);
// check that we now have more control points on the edge
expect(controlPointsAfter).toBeGreaterThan(controlPointsBefore);
expect(closureVar).toEqual(true);
});
it("should allow users to remove layer toggles", async ()=>{
var canvas = document.querySelector("esnet-map-canvas");
// set option boolean
var newOptions = JSON.parse(JSON.stringify(canvas.options));
newOptions.layers[0].legend = false;
newOptions.layers[1].legend = false;
newOptions.layers[2].legend = false;
// update options
canvas.setOptions(newOptions);
// check that no toggle visible for layer toggle we turned off
var toggleContainers = canvas.querySelectorAll(".toggle.container");
for(var i=0; i<toggleContainers.length; i++){
expect(toggleContainers[i].style.display).toEqual("none");
}
});
it("should allow users to double click to remove edge control points", async ()=>{
// get canvas
var canvas = document.querySelector("esnet-map-canvas");
var closureVar = false;
// test that we publish updateMapEdge
canvas.listen(signals.EDGE_UPDATED, (e)=>{ closureVar= true; });
// turn on editing mode
canvas.setEditMode("edge");
// double click control point to remove
var beforeAllCps = canvas.querySelectorAll(".control.controlPoint")
var cp = canvas.querySelector(".control.controlPoint")
var clickEvent = new Event('dblclick', { bubbles: true })
cp.dispatchEvent(clickEvent);
// edge should have 2 control points
var canvas = document.querySelector("esnet-map-canvas");
canvas.setEditMode("edge");
var afterAllCps = canvas.querySelectorAll(".control.controlPoint")
expect(afterAllCps.length).toBeLessThan(beforeAllCps.length)
expect(closureVar).toEqual(true);
})
it("should evenly space edge control points after node drag", async ()=>{
// enter editing mode
var canvas = document.querySelector("esnet-map-canvas");
canvas.setEditMode("edge");
// edge edit mode. Do some work adding vertices to the edge.
var edgeAC = document.querySelector(".control-for-A.control-for-C")
var edgeACPos = edgeAC.getBoundingClientRect();
var clickEvents = [
new MouseEvent('dblclick', { bubbles: true, clientX: edgeACPos.x, clientY: edgeACPos.y, view: window }),
new MouseEvent('dblclick', { bubbles: true, clientX: edgeACPos.x, clientY: edgeACPos.y, view: window })
]
// add vertices and check our work
var beforeAllCps = canvas.querySelectorAll(".control-point-for-edge-A--C")
for(var i=0; i<clickEvents.length; i++){
edgeAC = document.querySelector(".control-for-A.control-for-C");
edgeAC.dispatchEvent(clickEvents[i]);
}
var afterAllCps = canvas.querySelectorAll(".control-point-for-edge-A--C")
expect(afterAllCps.length).toBeGreaterThan(beforeAllCps.length)
var positionsBeforeDrag = [];
for(var i=0; i<afterAllCps.length; i++){
var rect = afterAllCps[i].getBoundingClientRect();
positionsBeforeDrag.push([rect.x, rect.y]);
}
// throw the signal for node edit mode
canvas.setEditMode("node");
var nodes = document.querySelectorAll("circle.control");
var nodeA = nodes[0];
var nodeC = nodes[2];
var originalNodeAPos = nodeA.getBoundingClientRect();
// compensate for radius
originalNodeAPos = {x: originalNodeAPos.x + 4, y: originalNodeAPos.y + 4};
// create mouse event for down
var downEvent = new MouseEvent('mousedown', { bubbles: true, clientX: originalNodeAPos.x, clientY: originalNodeAPos.y, view: window })
// create mouse event for drag
var dragEvent = new MouseEvent('mousemove', { bubbles: true, clientX: originalNodeAPos.x + 10, clientY: originalNodeAPos.y + 10, view: window })
// create mouse event for up
var upEvent = new MouseEvent('mouseup', { bubbles: true, clientX: originalNodeAPos.x + 10, clientY: originalNodeAPos.y + 10, view: window })
// fire down
nodeA.dispatchEvent(downEvent);
// fire drag
nodeA.dispatchEvent(dragEvent);
// fire up
nodeA.dispatchEvent(upEvent);
// check node moved
nodes = document.querySelectorAll("circle.control");
nodeA = nodes[0];
var newPos = nodeA.getBoundingClientRect()
newPos = {x: newPos.x + 4, y: newPos.y + 4};
expect(newPos.x).toBeCloseTo(originalNodeAPos.x + 10, -1);
expect(newPos.y).toBeCloseTo(originalNodeAPos.y + 10, -1);
canvas.setEditMode("edge");
var afterAllCps = canvas.querySelectorAll(".control-point-for-edge-A--C")
expect(afterAllCps.length).toBeGreaterThan(beforeAllCps.length)
var positionsAfterDrag = [];
for(var i=0; i<afterAllCps.length; i++){
var rect = afterAllCps[i].getBoundingClientRect();
positionsAfterDrag.push([rect.x, rect.y]);
}
var positionCount = positionsBeforeDrag.length - 1;
// check that none of the node positions are the same
for(var i=0; i<positionCount; i++){
expect(positionsAfterDrag[i][0]).withContext(`x coord of position ${i} of ${positionCount}`).not.toEqual(positionsBeforeDrag[i][0]);
expect(positionsAfterDrag[i][1]).withContext(`y coord of position ${i} of ${positionCount}`).not.toEqual(positionsBeforeDrag[i][1]);
}
// except the last one in the array, the node that didn't move.
expect(positionsAfterDrag[positionCount][0]).toEqual(positionsBeforeDrag[positionCount][0]);
expect(positionsAfterDrag[positionCount][1]).toEqual(positionsBeforeDrag[positionCount][1]);
for(var i=1; i<positionCount; i++){
// calculate x deltas for each position. they should all be 15.
var deltaX = positionsAfterDrag[i][0] - positionsBeforeDrag[i][0];
//deltaX.should.equal(15);
// calculate y deltas for each position. they should all be -8.
var deltaY = positionsAfterDrag[i][1] - positionsBeforeDrag[i][1];
//deltaY.should.equal(-8);
}
});
it("should show the same tooltip on nodes and node control points", ()=>{
// get canvas
var canvas = document.querySelector("esnet-map-canvas");
// turn on editing mode
canvas.setEditMode("edge");
// toggle node editing mode
// create hover event
// fire hover event on a control point
// get the tooltip text
// turn off editing mode
// fire hover event on a node
// get the tooltip text
// tooltip text before and after should be equal
})
it("should allow users to set the background color", ()=>{
// get canvas
var canvas = document.querySelector("esnet-map-canvas");
// set options to turn off background
// set option for background color
// check that background color is as expected
})
it("should allow users to toggle layer visibility", ()=>{
var canvas = document.querySelector("esnet-map-canvas");
// find a layer toggle
// create click event
// fire click event on layer toggle
// layer should be invisible
})
it("should allow users to style edges in all layers, even when some are not visible", ()=>{
// enter editing mode
var canvas = document.querySelector("esnet-map-canvas");
var newTopology = JSON.parse(JSON.stringify(canvas.topology));
newTopology[1] = newTopology[0];
newTopology[2] = newTopology[0];
canvas.setTopology(newTopology);
var newOptions = JSON.parse(JSON.stringify(canvas.options));
newOptions.layers[2]['edgeWidth'] = 5;
newOptions.layers[0]['visible'] = false;
newOptions.layers[1]['visible'] = false;
newOptions.layers[2]['visible'] = true;
canvas.setOptions(newOptions);
var randomEdge = canvas.querySelector('.edge.edge-az');
expect(randomEdge.getAttribute("stroke-width")).toEqual("5");
})
it("should have a node edit mode characterized by control points on nodes", ()=>{
var canvas = document.querySelector("esnet-map-canvas");
// throw the signal for node edit mode
canvas.setEditMode("node");
// run a query selector for control points
var controlPoints = document.querySelectorAll("circle.control");
// expect a specific count of control points
expect(controlPoints.length).toEqual(3)
});
it("should allow users to drag node edit control points", ()=>{
// enter editing mode
var canvas = document.querySelector("esnet-map-canvas");
// throw the signal for node edit mode
canvas.setEditMode("node");
var closureVar = null;
canvas.listen(signals.NODE_UPDATED, () => {
closureVar = "called";
});
var node = document.querySelector("circle.control");
var originalPos = node.getBoundingClientRect();
// compensate for radius
originalPos = {x: originalPos.x + 4, y: originalPos.y + 4};
// create mouse event for down
var downEvent = new MouseEvent('mousedown', { bubbles: true, clientX: originalPos.x, clientY: originalPos.y, view: window })
// create mouse event for drag
var dragEvent = new MouseEvent('mousemove', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
// create mouse event for up
var upEvent = new MouseEvent('mouseup', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
// fire down
node.dispatchEvent(downEvent);
// fire drag
node.dispatchEvent(dragEvent);
// fire up
node = document.querySelector("circle.control");
node.dispatchEvent(upEvent);
// check node moved
node = document.querySelector("circle.control");
var newPos = node.getBoundingClientRect()
newPos = {x: newPos.x + 4, y: newPos.y + 4};
expect(newPos.x).toBeCloseTo(originalPos.x + 10, -1);
expect(newPos.y).toBeCloseTo(originalPos.y + 10, -1);
expect(closureVar).toEqual("called")
});
it("should persist a topology change when a user drags an editable node control point", ()=>{
var canvas = document.querySelector("esnet-map-canvas");
var closureVar = null;
var closureVar2 = false;
var closureVar3 = false;
canvas.listen(signals.TOPOLOGY_UPDATED, () => {
closureVar = "called";
});
canvas.listen(signals.NODE_UPDATED, (e)=>{
closureVar3 = true;
}, canvas);
canvas.listen(signals.EDGE_UPDATED, (e)=>{
closureVar2 = true;
}, canvas);
// throw the signal for node edit mode
canvas.setEditMode("node");
var node = document.querySelector("circle.control.control-point-for-node-A");
var originalPos = node.getBoundingClientRect();
// compensate for radius
originalPos = {x: originalPos.x + 4, y: originalPos.y + 4};
// create mouse event for down
let downEvent = new MouseEvent('mousedown', { bubbles: true, clientX: originalPos.x, clientY: originalPos.y, view: window })
// create mouse event for drag
let dragEvent = new MouseEvent('mousemove', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
// create mouse event for up
let upEvent = new MouseEvent('mouseup', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
// fire down
node.dispatchEvent(downEvent);
// fire drag
node.dispatchEvent(dragEvent);
// fire up
node = document.querySelector("circle.control.control-point-for-node-A");
node.dispatchEvent(upEvent);
// check node moved
node = document.querySelector("circle.control.control-point-for-node-A");
var newPos = node.getBoundingClientRect()
newPos = {x: newPos.x + 4, y: newPos.y + 4};
expect(newPos.x).toBeCloseTo(originalPos.x + 10, -1);
expect(newPos.y).toBeCloseTo(originalPos.y + 10, -1);
// check callback fired
expect(closureVar).toEqual("called");
expect(closureVar2).toBeTruthy();
expect(closureVar3).toBeTruthy();
});
it("should allow users to drag edge edit control points", ()=>{
// enter editing mode
var canvas = document.querySelector("esnet-map-canvas");
// edge edit mode
canvas.setEditMode("edge");
var cPoint = canvas.querySelector("circle.control");
var originalPos = cPoint.getBoundingClientRect();
// compensate for radius
originalPos = {x: originalPos.x + 4, y: originalPos.y + 4};
// create mouse event for down
var downEvent = new MouseEvent('mousedown', { bubbles: true, clientX: originalPos.x, clientY: originalPos.y, view: window })
// create mouse event for drag
var dragEvent = new MouseEvent('mousemove', { bubbles: true, clientX: originalPos.x + 30, clientY: originalPos.y + 30, view: window })
// create mouse event for up
var upEvent = new MouseEvent('mouseup', { bubbles: true, clientX: originalPos.x + 30, clientY: originalPos.y + 30, view: window })
// fire down
cPoint.dispatchEvent(downEvent);
// fire drag
cPoint.dispatchEvent(dragEvent);
// fire up
cPoint.dispatchEvent(upEvent);
// check edge control point moved
var cPoint = canvas.querySelector("circle.control");
var newPos = cPoint.getBoundingClientRect()
newPos = {x: newPos.x + 4, y: newPos.y + 4};
expect(newPos.x).toBeCloseTo(originalPos.x + 30, -1);
expect(newPos.y).toBeCloseTo(originalPos.y + 30, -1);
});
it("should persist a topology change when a user drags an editable edge control point", ()=>{
var canvas = document.querySelector("esnet-map-canvas");
var closureVar = null;
canvas.listen(signals.TOPOLOGY_UPDATED, () => {
closureVar = "called";
});
// edge edit mode
canvas.setEditMode("edge");
var cPoint = document.querySelector("circle.control");
var originalPos = cPoint.getBoundingClientRect();
// compensate for radius
originalPos = {x: originalPos.x + 4, y: originalPos.y + 4};
// create mouse event for down
var downEvent = new MouseEvent('mousedown', { bubbles: true, clientX: originalPos.x, clientY: originalPos.y, view: window })
// create mouse event for drag
var dragEvent = new MouseEvent('mousemove', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
// create mouse event for up
var upEvent = new MouseEvent('mouseup', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
// fire down
cPoint.dispatchEvent(downEvent);
// fire drag
cPoint.dispatchEvent(dragEvent);
// the drag event destroys and repaints the circle control...
cPoint = canvas.querySelector("circle.control");
// fire up
cPoint.dispatchEvent(upEvent);
// check edge control point moved
// the drop event destroys and repaints the circle control...
cPoint = canvas.querySelector("circle.control");
var newPos = cPoint.getBoundingClientRect()
newPos = {x: newPos.x + 4, y: newPos.y + 4};
expect(newPos.x).toBeCloseTo(originalPos.x + 10, -1);
expect(newPos.y).toBeCloseTo(originalPos.y + 10, -1);
// check callback fired
expect(closureVar).toEqual("called");
});
// it appears this test is causing some kind of synchronicity problem. Commenting for now...
/*it("should allow for editing of same-name nodes in different layers", ()=>{
var canvas = document.querySelector("esnet-map-canvas");
// create test map topology
var newTopology = [
{
"edges": [
{"name":"A--B","meta":{"endpoint_identifiers":{"names":["A","B"]}},
"coordinates":[[39.02,-105.99],[35.81,-101.77],[34.59,-96.06]],
"children":[],
"azColor":LAVENDER,
"zaColor":LAVENDER,
}
],
"nodes": [
{
"name":"A",
"meta":{},
"coordinate":[39.02,-105.99],
"color":LAVENDER,
},
{
"name":"B",
"meta":{},
"coordinate":[34.59,-96.06],
"color":LAVENDER,
}
]
},
{
"edges": [
{"name":"A--B","meta":{"endpoint_identifiers":{"names":["A","B"]}},
"coordinates":[[49.02,-115.99],[45.81,-111.77],[44.59,-106.06]],
"children":[],
"azColor":LAVENDER,
"zaColor":LAVENDER,
}
],
"nodes": [
{
"name":"A",
"meta":{},
"coordinate":[49.02,-115.99],
"color":LAVENDER,
},
{
"name":"B",
"meta":{},
"coordinate":[44.59,-106.06],
"color":LAVENDER,
}
]
},
]
PubSub.publish("updateMapTopology", newTopology, canvas);
var newOptions = canvas.options;
newOptions.layers[1].visible = true;
PubSub.publish("updateMapOptions", {options: newOptions, changed: [
'layers[1].visible',
]}, canvas);
// enter editing mode
PubSub.publish("updateEditMode", true, canvas);
// enter Node editing mode
PubSub.publish("setEditMode", { "mode": "node", "value": true }, canvas);
// select edges that attach to node with this name, record positions
// toggle layers such that we have two layers with same-named nodes
// select the control point we want to work on
var cPoint = canvas.querySelector("circle.control.control-point-layer0");
var edgeABlayer1 = canvas.querySelector(".edge-az.l0.cnxn-A");
var beforeCoords1 = edgeABlayer1.getBoundingClientRect();
var edgeABlayer2 = canvas.querySelector(".edge-az.l1.cnxn-A");
var beforeCoords2 = edgeABlayer2.getBoundingClientRect();
var originalPos = cPoint.getBoundingClientRect();
// create mouse event for down
var downEvent = new MouseEvent('mousedown', { bubbles: true, clientX: originalPos.x, clientY: originalPos.y, view: window })
// create mouse event for drag
var dragEvent = new MouseEvent('mousemove', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
// create mouse event for up
var upEvent = new MouseEvent('mouseup', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
// fire down
cPoint.dispatchEvent(downEvent);
// fire drag
cPoint.dispatchEvent(dragEvent);
// fire up
cPoint = canvas.querySelector("circle.control");
cPoint.dispatchEvent(upEvent);
// select attached edges after, record positions
var edgeABlayer1 = canvas.querySelector(".edge-az.l0.cnxn-A");
var afterCoords1 = edgeABlayer1.getBoundingClientRect();
var edgeABlayer2 = canvas.querySelector(".edge-az.l1.cnxn-A");
var afterCoords2 = edgeABlayer2.getBoundingClientRect();
// positions for attached edges should have changed
beforeCoords1.x.should.not.equal(afterCoords1.x);
beforeCoords1.y.should.not.equal(afterCoords1.y);
// positions for "other layer" non-attached edges should be the same
beforeCoords2.x.should.equal(afterCoords2.x);
beforeCoords2.y.should.equal(afterCoords2.y);
// click layer 1 copy of "A"
var nodeAlayer1 = canvas.querySelector("circle.control.control-point-layer0");
var downEvent = new MouseEvent('mousedown', { bubbles: true, view: window })
var upEvent = new MouseEvent('mousedown', { bubbles: true, view: window })
nodeAlayer1.dispatchEvent(downEvent);
nodeAlayer1.dispatchEvent(upEvent);
// layer 1 "A" node should be selected
var classValue = nodeAlayer1.getAttribute("class");
classValue.should.contain("control-selected");
// click layer 2 copy of "A"
var nodeAlayer2 = canvas.querySelector("circle.control.control-point-layer1");
var downEvent = new MouseEvent('mousedown', { bubbles: true, view: window })
var upEvent = new MouseEvent('mousedown', { bubbles: true, view: window })
nodeAlayer2.dispatchEvent(downEvent);
nodeAlayer2.dispatchEvent(upEvent);
// layer 1 "A" node should be selected
var classValue = nodeAlayer2.getAttribute("class");
classValue.should.contain("control-selected");
// enter Edge editing mode
PubSub.publish("setEditMode", { "mode": "edge", "value": true }, canvas);
// click layer 1, edge A--B, ensure that it's selected
var edgeABlayer1 = canvas.querySelector(".controlEdge.l0.edge-az-A--B");
var downEvent = new MouseEvent('mousedown', { bubbles: true, view: window })
var upEvent = new MouseEvent('mouseup', { bubbles: true, view: window })
edgeABlayer1.dispatchEvent(downEvent);
edgeABlayer1.dispatchEvent(upEvent);
edgeABlayer1.getAttribute("class").should.contain("control-selected");
PubSub.publish("setEditMode", { "mode": "edge", "value": true }, canvas);
// click layer 2, edge A--B, ensure that it's selected
var edgeABlayer2 = canvas.querySelector(".controlEdge.l1.edge-az-A--B");
var downEvent = new MouseEvent('mousedown', { bubbles: true, view: window })
var upEvent = new MouseEvent('mouseup', { bubbles: true, view: window })
edgeABlayer2.dispatchEvent(downEvent);
edgeABlayer2.dispatchEvent(upEvent);
edgeABlayer2.getAttribute("class").should.contain("control-selected");
edgeABlayer1.getAttribute("class").should.not.contain("control-selected");
// turn off editing mode
PubSub.publish("updateEditMode", false, canvas);
var closureVar = null;
PubSub.subscribe("setSelection", function(){ closureVar = "called" }, canvas);
var edgeABlayer1 = canvas.querySelector(".edge.l0.edge-az.edge-az-A--B");
var mouseDown = new MouseEvent('mousedown', { bubbles: true, view: window });
var mouseUp = new MouseEvent('mouseup', { bubbles: true, view: window })
edgeABlayer1.dispatchEvent(mouseDown);
edgeABlayer1.dispatchEvent(mouseUp);
closureVar.should.equal("called");
// ensure we see chevrons
canvas.querySelectorAll("polygon").length.should.be.greaterThan(0);
// ensure selection class on our edge
edgeABlayer1.getAttribute("class").should.contain("animated-edge");
// click edge on other layer
var closureVar = null;
PubSub.subscribe("setSelection", function(){ closureVar = "called" }, canvas);
var edgeABlayer2 = canvas.querySelector(".edge.l1.edge-az.edge-az-A--B");
var mouseDown = new MouseEvent('mousedown', { bubbles: true, view: window });
var mouseUp = new MouseEvent('mouseup', { bubbles: true, view: window })
edgeABlayer2.dispatchEvent(mouseDown);
edgeABlayer2.dispatchEvent(mouseUp);
closureVar.should.equal("called");
// ensure we see chevrons
canvas.querySelectorAll("polygon").length.should.be.greaterThan(0);
// ensure selection class on our edge
edgeABlayer2.getAttribute("class").should.contain("animated-edge");
edgeABlayer1.getAttribute("class").should.not.contain("animated-edge");
var closureVar = null;
PubSub.subscribe("setSelection", function(){ closureVar = "called" }, canvas);
var nodeAlayer1 = canvas.querySelector(".node.l0.node-A circle");
var nodeAlayer2 = canvas.querySelector(".node.l1.node-A circle");
var mouseDown = new MouseEvent('mousedown', { bubbles: true, view: window });
var mouseUp = new MouseEvent('mouseup', { bubbles: true, view: window })
nodeAlayer1.dispatchEvent(mouseDown);
nodeAlayer1.dispatchEvent(mouseUp);
"called".should.equal(closureVar);
// ensure selection class on our edge
var nodeAlayer1 = canvas.querySelector(".node.l0.node-A .scale-container");
var nodeAlayer2 = canvas.querySelector(".node.l1.node-A .scale-container");
nodeAlayer1.getAttribute("class").should.contain("animated-node");
nodeAlayer2.getAttribute("class").should.not.contain("animated-node");
var closureVar = null;
PubSub.subscribe("setSelection", function(){ closureVar = "called" }, canvas);
var nodeAlayer1 = canvas.querySelector(".node.l0.node-A circle");
var nodeAlayer2 = canvas.querySelector(".node.l1.node-A circle");
var mouseDown = new MouseEvent('mousedown', { bubbles: true, view: window });
var mouseUp = new MouseEvent('mouseup', { bubbles: true, view: window })
nodeAlayer2.dispatchEvent(mouseDown);
nodeAlayer2.dispatchEvent(mouseUp);
"called".should.equal(closureVar);
// ensure selection class on our edge
var nodeAlayer1 = canvas.querySelector(".node.l0.node-A .scale-container");
var nodeAlayer2 = canvas.querySelector(".node.l1.node-A .scale-container");
nodeAlayer2.getAttribute("class").should.contain("animated-node");
nodeAlayer1.getAttribute("class").should.not.contain("animated-node");
})*/
it("should allow for icon and non-icon edge templates from the topology", () => {
var canvas = document.querySelector("esnet-map-canvas");
// create mouseover for edge with template
var newTopology = [
{
"edges": [
{
"name":"Z--L",
"meta":{
"endpoint_identifiers":{
"names":["Z","L"]
},
"template": "${labels.src} ABCDEF ${labels.dst} GHIJKL"
},
"coordinates":[[39.02,-105.99],[35.81,-101.77],[34.59,-96.06]],
"children":[],
"azColor":LAVENDER,
"zaColor":LAVENDER,
},
{
"name":"A--Z",
"meta":{
"endpoint_identifiers":{
"names":["A","Z"]
}
},
"coordinates":[[30.02,-105.99],[34.52,-105.99],[39.02,-105.99]],
"children":[],
"azColor":LAVENDER,
"zaColor":LAVENDER,
}
],
"nodes": [
{
"name":"A",
"meta":{},
"coordinate":[30.02,-105.99],
"color":LAVENDER,
},
{
"name":"Z",
"meta":{},
"coordinate":[39.02,-105.99],
"color":LAVENDER,
},
{
"name":"L",
"meta":{},
"coordinate":[34.59,-96.06],
"color":LAVENDER,
}
]
},
]
canvas.setTopology(newTopology);
var edgeZL = canvas.querySelector(".cnxn-Z.cnxn-L");
var edgeAZ = canvas.querySelector(".cnxn-A.cnxn-Z");
// fire mouseover
let mouseoverEvent = new Event('mouseover', { bubbles: true });
edgeZL.dispatchEvent(mouseoverEvent);
// check tooltip text
var label = canvas.querySelector(".flow-tooltip strong").innerText.trim();
expect("Z → L").toEqual(label);
var newOptions = canvas.options;
newOptions.enableCustomEdgeTooltip = true;
newOptions.customEdgeTooltip = "<div class='flow-tooltip'>${forward.from} → ${forward.to}</div>";
PubSub.publish("updateMapOptions", { options: newOptions, changed: [
"enableCustomEdgeTooltip",
]});
edgeAZ.dispatchEvent(mouseoverEvent);
var label = canvas.querySelector(".flow-tooltip").innerText.trim();
const testAZFlowMarkupStr = `A → Z`;
expect(testAZFlowMarkupStr).toEqual(label);
});
it("should santize names with non-alphanum characters", ()=>{
var canvas = document.querySelector("esnet-map-canvas");
var newTopology = [
{
"edges": [
{
"name":"Node A, Inc.--Node B - Inc.",
"meta":{
"endpoint_identifiers":{
"names":["Node A, Inc.","Node B - Inc."]
}
},
"coordinates":[[39.02,-105.99],[35.81,-101.77],[34.59,-96.06]],
"children":[],
"azColor":LAVENDER,
"zaColor":LAVENDER,
}
],
"nodes": [
{
"name":"Node A, Inc.",
"meta":{},
"coordinate":[39.02,-105.99],
"color":LAVENDER,
},
{
"name":"Node B - Inc.",
"meta":{},
"coordinate":[34.59,-96.06],
"color":LAVENDER,
}
]
},
]
// set topology with weird names for both edges and nodes
canvas.setTopology(newTopology);
// node edit mode
canvas.setEditMode("node");
// measure edge endpoints
var edgeAB = canvas.querySelector(".edge-az");
var beforeCoords = edgeAB.getBoundingClientRect();
var cPoint = canvas.querySelector("circle.control.control-point-for-node-Node-A-Inc");
var originalPos = cPoint.getBoundingClientRect();
// create mouse event for down
var downEvent = new MouseEvent('mousedown', { bubbles: true, clientX: originalPos.x, clientY: originalPos.y, view: window })
// create mouse event for drag
var dragEvent = new MouseEvent('mousemove', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
// create mouse event for up
var upEvent = new MouseEvent('mouseup', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
cPoint.dispatchEvent(downEvent);
cPoint.dispatchEvent(dragEvent);
cPoint = canvas.querySelector("circle.control");
// drag a node with weird name.
cPoint.dispatchEvent(upEvent);
// do edges move?
var edgeAB = canvas.querySelector(".edge-az");
var afterCoords = edgeAB.getBoundingClientRect();
expect(beforeCoords.x).not.toEqual(afterCoords.x);
expect(beforeCoords.y).not.toEqual(afterCoords.y);
// drag a control point for edge with weird name. All good?
var cPoint = canvas.querySelector("circle.control.control-point-for-node-Node-B-Inc");
var edgeAB = canvas.querySelector(".edge-az");
var beforeCoords = edgeAB.getBoundingClientRect();
// create mouse event for down
var downEvent = new MouseEvent('mousedown', { bubbles: true, clientX: originalPos.x, clientY: originalPos.y, view: window })
// create mouse event for drag
var dragEvent = new MouseEvent('mousemove', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
// create mouse event for up
var upEvent = new MouseEvent('mouseup', { bubbles: true, clientX: originalPos.x + 10, clientY: originalPos.y + 10, view: window })
cPoint.dispatchEvent(downEvent);
cPoint.dispatchEvent(dragEvent);
cPoint = canvas.querySelector("circle.control");
cPoint.dispatchEvent(upEvent);
// drag a node with weird name.
var edgeAB = canvas.querySelector(".edge-az");
var afterCoords = edgeAB.getBoundingClientRect();
expect(beforeCoords.x).not.toEqual(afterCoords.x);
expect(beforeCoords.y).not.toEqual(afterCoords.y);
})
it("should not animate nodes if the appropriate option is set", ()=>{
let canvas = document.querySelector("esnet-map-canvas");
canvas.setTopology(JSON.parse(JSON.stringify(TOPOLOGY)));
let node = canvas.querySelector(".node-A circle");
let style = window.getComputedStyle(node);
let originalPos = node.getBoundingClientRect();
let downEvent = new MouseEvent('mousedown', { bubbles: true, clientX: originalPos.x, clientY: originalPos.y, view: window })
let upEvent = new MouseEvent('mouseup', { bubbles: true, clientX: originalPos.x, clientY: originalPos.y, view: window })
node.dispatchEvent(downEvent);
node.dispatchEvent(upEvent);
node = canvas.querySelector(".animated-node");
style = window.getComputedStyle(node);
let animationWhileTrue = style.animation;
let newOptions = {...canvas.options};
newOptions['enableNodeAnimation'] = false;
let changes = canvas.calculateOptionsChanges(newOptions);
canvas.setOptions(newOptions);
node = canvas.querySelector(".animated-node");
style = window.getComputedStyle(node);
let animationWhileFalse = style.animation;
expect(animationWhileTrue).toMatch("throb");
expect(animationWhileFalse).not.toEqual(animationWhileTrue);
})
it("should append tooltips to the correct DOM element in a context with multiple instances", ()=>{
var canvas = document.querySelector("esnet-map-canvas");
var newOptions = JSON.parse(JSON.stringify(canvas.options));
newOptions.showSidebar = false;
canvas.setOptions(newOptions);
var elem2 = document.createElement("esnet-map-canvas");
elem2.setAttribute('width', 800);
elem2.setAttribute('height', 400);
elem2.setAttribute("id", "testing-element2");
elem2.setTopology(TOPOLOGY);
elem2.setOptions(newOptions);
document.body.appendChild(elem2);
var edge = elem2.querySelector('.edge.edge-az');
let mouseoverEvent = new Event('mouseover', { bubbles: true });
edge.dispatchEvent(mouseoverEvent);
var tooltip = document.querySelector("#tooltip-hover")
expect(tooltip.parentElement.id).toEqual(`map-${elem2.instanceId}`);