From 2a084466dfcb504d61d031e19ccf26430db7ce05 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 1 Mar 2024 15:45:07 +0100 Subject: [PATCH 1/2] fix: make sure to reset feature query string parameter fix #1662 --- umap/static/umap/js/umap.share.js | 2 ++ umap/tests/integration/test_share.py | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/umap/static/umap/js/umap.share.js b/umap/static/umap/js/umap.share.js index a70930b0..167f73d1 100644 --- a/umap/static/umap/js/umap.share.js +++ b/umap/static/umap/js/umap.share.js @@ -226,6 +226,8 @@ U.IframeExporter = L.Evented.extend({ const datalayers = [] if (this.options.viewCurrentFeature && this.map.currentFeature) { this.queryString.feature = this.map.currentFeature.getSlug() + } else { + delete this.queryString.feature } if (this.options.keepCurrentDatalayers) { this.map.eachDataLayer((datalayer) => { diff --git a/umap/tests/integration/test_share.py b/umap/tests/integration/test_share.py index 3c4b1ec8..2b3c83c6 100644 --- a/umap/tests/integration/test_share.py +++ b/umap/tests/integration/test_share.py @@ -6,7 +6,7 @@ from playwright.sync_api import expect pytestmark = pytest.mark.django_db -def test_iframe_code(map, live_server, datalayer, page): +def test_iframe_code_can_contain_datalayers(map, live_server, datalayer, page): page.goto(f"{live_server.url}{map.get_absolute_url()}?share") textarea = page.locator(".umap-share-iframe") expect(textarea).to_be_visible() @@ -20,3 +20,21 @@ def test_iframe_code(map, live_server, datalayer, page): page.get_by_text("Embed and link options").click() page.get_by_title("Keep current visible layers").click() expect(textarea).to_have_text(re.compile(f"datalayers={datalayer.pk}")) + # Now click again + page.get_by_title("Keep current visible layers").click() + expect(textarea).not_to_have_text(re.compile(f"datalayers={datalayer.pk}")) + + +def test_iframe_code_can_contain_feature(map, live_server, datalayer, page): + page.goto(f"{live_server.url}{map.get_absolute_url()}?share") + page.locator(".icon_container").click() + textarea = page.locator(".umap-share-iframe") + expect(textarea).to_be_visible() + expect(textarea).not_to_have_text(re.compile("feature=Here")) + # Open options + page.get_by_text("Embed and link options").click() + page.get_by_title("Open current feature on load").click() + expect(textarea).to_have_text(re.compile("feature=Here")) + # Click again to deactivate it + page.get_by_title("Open current feature on load").click() + expect(textarea).not_to_have_text(re.compile("feature=Here")) From dee6073428b84596472f6fac969ff8661c2db831 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 1 Mar 2024 15:49:27 +0100 Subject: [PATCH 2/2] chore: add test to cover opening feature on load --- umap/tests/integration/test_map_preview.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/umap/tests/integration/test_map_preview.py b/umap/tests/integration/test_map_preview.py index 9176eba8..ca338956 100644 --- a/umap/tests/integration/test_map_preview.py +++ b/umap/tests/integration/test_map_preview.py @@ -73,3 +73,11 @@ def test_map_preview_can_change_styling_from_querystring(page, live_server, tile markers = page.locator(".leaflet-marker-icon .icon_container") expect(markers).to_have_count(1) expect(markers).to_have_css("background-color", "rgb(139, 0, 0)") + + +def test_can_open_feature_on_load(page, live_server, tilelayer): + page.goto( + f"{live_server.url}/map/?data={quote(json.dumps(GEOJSON))}&feature=Niagara Falls" + ) + # Popup is open. + expect(page.get_by_text("Niagara Falls")).to_be_visible()