Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error where default_css was missing #201

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="streamlit_folium",
version="0.21.0",
version="0.21.1",
author="Randy Zwitch",
author_email="[email protected]",
description="Render Folium objects in Streamlit",
Expand Down
4 changes: 2 additions & 2 deletions streamlit_folium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ def walk(fig):
0, "https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"
)
js_links.insert(0, "https://d3js.org/d3.v4.min.js")
css_links.extend([href for _, href in elem.default_css])
js_links.extend([src for _, src in elem.default_js])
css_links.extend([href for _, href in getattr(elem, "default_css", [])])
js_links.extend([src for _, src in getattr(elem, "default_js", [])])

component_value = _component_func(
script=leaflet,
Expand Down
67 changes: 42 additions & 25 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

from contextlib import contextmanager
from time import sleep

import pytest
from playwright.sync_api import Page, expect
from playwright.sync_api import Page, Response, expect

LOCAL_TEST = False

Expand All @@ -20,6 +22,7 @@ def before_module():
def before_test(page: Page):
page.goto(f"localhost:{PORT}")
page.set_viewport_size({"width": 2000, "height": 2000})
expect.set_options(timeout=5_000)


# Take screenshot of each page if there are failures for this session
Expand Down Expand Up @@ -61,17 +64,39 @@ def run_streamlit():
p.kill()


def click_button_or_marker(page: Page, nth: int = 0, locator: str | None = None):
"""For some reason, there's a discrepancy between how the map markers are
selectable locally and on github actions, perhaps related some error in loading
the actual marker images. This tries both ways to select a marker"""

frame = page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]')
if locator is not None:
frame = frame.locator(locator)
try:
frame.get_by_role("button", name="Marker").nth(nth).click(timeout=5_000)
except Exception:
frame.get_by_role("img").nth(nth).click(timeout=5_000)


def test_marker_click(page: Page):
def check_for_404(response: Response):
if not response.ok:
print(response)
print(response.text())
print(response.url)
print(response.status)
raise Exception("404")

page.on("response", check_for_404)

# Check page title
expect(page).to_have_title("streamlit-folium documentation")

expect(page.get_by_text('"last_object_clicked":NULL')).to_be_visible()

# Click marker
try:
page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]').get_by_role(
"button", name="Marker"
).click()
click_button_or_marker(page)
except Exception as e:
page.screenshot(path="screenshot-test-marker-click.png", full_page=True)
raise e
Expand Down Expand Up @@ -119,15 +144,11 @@ def test_limit_data(page: Page):
expect(page.get_by_text('{"last_object_clicked":NULL}')).to_be_visible()

# Click marker
page.frame_locator(
'internal:attr=[title="streamlit_folium.st_folium"i]'
).get_by_role("button").nth(2).click()
click_button_or_marker(page, 2)

# Have to click a second time for some reason, maybe because it doesn't load right
# away
page.frame_locator(
'internal:attr=[title="streamlit_folium.st_folium"i]'
).get_by_role("button").nth(2).click()
click_button_or_marker(page, 2)

expect(page.get_by_text('{"last_object_clicked":{"lat":39.96')).to_be_visible()

Expand All @@ -144,12 +165,8 @@ def test_dual_map(page: Page):

# Click marker on left map
try:
page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]').locator(
"#map_div"
).get_by_role("button", name="Marker").click()
page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]').locator(
"#map_div2"
).get_by_role("button", name="Marker").click()
click_button_or_marker(page, 0, "#map_div")
click_button_or_marker(page, 0, "#map_div2")
except Exception as e:
page.screenshot(path="screenshot-dual-map.png", full_page=True)
raise e
Expand All @@ -170,9 +187,7 @@ def test_tooltip_click(page: Page):
expect(page.get_by_text('"last_object_clicked_tooltip":NULL')).to_be_visible()

# Click marker on map
page.frame_locator(
'internal:attr=[title="streamlit_folium.st_folium"i]'
).get_by_role("button").nth(0).click()
click_button_or_marker(page)

expect(
page.get_by_text('"last_object_clicked_tooltip":"Liberty Bell"')
Expand All @@ -186,9 +201,7 @@ def test_popup_text(page: Page):
expect(page.get_by_text("Popup: None")).to_be_visible()
expect(page.get_by_text("Tooltip: None")).to_be_visible()

page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]').get_by_role(
"button"
).nth(0).click()
click_button_or_marker(page)

try:
expect(page.get_by_text("Popup: Popup!")).to_be_visible()
Expand All @@ -207,9 +220,7 @@ def test_return_on_hover(page: Page):

page.get_by_text("Return on hover?").click()

page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]').get_by_role(
"button"
).nth(1).hover()
click_button_or_marker(page, 1)

try:
expect(page.get_by_text("Popup: Popup 2!")).to_be_visible()
Expand Down Expand Up @@ -273,6 +284,12 @@ def test_grouped_layer_control(page: Page):
).check()


def test_geojson_popup(page: Page):
page.get_by_role("link", name="geojson popup").click()

expect(page.get_by_text("AttributeError")).to_be_hidden()


def test_dynamic_feature_group_update(page: Page):
page.get_by_role("link", name="dynamic updates").click()
page.get_by_text("Show generated code").click()
Expand Down
Loading