diff --git a/src/utils.py b/src/utils.py
index 642bad4..09eca00 100644
--- a/src/utils.py
+++ b/src/utils.py
@@ -80,15 +80,21 @@ def add_links(dff: pl.DataFrame):
.alias(col)
)
if col.startswith("acheteur_"):
- dff = dff.with_columns(
- (
- ''
- + pl.col(col)
- + ""
- ).alias(col)
+ detail_link = (
+ ''
+ + pl.col(col)
+ + ""
)
+ if col == "acheteur_nom":
+ detail_link = (
+ detail_link
+ + ' 📊'
+ )
+ dff = dff.with_columns(detail_link.alias(col))
if col == "uid":
dff = dff.with_columns(
(
@@ -648,7 +654,7 @@ def prepare_table_data(
# Remplace les strings null par "", mais pas les numeric null
dff = dff.fill_null("")
- # Ajout des liens vers l'annuaire des entreprises
+ # Ajout des liens vers les pages de détails
dff = add_links(dff)
# Ajout des liens vers les fichiers Open Data
diff --git a/tests/test_main.py b/tests/test_main.py
index 1b8e7db..39b38a2 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -29,12 +29,11 @@ def test_001_logo_and_search(dash_duo: DashComposite):
assert len(result_table.find_elements(by=By.TAG_NAME, value="tr")) == 2, (
"The search should return only one result"
) # header row + 1 result
- assert (
- result_table.find_element(
- by=By.CSS_SELECTOR, value=f'td[data-dash-column="{org_type}_nom"]'
- ).text
- == name
- ), f"The search result should have the right {org_type} name"
+ assert result_table.find_element(
+ by=By.CSS_SELECTOR, value=f'td[data-dash-column="{org_type}_nom"]'
+ ).text.startswith(name), (
+ f"The search result should have the right {org_type} name"
+ )
def test_002_filter_persistence(dash_duo: DashComposite):
@@ -87,3 +86,28 @@ def test_003_tableau_download(dash_duo: DashComposite):
)
assert output["type"] is None
assert output["base64"] is True
+
+
+def test_004_add_links_observatoire_acheteur():
+ import polars as pl
+
+ from src.utils import add_links
+
+ dff = pl.DataFrame(
+ {
+ "acheteur_id": ["a1"],
+ "acheteur_nom": ["ACHETEUR 1"],
+ }
+ )
+ result = add_links(dff)
+ nom_value = result["acheteur_nom"][0]
+ id_value = result["acheteur_id"][0]
+
+ # acheteur_nom should contain detail link + observatoire link
+ assert "/acheteurs/a1" in nom_value
+ assert "ACHETEUR 1" in nom_value
+ assert "/observatoire?acheteur_id=a1" in nom_value
+ assert "📊" in nom_value
+
+ # acheteur_id should NOT contain observatoire link
+ assert "/observatoire" not in id_value