From dcbec3534c6fe3a47377103ca67c1cad47d9e314 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 22 Sep 2023 20:48:08 +0200 Subject: [PATCH] Fix datalayer's data duplicated at first save --- umap/static/umap/js/umap.layer.js | 3 ++- umap/tests/integration/test_owned_map.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 81a4cd21..8bc110b4 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -317,7 +317,8 @@ L.U.DataLayer = L.Evented.extend({ }, resetLayer: function (force) { - if (this.layer && this.options.type === this.layer._type && !force) return + // Only reset if type is defined (undefined is the default) and different from current type + if (this.layer && (!this.options.type || this.options.type === this.layer._type) && !force) return const visible = this.isVisible() if (this.layer) this.layer.clearLayers() // delete this.layer? diff --git a/umap/tests/integration/test_owned_map.py b/umap/tests/integration/test_owned_map.py index 75becdcc..2395edd5 100644 --- a/umap/tests/integration/test_owned_map.py +++ b/umap/tests/integration/test_owned_map.py @@ -168,6 +168,24 @@ def test_editor_do_not_have_delete_map_button(map, live_server, login, user): expect(delete).to_be_hidden() +def test_create(tilelayer, live_server, login, user): + page = login(user) + page.goto(f"{live_server.url}/en/map/new") + add_marker = page.get_by_title("Draw a marker") + map_el = page.locator("#map") + expect(add_marker).to_be_visible() + marker = page.locator(".leaflet-marker-icon") + expect(marker).to_have_count(0) + add_marker.click() + map_el.click(position={"x": 100, "y": 100}) + expect(marker).to_have_count(1) + save = page.get_by_title("Save current edits") + expect(save).to_be_visible() + save.click() + sleep(1) # Let save ajax go back + expect(marker).to_have_count(1) + + def test_can_change_perms_after_create(tilelayer, live_server, login, user): page = login(user) page.goto(f"{live_server.url}/en/map/new")