Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@
"leaflet/GeoJsonTest.js",
"leaflet/FeatureBuilderTest.js",
"leaflet/JQueryLeafletTest.js",
"leaflet/LeafletEditorTest.js",
"MapSaverTest.js"
],
"dependencies": [
Expand Down
4 changes: 3 additions & 1 deletion resources/leaflet/LeafletEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@

self.remove = function() {
self.drawControl.remove();
self.saveButton.remove();
if (self.saveButton) {
self.saveButton.remove();
}
self.geoJsonLayer.remove();
};

Expand Down
58 changes: 58 additions & 0 deletions tests/js/leaflet/LeafletEditorTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
( function () {
'use strict';

QUnit.module( 'Maps.LeafletEditor', {
beforeEach: function () {
this.$container = $( '<div>' ).css( { width: '400px', height: '300px' } ).appendTo( '#qunit-fixture' );
this.map = L.map( this.$container[ 0 ], { center: [ 52, 5 ], zoom: 10 } );
this.mapSaver = new window.maps.MapSaver( 'TestPage' );
},
afterEach: function () {
this.map.remove();
}
} );

QUnit.test( 'remove() does not crash when no edits were made', function ( assert ) {
var editor = window.maps.leaflet.LeafletEditor(
this.map,
this.mapSaver
);

editor.initialize( { type: 'FeatureCollection', features: [] } );

var layerCountBefore = 0;
this.map.eachLayer( function () { layerCountBefore++; } );

editor.remove();

var layerCountAfter = 0;
this.map.eachLayer( function () { layerCountAfter++; } );

assert.true( layerCountAfter < layerCountBefore, 'GeoJSON layer was removed from the map' );
} );

QUnit.test( 'remove() cleans up after edits were made', function ( assert ) {
var editor = window.maps.leaflet.LeafletEditor(
this.map,
this.mapSaver
);

editor.initialize( { type: 'FeatureCollection', features: [] } );

// Simulate a created feature to trigger _showSaveButton
this.map.fire( L.Draw.Event.CREATED, {
layer: L.marker( [ 52, 5 ] )
} );

var layerCountBefore = 0;
this.map.eachLayer( function () { layerCountBefore++; } );

editor.remove();

var layerCountAfter = 0;
this.map.eachLayer( function () { layerCountAfter++; } );

assert.true( layerCountAfter < layerCountBefore, 'Layers were removed from the map after edits' );
} );

}() );
Loading