Skip to content

Commit 4b32919

Browse files
authored
Add sidebar test (#631)
1 parent 789049c commit 4b32919

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

e2e/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ def create_doc_example_fixture(example_name: str, scope: str = "module"):
200200
)
201201

202202

203+
def x_create_doc_example_fixture(example_name: str, scope: str = "module"):
204+
"""Used to create app fixtures from apps in py-shiny/shiny/examples"""
205+
return create_app_fixture(
206+
here / "../shiny/experimental/api-examples" / example_name / "app.py", scope
207+
)
208+
209+
203210
@pytest.fixture(scope="module")
204211
def local_app(request: pytest.FixtureRequest) -> Generator[ShinyAppProc, None, None]:
205212
sa = run_shiny_app(PurePath(request.path).parent / "app.py", wait_for_start=False)

e2e/controls.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,3 +2336,38 @@ def expect_n_row(
23362336
n,
23372337
timeout=timeout,
23382338
)
2339+
2340+
2341+
class Sidebar(
2342+
_WidthLocM,
2343+
_InputWithContainer,
2344+
):
2345+
# *args: TagChild | TagAttrs,
2346+
# width: CssUnit = 250,
2347+
# position: Literal["left", "right"] = "left",
2348+
# open: Literal["desktop", "open", "closed", "always"] = "desktop",
2349+
# id: Optional[str] = None,
2350+
# title: TagChild | str = None,
2351+
# bg: Optional[str] = None,
2352+
# fg: Optional[str] = None,
2353+
# class_: Optional[str] = None, # TODO-future; Consider using `**kwargs` instead
2354+
# max_height_mobile: Optional[str | float] = None,
2355+
def __init__(self, page: Page, id: str) -> None:
2356+
super().__init__(
2357+
page,
2358+
id=id,
2359+
loc=f"> div#{id}",
2360+
loc_container="div.bslib-sidebar-layout",
2361+
)
2362+
self.loc_handle = self.loc_container.locator("button.collapse-toggle")
2363+
2364+
def expect_title(self, value: PatternOrStr, *, timeout: Timeout = None) -> None:
2365+
playwright_expect(self.loc).to_have_text(value, timeout=timeout)
2366+
2367+
def expect_handle(self, exists: bool, *, timeout: Timeout = None) -> None:
2368+
playwright_expect(self.loc_handle).to_have_count(int(exists), timeout=timeout)
2369+
2370+
def expect_open(self, open: bool, *, timeout: Timeout = None) -> None:
2371+
playwright_expect(self.loc_handle).to_have_attribute(
2372+
"aria-expanded", str(open).lower(), timeout=timeout
2373+
)

e2e/experimental/test_sidebar.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from conftest import ShinyAppProc, x_create_doc_example_fixture
2+
from controls import OutputTextVerbatim, Sidebar
3+
from playwright.sync_api import Page
4+
5+
app = x_create_doc_example_fixture("sidebar")
6+
7+
8+
def test_autoresize(page: Page, app: ShinyAppProc) -> None:
9+
page.goto(app.url)
10+
11+
left_sidebar = Sidebar(page, "sidebar_left")
12+
output_txt_left = OutputTextVerbatim(page, "state_left")
13+
left_sidebar.expect_title("Left sidebar content")
14+
output_txt_left.expect_value("input.sidebar_left(): True")
15+
left_sidebar.expect_handle(True)
16+
left_sidebar.expect_open(True)
17+
left_sidebar.loc_handle.click()
18+
left_sidebar.expect_open(False)
19+
output_txt_left.expect_value("input.sidebar_left(): False")
20+
21+
right_sidebar = Sidebar(page, "sidebar_right")
22+
output_txt_right = OutputTextVerbatim(page, "state_right")
23+
right_sidebar.expect_title("Right sidebar content")
24+
output_txt_right.expect_value("input.sidebar_right(): True")
25+
right_sidebar.expect_handle(True)
26+
right_sidebar.expect_open(True)
27+
right_sidebar.loc_handle.click()
28+
right_sidebar.expect_open(False)
29+
output_txt_right.expect_value("input.sidebar_right(): False")
30+
31+
closed_sidebar = Sidebar(page, "sidebar_closed")
32+
output_txt_closed = OutputTextVerbatim(page, "state_closed")
33+
output_txt_closed.expect_value("input.sidebar_closed(): False")
34+
closed_sidebar.expect_handle(True)
35+
closed_sidebar.expect_open(False)
36+
closed_sidebar.loc_handle.click()
37+
closed_sidebar.expect_title("Closed sidebar content")
38+
closed_sidebar.expect_open(True)
39+
output_txt_closed.expect_value("input.sidebar_closed(): True")
40+
41+
always_sidebar = Sidebar(page, "sidebar_always")
42+
output_txt_always = OutputTextVerbatim(page, "state_always")
43+
always_sidebar.expect_title("Always sidebar content")
44+
output_txt_always.expect_value("input.sidebar_always(): False")
45+
always_sidebar.expect_handle(False)

0 commit comments

Comments
 (0)