Skip to content

Commit a7160f5

Browse files
committed
Add more test methods
1 parent 713e688 commit a7160f5

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

shiny/playwright/controller/_layout.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from playwright.sync_api import expect as playwright_expect
77

88
from .._types import PatternOrStr, Timeout
9+
from ..expect._internal import (
10+
expect_attribute_to_have_value as _expect_attribute_to_have_value,
11+
)
912
from ..expect._internal import expect_class_to_have_value as _expect_class_to_have_value
1013
from ..expect._internal import expect_style_to_have_value as _expect_style_to_have_value
1114
from ._base import UiWithContainer, WidthLocM
@@ -131,6 +134,64 @@ def expect_bg_color(self, value: PatternOrStr, *, timeout: Timeout = None) -> No
131134
self.loc_container, "--_sidebar-bg", value, timeout=timeout
132135
)
133136

137+
def expect_desktop_state(
138+
self, value: Literal["open", "closed", "always"], *, timeout: Timeout = None
139+
) -> None:
140+
"""
141+
Asserts that the sidebar has the expected state on desktop.
142+
143+
Parameters
144+
----------
145+
value
146+
The expected state of the sidebar on desktop.
147+
timeout
148+
The maximum time to wait for the state to appear. Defaults to `None`.
149+
"""
150+
_expect_attribute_to_have_value(
151+
self.loc_container,
152+
name="data-open-desktop",
153+
value=value,
154+
timeout=timeout,
155+
)
156+
157+
def expect_mobile_state(
158+
self, value: Literal["open", "closed", "always"], *, timeout: Timeout = None
159+
) -> None:
160+
"""
161+
Asserts that the sidebar has the expected state on mobile.
162+
163+
Parameters
164+
----------
165+
value
166+
The expected state of the sidebar on mobile.
167+
timeout
168+
The maximum time to wait for the state to appear. Defaults to `None`.
169+
"""
170+
_expect_attribute_to_have_value(
171+
self.loc_container,
172+
name="data-open-mobile",
173+
value=value,
174+
timeout=timeout,
175+
)
176+
177+
def expect_mobile_max_height(
178+
self, value: PatternOrStr, *, timeout: Timeout = None
179+
) -> None:
180+
"""
181+
Asserts that the sidebar has the expected maximum height on mobile.
182+
183+
Parameters
184+
----------
185+
value
186+
The expected maximum height of the sidebar on mobile.
187+
timeout
188+
The maximum time to wait for the maximum height to appear. Defaults to `None`.
189+
"""
190+
self.expect_mobile_state("always", timeout=timeout)
191+
_expect_style_to_have_value(
192+
self.loc_container, "--_mobile-max-height", value, timeout=timeout
193+
)
194+
134195
def expect_title(self, value: PatternOrStr, *, timeout: Timeout = None) -> None:
135196
"""
136197
Asserts that the sidebar has the expected title.

tests/playwright/shiny/inputs/sidebar_kitchensink/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
title="Left sidebar",
1111
bg="dodgerBlue",
1212
class_="text-white",
13-
max_height_mobile="175px",
1413
gap="20px",
1514
padding="10px",
1615
):
@@ -26,7 +25,7 @@ def state_left():
2625
with ui.sidebar(
2726
id="sidebar_right",
2827
position="right",
29-
open="desktop",
28+
open={"desktop": "closed", "mobile": "open"},
3029
padding=["10px", "20px"],
3130
bg="SlateBlue",
3231
):
@@ -59,6 +58,7 @@ def state_closed():
5958
open="always",
6059
bg="PeachPuff",
6160
padding=["10px", "20px", "30px", "40px"],
61+
max_height_mobile="175px",
6262
):
6363
"Always sidebar content"
6464

tests/playwright/shiny/inputs/sidebar_kitchensink/test_sidebar_kitchensink.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def test_sidebar_position_and_open(page: Page, local_app: ShinyAppProc) -> None:
1515
left_sidebar.expect_gap("20px")
1616
left_sidebar.expect_class("text-white", has_class=True)
1717
left_sidebar.expect_bg_color("dodgerBlue")
18+
left_sidebar.expect_desktop_state("open")
19+
left_sidebar.expect_mobile_state("closed")
1820
output_txt_left.expect_value("input.sidebar_left(): True")
1921
left_sidebar.expect_open(True)
2022
left_sidebar.set(False)
@@ -28,6 +30,8 @@ def test_sidebar_position_and_open(page: Page, local_app: ShinyAppProc) -> None:
2830
right_sidebar = controller.Sidebar(page, "sidebar_right")
2931
right_sidebar.expect_padding(["10px", "20px"])
3032
right_sidebar.expect_bg_color("SlateBlue")
33+
right_sidebar.expect_mobile_state("open")
34+
right_sidebar.expect_desktop_state("closed")
3135

3236
closed_sidebar = controller.Sidebar(page, "sidebar_closed")
3337
closed_sidebar.expect_padding(["10px", "20px", "30px"])
@@ -36,3 +40,7 @@ def test_sidebar_position_and_open(page: Page, local_app: ShinyAppProc) -> None:
3640
always_sidebar = controller.Sidebar(page, "sidebar_always")
3741
always_sidebar.expect_padding(["10px", "20px", "30px", "40px"])
3842
always_sidebar.expect_bg_color("PeachPuff")
43+
always_sidebar.expect_open(True)
44+
always_sidebar.expect_desktop_state("always")
45+
always_sidebar.expect_mobile_state("always")
46+
always_sidebar.expect_mobile_max_height("175px")

0 commit comments

Comments
 (0)