streamlit
61 строка · 2.6 Кб
1# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
16from playwright.sync_api import Page, expect17
18from e2e_playwright.conftest import ImageCompareFunction19
20
21def test_status_container_rendering(22themed_app: Page, assert_snapshot: ImageCompareFunction23):24"""Test that st.status renders correctly via screenshots."""25status_containers = themed_app.get_by_test_id("stExpander")26expect(status_containers).to_have_count(9)27
28# Don't check screenshot for first element,29# since we cannot reliably screenshot test the spinner icon.30
31assert_snapshot(status_containers.nth(1), name="st_status-complete_state")32assert_snapshot(status_containers.nth(2), name="st_status-error_state")33assert_snapshot(status_containers.nth(3), name="st_status-collapsed")34assert_snapshot(status_containers.nth(4), name="st_status-changed_label")35assert_snapshot(status_containers.nth(5), name="st_status-without_cm")36assert_snapshot(status_containers.nth(6), name="st_status-collapsed_via_update")37assert_snapshot(status_containers.nth(7), name="st_status-empty_state")38assert_snapshot(status_containers.nth(8), name="st_status-uncaught_exception")39
40
41def test_running_state(app: Page):42"""Test that st.status renders a spinner when in running state."""43running_status = app.get_by_test_id("stExpander").nth(0)44# Check if it has a spinner icon:45expect(running_status.get_by_test_id("stExpanderIconSpinner")).to_be_visible()46
47
48def test_status_collapses_and_expands(app: Page):49"""Test that a status collapses and expands."""50expander_content = "Doing some work..."51running_status = app.get_by_test_id("stExpander").nth(0)52# Starts expanded:53expect(running_status.get_by_text(expander_content)).to_be_visible()54
55expander_header = running_status.locator("summary")56# Collapse:57expander_header.click()58expect(running_status.get_by_text(expander_content)).not_to_be_visible()59# Expand:60expander_header.click()61expect(running_status.get_by_text(expander_content)).to_be_visible()62