Skip to content

Commit 2b5c77b

Browse files
committed
Add kitchensink tests for accordion
1 parent b56c2af commit 2b5c77b

File tree

3 files changed

+144
-4
lines changed

3 files changed

+144
-4
lines changed

shiny/playwright/controller/_accordion.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ def expect_body(self, value: PatternOrStr, *, timeout: Timeout = None) -> None:
9898
"""
9999
playwright_expect(self.loc_body).to_have_text(value, timeout=timeout)
100100

101-
def expect_icon(self, value: PatternOrStr, *, timeout: Timeout = None) -> None:
101+
def expect_icon(self, value: bool, *, timeout: Timeout = None) -> None:
102102
"""
103-
Expects the accordion panel icon to have the specified text.
103+
Expects the accordion panel icon to exist or not.
104104
105105
Parameters
106106
----------
107107
value
108-
The expected text pattern or string.
108+
`True` if the icon is expected to exist, `False` otherwise.
109109
timeout
110110
The maximum time to wait for the icon to appear. Defaults to `None`.
111111
"""
112-
playwright_expect(self.loc_icon).to_have_text(value, timeout=timeout)
112+
playwright_expect(self.loc_icon).to_have_count(int(value), timeout=timeout)
113113

114114
def expect_open(self, value: bool, *, timeout: Timeout = None) -> None:
115115
"""
@@ -307,6 +307,55 @@ def set(
307307
)
308308
self.accordion_panel(elem_value).set(elem_value in open, timeout=timeout)
309309

310+
def expect_class(
311+
self,
312+
class_name: str,
313+
has_class: bool,
314+
*,
315+
timeout: Timeout = None,
316+
) -> None:
317+
"""
318+
Expects the accordion to have the specified class.
319+
320+
Parameters
321+
----------
322+
class_name
323+
The class name to expect.
324+
has_class
325+
`True` if the class is expected
326+
timeout
327+
The maximum time to wait for the class to appear. Defaults to `None`.
328+
"""
329+
_expect_class_to_have_value(
330+
self.loc_container,
331+
class_name,
332+
has_class=has_class,
333+
timeout=timeout,
334+
)
335+
336+
def expect_multiple(
337+
self,
338+
value: bool,
339+
*,
340+
timeout: Timeout = None,
341+
) -> None:
342+
"""
343+
Expects the accordion to be multiple or not.
344+
345+
Parameters
346+
----------
347+
value
348+
`True` if the accordion is expected to be multiple, `False` otherwise.
349+
timeout
350+
The maximum time to wait for the expectation to pass. Defaults to `None`.
351+
"""
352+
_expect_class_to_have_value(
353+
self.loc_container,
354+
"autoclose",
355+
has_class=not value,
356+
timeout=timeout,
357+
)
358+
310359
def accordion_panel(
311360
self,
312361
data_value: str,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from faicons import icon_svg
2+
3+
from shiny import App, ui
4+
5+
app_ui = ui.page_fluid(
6+
ui.h1("Accordion Kitchensink"),
7+
ui.accordion(
8+
ui.accordion_panel(
9+
"Panel 1",
10+
ui.p("This is the content of Panel 1"),
11+
value="panel1",
12+
),
13+
ui.accordion_panel(
14+
"Panel 2",
15+
ui.p("This is the content of Panel 2"),
16+
icon=icon_svg("trash-arrow-up"),
17+
value="panel2",
18+
),
19+
id="accordion_1",
20+
width="600px",
21+
height="300px",
22+
multiple=False,
23+
class_="bg-light",
24+
),
25+
ui.accordion(
26+
ui.accordion_panel(
27+
"Panel 3",
28+
ui.p("This is the content of Panel 3"),
29+
value="panel3",
30+
),
31+
ui.accordion_panel(
32+
"Panel 4",
33+
ui.p("This is the content of Panel 4"),
34+
value="panel4",
35+
),
36+
id="accordion_2",
37+
multiple=True,
38+
),
39+
)
40+
41+
42+
def server(
43+
input,
44+
output,
45+
session, # pyright: ignore[reportUnknownParameterType, reportMissingParameterType]
46+
):
47+
pass
48+
49+
50+
app = App(app_ui, server) # pyright: ignore[reportUnknownArgumentType]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from playwright.sync_api import Page
2+
3+
from shiny.playwright import controller
4+
from shiny.run import ShinyAppProc
5+
6+
7+
def test_accordion_kitchensink(page: Page, local_app: ShinyAppProc) -> None:
8+
page.goto(local_app.url)
9+
10+
accordion1 = controller.Accordion(page, "accordion_1")
11+
accordion1.expect_width("600px")
12+
accordion1.expect_height("300px")
13+
accordion1.expect_class("bg-light", True)
14+
accordion1.expect_multiple(False)
15+
accordion1_panel1 = accordion1.accordion_panel("panel1")
16+
accordion1_panel1.expect_open(True)
17+
accordion1_panel1.expect_label("Panel 1")
18+
# accordion1_panel1.expect_icon(False) # not sure why this is not working
19+
20+
accordion1_panel2 = accordion1.accordion_panel("panel2")
21+
accordion1_panel2.expect_open(False)
22+
accordion1_panel2.expect_label("Panel 2")
23+
accordion1_panel2.expect_icon(True)
24+
accordion1_panel2.set(True)
25+
accordion1_panel2.expect_open(True)
26+
accordion1_panel1.expect_open(False)
27+
28+
accordion2 = controller.Accordion(page, "accordion_2")
29+
accordion2.expect_width(None)
30+
accordion2.expect_height(None)
31+
accordion2.expect_class("bg-light", False)
32+
accordion2.expect_multiple(True)
33+
34+
accordion2_panel3 = accordion2.accordion_panel("panel3")
35+
accordion2_panel3.expect_open(True)
36+
37+
accordion2_panel4 = accordion2.accordion_panel("panel4")
38+
accordion2_panel4.expect_open(False)
39+
accordion2_panel4.set(True)
40+
accordion2_panel4.expect_open(True)
41+
accordion2_panel3.expect_open(True)

0 commit comments

Comments
 (0)