streamlit
104 строки · 3.4 Кб
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.
14from playwright.sync_api import Page, expect
15
16from e2e_playwright.conftest import ImageCompareFunction
17
18
19def test_first_metric_in_first_row(app: Page):
20expect(app.get_by_test_id("stMetricLabel").nth(0)).to_have_text("User growth")
21expect(app.get_by_test_id("stMetricValue").nth(0)).to_have_text(" 123 ")
22expect(app.get_by_test_id("stMetricDelta").nth(0)).to_have_text(" 123 ")
23
24
25def test_second_metric_in_first_row(app: Page):
26expect(app.get_by_test_id("stMetricLabel").nth(2)).to_have_text("S&P 500")
27expect(app.get_by_test_id("stMetricValue").nth(2)).to_have_text(" -4.56 ")
28expect(app.get_by_test_id("stMetricDelta").nth(2)).to_have_text(" -50 ")
29
30
31def test_third_metric_in_first_row(app: Page):
32expect(app.get_by_test_id("stMetricLabel").nth(4)).to_have_text("Apples I've eaten")
33expect(app.get_by_test_id("stMetricValue").nth(4)).to_have_text(" 23k ")
34expect(app.get_by_test_id("stMetricDelta").nth(4)).to_have_text(" -20 ")
35
36
37def test_green_up_arrow_render(themed_app: Page, assert_snapshot: ImageCompareFunction):
38assert_snapshot(
39themed_app.get_by_test_id("stMetric").nth(0),
40name="st_metric-green",
41)
42
43
44def test_red_down_arrow_render(themed_app: Page, assert_snapshot: ImageCompareFunction):
45assert_snapshot(
46themed_app.get_by_test_id("stMetric").nth(2),
47name="st_metric-red",
48)
49
50
51def test_gray_down_arrow_render(
52themed_app: Page, assert_snapshot: ImageCompareFunction
53):
54assert_snapshot(
55themed_app.get_by_test_id("stMetric").nth(4),
56name="st_metric-gray",
57)
58
59
60def test_help_shows_up_without_columns(
61themed_app: Page, assert_snapshot: ImageCompareFunction
62):
63assert_snapshot(
64themed_app.get_by_test_id("stMetric").nth(6),
65name="st_metric-with_help",
66)
67
68
69def test_none_results_in_dash_in_value(
70themed_app: Page, assert_snapshot: ImageCompareFunction
71):
72assert_snapshot(
73themed_app.get_by_test_id("stMetric").nth(7),
74name="st_metric-with_none_value",
75)
76
77
78def test_label_visibility_set_to_hidden(
79themed_app: Page, assert_snapshot: ImageCompareFunction
80):
81expect(themed_app.get_by_test_id("stMetricLabel").nth(3)).to_have_text("Test 4")
82assert_snapshot(
83themed_app.get_by_test_id("stMetric").nth(3),
84name="st_metric-label_hidden",
85)
86
87
88def test_label_visibility_set_to_collapse(
89themed_app: Page, assert_snapshot: ImageCompareFunction
90):
91expect(themed_app.get_by_test_id("stMetricLabel").nth(5)).to_have_text("Test 5")
92assert_snapshot(
93themed_app.get_by_test_id("stMetric").nth(5),
94name="st_metric-label_collapse",
95)
96
97
98def test_ellipses_and_help_shows_up_properly(
99themed_app: Page, assert_snapshot: ImageCompareFunction
100):
101assert_snapshot(
102themed_app.get_by_test_id("stMetric").nth(8),
103name="st_metric-help_and_ellipses",
104)
105