From 009f2c916f01c0c5513d766aeac461e5f2ed1bd8 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 7 Feb 2024 19:37:45 +0100 Subject: [PATCH] fix: use variable for color in browser if any --- umap/static/umap/js/umap.browser.js | 2 +- umap/tests/integration/test_browser.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/umap/static/umap/js/umap.browser.js b/umap/static/umap/js/umap.browser.js index 01e2dcda..a43b0e4f 100644 --- a/umap/static/umap/js/umap.browser.js +++ b/umap/static/umap/js/umap.browser.js @@ -22,7 +22,7 @@ L.U.Browser = L.Class.extend({ edit.title = L._('Edit this feature') del.title = L._('Delete this feature') title.textContent = feature.getDisplayName() || '—' - const bgcolor = feature.getOption('color') + const bgcolor = feature.getDynamicOption('color') colorBox.style.backgroundColor = bgcolor if (symbol && symbol !== this.map.options.default_iconUrl) { const icon = L.U.Icon.makeIconElement(symbol, colorBox) diff --git a/umap/tests/integration/test_browser.py b/umap/tests/integration/test_browser.py index 4a619e6e..c665f71f 100644 --- a/umap/tests/integration/test_browser.py +++ b/umap/tests/integration/test_browser.py @@ -228,3 +228,22 @@ def test_should_show_header_for_display_on_load_false( browser = page.locator(".umap-browse-data") expect(browser).to_be_visible() expect(browser.get_by_text("This layer is not loaded")).to_be_visible() + + +def test_should_use_color_variable(live_server, map, page): + map.settings["properties"]["onLoadPanel"] = "databrowser" + map.settings["properties"]["color"] = "{mycolor}" + map.save() + datalayer_data = deepcopy(DATALAYER_DATA) + datalayer_data["features"][0]["properties"]["mycolor"] = "DarkRed" + datalayer_data["features"][2]["properties"]["mycolor"] = "DarkGreen" + DataLayerFactory(map=map, data=datalayer_data) + page.goto(f"{live_server.url}{map.get_absolute_url()}") + features = page.locator(".umap-browse-data li .feature-color") + expect(features).to_have_count(3) + # DarkGreen + expect(features.nth(0)).to_have_css("background-color", "rgb(0, 100, 0)") + # DarkRed + expect(features.nth(1)).to_have_css("background-color", "rgb(139, 0, 0)") + # DarkBlue (default color) + expect(features.nth(2)).to_have_css("background-color", "rgb(0, 0, 139)")