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

Call Streamlit.setFrameHeight to set frame height correctly #237

Merged
merged 2 commits into from
Nov 14, 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
1 change: 1 addition & 0 deletions streamlit_folium/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ async function onRender(event: Event) {
})
}
finalizeOnRender()
Streamlit.setFrameHeight()
}

// Attach our `onRender` handler to Streamlit's render event.
Expand Down
24 changes: 24 additions & 0 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]').get_by_text(
"Parcels"
)
).not_to_be_checked()

Check failure on line 383 in tests/test_frontend.py

View workflow job for this annotation

GitHub Actions / build (3.12)

test_layer_control_dynamic_update[chromium] AssertionError: Locator expected not to be checked Actual value: True Call log: LocatorAssertions.not_to_be_checked with timeout 5000ms - waiting for locator("iframe[title=\"streamlit_folium\\.st_folium\"]").content_frame.get_by_text("Parcels") - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked"

Check failure on line 383 in tests/test_frontend.py

View workflow job for this annotation

GitHub Actions / build (3.13)

test_layer_control_dynamic_update[chromium] AssertionError: Locator expected not to be checked Actual value: True Call log: LocatorAssertions.not_to_be_checked with timeout 5000ms - waiting for locator("iframe[title=\"streamlit_folium\\.st_folium\"]").content_frame.get_by_text("Parcels") - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked" - locator resolved to <span> Parcels</span> - unexpected value "checked"
expect(
page.frame_locator('iframe[title="streamlit_folium\\.st_folium"]').get_by_text(
"Buildings"
Expand All @@ -391,3 +391,27 @@
.get_by_role("img")
.locator("path")
).to_be_visible()


def test_frame_height_matches_content_height(page: Page):
"""Make sure that the frame height matches the document height to confirm that
Streamlit.setFrameHeight was called correctly."""

iframe = page.get_by_test_id("stCustomComponentV1")
iframe_html = page.frame_locator("[data-testid=stCustomComponentV1]").locator(
"html"
)

# Wait for the iframe to load and have a height - otherwise the test will be flaky
page.wait_for_function(
"el => window.getComputedStyle(el).height !== '0px'",
arg=iframe.element_handle(),
)

# Now make sure that the heights match
iframe_height = iframe.evaluate("el => window.getComputedStyle(el).height")
iframe_html_height = iframe_html.evaluate(
"el => window.getComputedStyle(el).height"
)

assert iframe_height == iframe_html_height
Loading