streamlit

Форк
0
/
st_toast_test.py 
88 строк · 3.0 Кб
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
from playwright.sync_api import Page, expect
16

17
from e2e_playwright.conftest import ImageCompareFunction, wait_for_app_loaded
18

19

20
def test_default_toast_rendering(
21
    themed_app: Page, assert_snapshot: ImageCompareFunction
22
):
23
    """Test that toasts are correctly rendered."""
24
    themed_app.keyboard.press("r")
25
    wait_for_app_loaded(themed_app)
26
    themed_app.wait_for_timeout(250)
27

28
    toasts = themed_app.get_by_test_id("stToast")
29
    expect(toasts).to_have_count(2)
30
    toasts.nth(1).hover()
31

32
    expect(toasts.nth(1)).to_have_text("🐶 This is a default toast messageClose")
33
    assert_snapshot(toasts.nth(1), name="toast-default")
34

35

36
def test_collapsed_toast_rendering(
37
    themed_app: Page, assert_snapshot: ImageCompareFunction
38
):
39
    """Test collapsed long toasts are correctly rendered."""
40
    themed_app.keyboard.press("r")
41
    wait_for_app_loaded(themed_app)
42
    themed_app.wait_for_timeout(250)
43

44
    toasts = themed_app.get_by_test_id("stToast")
45
    expect(toasts).to_have_count(2)
46
    toasts.nth(0).hover()
47

48
    expect(toasts.nth(0)).to_have_text(
49
        "🦄 Random toast message that is a really really really really really really really long message, going wayview moreClose"
50
    )
51
    assert_snapshot(toasts.nth(0), name="toast-collapsed")
52

53

54
def test_expanded_toast_rendering(
55
    themed_app: Page, assert_snapshot: ImageCompareFunction
56
):
57
    """Test expanded long toasts are correctly rendered."""
58
    themed_app.keyboard.press("r")
59
    wait_for_app_loaded(themed_app)
60
    themed_app.wait_for_timeout(250)
61

62
    toasts = themed_app.get_by_test_id("stToast")
63
    expect(toasts).to_have_count(2)
64
    toasts.nth(0).hover()
65

66
    expand = themed_app.get_by_text("view more")
67
    expect(expand).to_have_count(1)
68
    expand.click()
69

70
    expect(toasts.nth(0)).to_have_text(
71
        "🦄 Random toast message that is a really really really really really really really long message, going way past the 3 line limitview lessClose"
72
    )
73
    assert_snapshot(toasts.nth(0), name="toast-expanded")
74

75

76
def test_toast_overlay_with_chat(
77
    themed_app: Page, assert_snapshot: ImageCompareFunction
78
):
79
    """Test that toasts overlay with st.chat_input."""
80
    themed_app.keyboard.press("r")
81
    wait_for_app_loaded(themed_app)
82
    themed_app.wait_for_timeout(250)
83

84
    container = themed_app.get_by_test_id("stBottomBlockContainer")
85
    toasts = themed_app.get_by_test_id("stToast")
86
    toasts.nth(0).hover()
87

88
    assert_snapshot(container, name="toast-with-chat")
89

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

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

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

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