Skip to content

Commit d8082d5

Browse files
authored
Merge branch 'master' into fix/issue-392
2 parents a34eb50 + 630e8f9 commit d8082d5

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

public/example_templates/netjsonmap-plugins.html

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
<script type="text/javascript" src="../lib/js/leaflet-measure.js"></script>
2828
<script type="module">
2929
/*
30-
The demo is used to show how to use the leaflet plugins.
31-
Mainly the operation of leaflet.
32-
See below for details.
30+
The demo is used to show how to use the leaflet plugins.
31+
Mainly the operation of leaflet.
32+
See below for details.
3333
*/
3434
const graph = new NetJSONGraph("../assets/data/netjsonmap.json", {
3535
render: "map",
@@ -44,7 +44,6 @@
4444
},
4545
},
4646
},
47-
4847
// Convert to internal json format
4948
prepareData: (data) => {
5049
data.nodes.map((node) => {
@@ -54,13 +53,12 @@
5453
});
5554
});
5655
},
57-
5856
// Load related plugins after the map is rendered
5957
onReady: function () {
6058
/*
61-
The map has this property only after the map is rendered,
62-
so we have to put the relevant function in `onLoad` life cycle
63-
*/
59+
The map has this property only after the map is rendered,
60+
so we have to put the relevant function in `onLoad` life cycle
61+
*/
6462
let map = this.leaflet,
6563
editableLayers = new L.FeatureGroup(),
6664
// Plugin related configuration
@@ -101,28 +99,24 @@
10199
},
102100
},
103101
edit: {
104-
featureGroup: editableLayers, //REQUIRED!!
102+
featureGroup: editableLayers, // REQUIRED!!
105103
remove: true,
106104
},
107105
};
108-
109106
map.addLayer(editableLayers);
110107
map.addControl(new L.Control.Draw(options));
111108
map.on(L.Draw.Event.CREATED, function (e) {
112109
var type = e.layerType,
113110
layer = e.layer;
114-
115111
if (type === "marker") {
116112
layer.bindPopup("A popup!");
117113
}
118114

119115
editableLayers.addLayer(layer);
120116
});
121-
122117
L.control.measure({}).addTo(map);
123118
},
124119
});
125-
126120
graph.render();
127121
</script>
128122
</body>

test/browser.test.utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const urls = {
3939
geoJson: `${url}/examples/njg-geojson.html`,
4040
movingNode: `${url}/examples/netjsonmap-moving-node.html`,
4141
clustering: `${url}/examples/netjson-clustering.html`,
42+
leafletPlugins: `${url}/examples/netjsonmap-plugins.html`,
4243
};
4344

4445
export const getElementByCss = async (driver, css, waitTime = 1000) => {

test/netjsongraph.browser.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,4 +522,33 @@ describe("Chart Rendering Test", () => {
522522
expect(finalNodeCount).toBeGreaterThan(5);
523523
expect(initialNodeCount).toBeGreaterThan(0);
524524
});
525+
526+
test("render geo map with leaflet plugins without console errors", async () => {
527+
await driver.get(urls.leafletPlugins);
528+
const leafletContainer = await getElementByCss(
529+
driver,
530+
".ec-extension-leaflet",
531+
2000,
532+
);
533+
const drawToolbar = await getElementByCss(driver, ".leaflet-draw-toolbar", 2000);
534+
const drawSection = await getElementByCss(driver, ".leaflet-draw-section", 2000);
535+
const drawPolylineBtn = await getElementByCss(
536+
driver,
537+
".leaflet-draw-draw-polyline",
538+
2000,
539+
);
540+
const measureControl = await getElementByCss(
541+
driver,
542+
".leaflet-control-measure",
543+
2000,
544+
);
545+
const consoleErrors = await captureConsoleErrors(driver);
546+
printConsoleErrors(consoleErrors);
547+
expect(consoleErrors.length).toBe(0);
548+
expect(leafletContainer).not.toBeNull();
549+
expect(drawToolbar).not.toBeNull();
550+
expect(drawSection).not.toBeNull();
551+
expect(drawPolylineBtn).not.toBeNull();
552+
expect(measureControl).not.toBeNull();
553+
});
525554
});

0 commit comments

Comments
 (0)