streamlit

Форк
0
/
st_status_test.py 
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

16
from playwright.sync_api import Page, expect
17

18
from e2e_playwright.conftest import ImageCompareFunction
19

20

21
def test_status_container_rendering(
22
    themed_app: Page, assert_snapshot: ImageCompareFunction
23
):
24
    """Test that st.status renders correctly via screenshots."""
25
    status_containers = themed_app.get_by_test_id("stExpander")
26
    expect(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

31
    assert_snapshot(status_containers.nth(1), name="st_status-complete_state")
32
    assert_snapshot(status_containers.nth(2), name="st_status-error_state")
33
    assert_snapshot(status_containers.nth(3), name="st_status-collapsed")
34
    assert_snapshot(status_containers.nth(4), name="st_status-changed_label")
35
    assert_snapshot(status_containers.nth(5), name="st_status-without_cm")
36
    assert_snapshot(status_containers.nth(6), name="st_status-collapsed_via_update")
37
    assert_snapshot(status_containers.nth(7), name="st_status-empty_state")
38
    assert_snapshot(status_containers.nth(8), name="st_status-uncaught_exception")
39

40

41
def test_running_state(app: Page):
42
    """Test that st.status renders a spinner when in running state."""
43
    running_status = app.get_by_test_id("stExpander").nth(0)
44
    # Check if it has a spinner icon:
45
    expect(running_status.get_by_test_id("stExpanderIconSpinner")).to_be_visible()
46

47

48
def test_status_collapses_and_expands(app: Page):
49
    """Test that a status collapses and expands."""
50
    expander_content = "Doing some work..."
51
    running_status = app.get_by_test_id("stExpander").nth(0)
52
    # Starts expanded:
53
    expect(running_status.get_by_text(expander_content)).to_be_visible()
54

55
    expander_header = running_status.locator("summary")
56
    # Collapse:
57
    expander_header.click()
58
    expect(running_status.get_by_text(expander_content)).not_to_be_visible()
59
    # Expand:
60
    expander_header.click()
61
    expect(running_status.get_by_text(expander_content)).to_be_visible()
62

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.