From cf13d1575354d669a6837a00b93202613d9547fc Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 16 Jan 2024 19:58:10 +0100 Subject: [PATCH] fix: honour datalayersControl=expanded in querystring fix #1525 --- umap/static/umap/js/umap.js | 5 +++ umap/tests/integration/test_querystring.py | 39 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 umap/tests/integration/test_querystring.py diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 88d328e7..bf0f5f91 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -122,6 +122,11 @@ L.U.Map.include({ `${this.HIDDABLE_CONTROLS[i]}Control` ) } + // Specific case for datalayersControl + // which accept "expanded" value, on top of true/false/null + if (L.Util.queryString('datalayersControl') === 'expanded') { + L.Util.setFromQueryString(this.options, 'datalayersControl') + } this.datalayersOnLoad = L.Util.queryString('datalayers') this.options.onLoadPanel = L.Util.queryString( 'onLoadPanel', diff --git a/umap/tests/integration/test_querystring.py b/umap/tests/integration/test_querystring.py new file mode 100644 index 00000000..faab701e --- /dev/null +++ b/umap/tests/integration/test_querystring.py @@ -0,0 +1,39 @@ +import pytest +from playwright.sync_api import expect + +pytestmark = pytest.mark.django_db + + +def test_scale_control(map, live_server, datalayer, page): + control = page.locator(".leaflet-control-scale") + page.goto(f"{live_server.url}{map.get_absolute_url()}") + expect(control).to_be_visible() + page.goto(f"{live_server.url}{map.get_absolute_url()}?scaleControl=false") + expect(control).to_be_hidden() + + +def test_datalayers_control(map, live_server, datalayer, page): + control = page.locator(".umap-browse-toggle") + box = page.locator(".umap-browse-datalayers") + more = page.get_by_title("More controls") + page.goto(f"{live_server.url}{map.get_absolute_url()}") + expect(control).to_be_visible() + expect(box).to_be_hidden() + page.goto(f"{live_server.url}{map.get_absolute_url()}?datalayersControl=true") + expect(control).to_be_visible() + expect(box).to_be_hidden() + page.goto(f"{live_server.url}{map.get_absolute_url()}?datalayersControl=null") + expect(control).to_be_hidden() + expect(more).to_be_visible() + more.click() + expect(control).to_be_visible() + expect(box).to_be_hidden() + page.goto(f"{live_server.url}{map.get_absolute_url()}?datalayersControl=false") + expect(control).to_be_hidden() + expect(more).to_be_visible() + more.click() + expect(control).to_be_hidden() + expect(box).to_be_hidden() + page.goto(f"{live_server.url}{map.get_absolute_url()}?datalayersControl=expanded") + expect(control).to_be_hidden() + expect(box).to_be_visible()