streamlit
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
15from playwright.sync_api import Page, expect
16
17from e2e_playwright.conftest import ImageCompareFunction, wait_for_app_loaded
18
19
20def test_default_toast_rendering(
21themed_app: Page, assert_snapshot: ImageCompareFunction
22):
23"""Test that toasts are correctly rendered."""
24themed_app.keyboard.press("r")
25wait_for_app_loaded(themed_app)
26themed_app.wait_for_timeout(250)
27
28toasts = themed_app.get_by_test_id("stToast")
29expect(toasts).to_have_count(2)
30toasts.nth(1).hover()
31
32expect(toasts.nth(1)).to_have_text("🐶 This is a default toast messageClose")
33assert_snapshot(toasts.nth(1), name="toast-default")
34
35
36def test_collapsed_toast_rendering(
37themed_app: Page, assert_snapshot: ImageCompareFunction
38):
39"""Test collapsed long toasts are correctly rendered."""
40themed_app.keyboard.press("r")
41wait_for_app_loaded(themed_app)
42themed_app.wait_for_timeout(250)
43
44toasts = themed_app.get_by_test_id("stToast")
45expect(toasts).to_have_count(2)
46toasts.nth(0).hover()
47
48expect(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)
51assert_snapshot(toasts.nth(0), name="toast-collapsed")
52
53
54def test_expanded_toast_rendering(
55themed_app: Page, assert_snapshot: ImageCompareFunction
56):
57"""Test expanded long toasts are correctly rendered."""
58themed_app.keyboard.press("r")
59wait_for_app_loaded(themed_app)
60themed_app.wait_for_timeout(250)
61
62toasts = themed_app.get_by_test_id("stToast")
63expect(toasts).to_have_count(2)
64toasts.nth(0).hover()
65
66expand = themed_app.get_by_text("view more")
67expect(expand).to_have_count(1)
68expand.click()
69
70expect(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)
73assert_snapshot(toasts.nth(0), name="toast-expanded")
74
75
76def test_toast_overlay_with_chat(
77themed_app: Page, assert_snapshot: ImageCompareFunction
78):
79"""Test that toasts overlay with st.chat_input."""
80themed_app.keyboard.press("r")
81wait_for_app_loaded(themed_app)
82themed_app.wait_for_timeout(250)
83
84container = themed_app.get_by_test_id("stBottomBlockContainer")
85toasts = themed_app.get_by_test_id("stToast")
86toasts.nth(0).hover()
87
88assert_snapshot(container, name="toast-with-chat")
89