Skip to content

Commit f6b92d8

Browse files
authored
tests(brand-yml): Add tests for brand.yml (#1764)
1 parent 36aa320 commit f6b92d8

File tree

2 files changed

+130
-7
lines changed

2 files changed

+130
-7
lines changed

examples/brand/app.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@
3434
"Metric 1",
3535
"100",
3636
theme="primary",
37+
id="value_box_primary",
3738
),
3839
ui.value_box(
3940
"Metric 2",
4041
"200",
4142
theme="secondary",
43+
id="value_box_secondary",
4244
),
4345
ui.value_box(
4446
"Metric 3",
4547
"300",
4648
theme="info",
49+
id="value_box_info",
4750
),
4851
),
4952
ui.card(
@@ -61,13 +64,15 @@
6164
ui.layout_column_wrap(
6265
ui.card(
6366
ui.card_header("Button Variants"),
64-
ui.input_action_button("btn1", "Default"),
65-
ui.input_action_button("btn2", "Primary", class_="btn-primary"),
66-
ui.input_action_button("btn3", "Secondary", class_="btn-secondary"),
67-
ui.input_action_button("btn4", "Info", class_="btn-info"),
68-
ui.input_action_button("btn5", "Success", class_="btn-success"),
69-
ui.input_action_button("btn6", "Warning", class_="btn-warning"),
70-
ui.input_action_button("btn7", "Danger", class_="btn-danger"),
67+
ui.input_action_button("btn_default", "Default"),
68+
ui.input_action_button("btn_primary", "Primary", class_="btn-primary"),
69+
ui.input_action_button(
70+
"btn_secondary", "Secondary", class_="btn-secondary"
71+
),
72+
ui.input_action_button("btn_success", "Success", class_="btn-success"),
73+
ui.input_action_button("btn_danger", "Danger", class_="btn-danger"),
74+
ui.input_action_button("btn_warning", "Warning", class_="btn-warning"),
75+
ui.input_action_button("btn_info", "Info", class_="btn-info"),
7176
),
7277
ui.card(
7378
ui.card_header("Radio Button Examples"),
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import re
2+
from typing import Any, Callable, Dict
3+
4+
from conftest import create_example_fixture
5+
from playwright.sync_api import Locator, Page, expect
6+
7+
from shiny.playwright import controller
8+
from shiny.run import ShinyAppProc
9+
10+
app = create_example_fixture("brand")
11+
12+
13+
def test_brand_yml_kitchensink(page: Page, app: ShinyAppProc) -> None:
14+
page.goto(app.url)
15+
16+
expected_styles = {
17+
"value_box_primary": {
18+
"background-color": "rgb(111, 66, 193)",
19+
"color": "rgb(248, 248, 248)",
20+
"font-family": re.compile(r"Monda.*"),
21+
},
22+
"value_box_secondary": {
23+
"background-color": "rgb(64, 64, 64)",
24+
"color": "rgb(248, 248, 248)",
25+
"font-family": re.compile(r"Monda.*"),
26+
},
27+
"value_box_info": {
28+
"background-color": "rgb(23, 162, 184)",
29+
"color": "rgb(26, 26, 26)",
30+
"font-family": re.compile(r"Monda.*"),
31+
},
32+
"switch1": {
33+
"background-color": "rgba(0, 0, 0, 0)",
34+
"color": "rgb(26, 26, 26)",
35+
"font-family": re.compile(r"Monda.*"),
36+
},
37+
"out_text1": {
38+
"background-color": "rgb(26, 26, 26)",
39+
"color": "rgb(40, 167, 69)",
40+
"font-family": re.compile(r"Share Tech Mono.*"),
41+
},
42+
"btn_default": {
43+
"background-color": "rgba(0, 0, 0, 0)",
44+
"color": "rgb(64, 64, 64)",
45+
"font-family": re.compile(r"Monda.*"),
46+
},
47+
"btn_primary": {
48+
"background-color": "rgb(111, 66, 193)",
49+
"color": "rgb(248, 248, 248)",
50+
"font-family": re.compile(r"Monda.*"),
51+
},
52+
"btn_secondary": {
53+
"background-color": "rgb(64, 64, 64)",
54+
"color": "rgb(248, 248, 248)",
55+
"font-family": re.compile(r"Monda.*"),
56+
},
57+
"btn_success": {
58+
"background-color": "rgb(40, 167, 69)",
59+
"color": "rgb(26, 26, 26)",
60+
"font-family": re.compile(r"Monda.*"),
61+
},
62+
"btn_danger": {
63+
"background-color": "rgb(255, 127, 80)",
64+
"color": "rgb(26, 26, 26)",
65+
"font-family": re.compile(r"Monda.*"),
66+
},
67+
"btn_warning": {
68+
"background-color": "rgb(255, 215, 0)",
69+
"color": "rgb(26, 26, 26)",
70+
"font-family": re.compile(r"Monda.*"),
71+
},
72+
"btn_info": {
73+
"background-color": "rgb(23, 162, 184)",
74+
"color": "rgb(26, 26, 26)",
75+
"font-family": re.compile(r"Monda.*"),
76+
},
77+
}
78+
79+
component_mapping = {
80+
"value_box_primary": controller.ValueBox,
81+
"value_box_secondary": controller.ValueBox,
82+
"value_box_info": controller.ValueBox,
83+
"switch1": controller.InputSwitch,
84+
"out_text1": controller.OutputText,
85+
"btn_default": controller.InputActionButton,
86+
"btn_primary": controller.InputActionButton,
87+
"btn_secondary": controller.InputActionButton,
88+
"btn_success": controller.InputActionButton,
89+
"btn_danger": controller.InputActionButton,
90+
"btn_warning": controller.InputActionButton,
91+
"btn_info": controller.InputActionButton,
92+
}
93+
94+
locator_mapping: Dict[type[Any], Callable[[Any], Locator]] = {
95+
controller.ValueBox: lambda component: component.loc_container,
96+
controller.InputSwitch: lambda component: component.loc_label,
97+
controller.OutputText: lambda component: component.loc,
98+
controller.InputActionButton: lambda component: component.loc,
99+
}
100+
101+
# Iterate over expected styles and perform assertions
102+
for component_name, styles in expected_styles.items():
103+
component_class = component_mapping[component_name]
104+
component = component_class(page, component_name)
105+
locator = locator_mapping[component_class](component)
106+
for property_name, expected_value in styles.items():
107+
expect(locator).to_have_css(property_name, expected_value)
108+
109+
# inline-code block
110+
expect(page.get_by_text("@reactive.effect")).to_have_css(
111+
"background-color", "rgba(26, 26, 26, 0.867)"
112+
)
113+
expect(page.get_by_text("@reactive.effect")).to_have_css(
114+
"color", "rgb(255, 215, 0)"
115+
)
116+
expect(page.get_by_text("@reactive.effect")).to_have_css(
117+
"font-family", re.compile(r"Share Tech Mono.*")
118+
)

0 commit comments

Comments
 (0)