From 882cc74bcfe9f0e851e86ed649fcae40a569dcb8 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 27 Oct 2023 12:25:40 +0200 Subject: [PATCH] Fix displayOnLoad not honoured at import fix #1043 --- umap/static/umap/js/umap.layer.js | 1 + umap/tests/fixtures/display_on_load.umap | 85 ++++++++++++++++++++++++ umap/tests/integration/test_import.py | 25 +++++++ 3 files changed, 111 insertions(+) create mode 100644 umap/tests/fixtures/display_on_load.umap create mode 100644 umap/tests/integration/test_import.py diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 1200f8c2..d2661d24 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -1114,6 +1114,7 @@ L.U.DataLayer = L.Evented.extend({ }, redraw: function () { + if (!this.isVisible()) return this.hide() this.show() }, diff --git a/umap/tests/fixtures/display_on_load.umap b/umap/tests/fixtures/display_on_load.umap new file mode 100644 index 00000000..d83ed9fb --- /dev/null +++ b/umap/tests/fixtures/display_on_load.umap @@ -0,0 +1,85 @@ +{ + "type": "umap", + "uri": "http://localhost:8020/fr/map/carte-sans-nom_128#6/50.233/6.910", + "properties": { + "easing": false, + "embedControl": true, + "fullscreenControl": true, + "searchControl": true, + "datalayersControl": true, + "zoomControl": true, + "permanentCreditBackground": true, + "slideshow": {}, + "captionMenus": true, + "captionBar": false, + "limitBounds": {}, + "overlay": null, + "licence": "", + "description": "", + "name": "Carte sans nom", + "displayPopupFooter": false, + "miniMap": false, + "moreControl": true, + "scaleControl": true, + "scrollWheelZoom": true, + "zoom": 6 + }, + "geometry": { + "type": "Point", + "coordinates": [ + 6.734619140625, + 50.359480346298696 + ] + }, + "layers": [ + { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 5.141602, + 50.889174 + ] + } + } + ], + "_umap_options": { + "displayOnLoad": true, + "inCaption": true, + "browsable": true, + "editMode": "advanced", + "name": "Visible", + "remoteData": {} + } + }, + { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 5.383301, + 49.809632 + ] + } + } + ], + "_umap_options": { + "displayOnLoad": false, + "inCaption": true, + "browsable": true, + "editMode": "advanced", + "remoteData": {}, + "name": "Invisible", + "color": "DarkRed" + } + } + ] +} diff --git a/umap/tests/integration/test_import.py b/umap/tests/integration/test_import.py new file mode 100644 index 00000000..06b70138 --- /dev/null +++ b/umap/tests/integration/test_import.py @@ -0,0 +1,25 @@ +from pathlib import Path + +import pytest +from playwright.sync_api import expect + +pytestmark = pytest.mark.django_db + + +def test_umap_import(live_server, datalayer, page): + page.goto(f"{live_server.url}/map/new/") + button = page.get_by_title("Import data (Ctrl+I)") + expect(button).to_be_visible() + button.click() + with page.expect_file_chooser() as fc_info: + page.locator("input[type='file']").click() + file_chooser = fc_info.value + path = Path(__file__).parent.parent / "fixtures/display_on_load.umap" + file_chooser.set_files(path) + button = page.get_by_role("button", name="Import") + expect(button).to_be_visible() + button.click() + layers = page.locator(".umap-browse-datalayers li") + expect(layers).to_have_count(3) + nonloaded = page.locator(".umap-browse-datalayers li.off") + expect(nonloaded).to_have_count(1)