Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

tests(accordion): Add kitchensink tests for accordion #1710

Merged
merged 10 commits into from
Oct 4, 2024
57 changes: 53 additions & 4 deletions shiny/playwright/controller/_accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ def expect_body(self, value: PatternOrStr, *, timeout: Timeout = None) -> None:
"""
playwright_expect(self.loc_body).to_have_text(value, timeout=timeout)

def expect_icon(self, value: PatternOrStr, *, timeout: Timeout = None) -> None:
def expect_icon(self, value: bool, *, timeout: Timeout = None) -> None:
"""
Expects the accordion panel icon to have the specified text.
Expects the accordion panel icon to exist or not.

Parameters
----------
value
The expected text pattern or string.
`True` if the icon is expected to exist, `False` otherwise.
timeout
The maximum time to wait for the icon to appear. Defaults to `None`.
"""
playwright_expect(self.loc_icon).to_have_text(value, timeout=timeout)
playwright_expect(self.loc_icon).to_have_count(int(value), timeout=timeout)

def expect_open(self, value: bool, *, timeout: Timeout = None) -> None:
"""
Expand Down Expand Up @@ -307,6 +307,55 @@ def set(
)
self.accordion_panel(elem_value).set(elem_value in open, timeout=timeout)

def expect_class(
self,
class_name: str,
has_class: bool,
*,
timeout: Timeout = None,
) -> None:
"""
Expects the accordion to have the specified class.

Parameters
----------
class_name
The class name to expect.
has_class
`True` if the class is expected
timeout
The maximum time to wait for the class to appear. Defaults to `None`.
"""
_expect_class_to_have_value(
self.loc_container,
class_name,
has_class=has_class,
timeout=timeout,
)

def expect_multiple(
self,
value: bool,
*,
timeout: Timeout = None,
) -> None:
"""
Expects the accordion to be multiple or not.

Parameters
----------
value
`True` if the accordion is expected to be multiple, `False` otherwise.
timeout
The maximum time to wait for the expectation to pass. Defaults to `None`.
"""
_expect_class_to_have_value(
self.loc_container,
"autoclose",
has_class=not value,
timeout=timeout,
)

def accordion_panel(
self,
data_value: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_accordion(page: Page, local_app: ShinyAppProc) -> None:
toggle_updates_button.click()
acc_panel_updated_A.expect_label("Updated title")
acc_panel_updated_A.expect_body("Updated body")
acc_panel_updated_A.expect_icon("Look! An icon! -->")
acc_panel_updated_A.expect_icon(True)

acc.expect_panels(["updated_section_a", "Section B", "Section C", "Section D"])
# workaround - toggle it twice Section A
Expand Down
50 changes: 50 additions & 0 deletions tests/playwright/shiny/inputs/accordion_kitchensink/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from faicons import icon_svg

from shiny import App, ui

app_ui = ui.page_fluid(
ui.h1("Accordion Kitchensink"),
ui.accordion(
ui.accordion_panel(
"Panel 1",
ui.p("This is the content of Panel 1"),
value="panel1",
),
ui.accordion_panel(
"Panel 2",
ui.p("This is the content of Panel 2"),
icon=icon_svg("trash-arrow-up"),
value="panel2",
),
id="accordion_1",
width="600px",
height="300px",
multiple=False,
class_="bg-light",
),
ui.accordion(
ui.accordion_panel(
"Panel 3",
ui.p("This is the content of Panel 3"),
value="panel3",
),
ui.accordion_panel(
"Panel 4",
ui.p("This is the content of Panel 4"),
value="panel4",
),
id="accordion_2",
multiple=True,
),
)


def server(
input, # pyright: ignore[reportUnknownParameterType, reportMissingParameterType]
output, # pyright: ignore[reportUnknownParameterType, reportMissingParameterType]
session, # pyright: ignore[reportUnknownParameterType, reportMissingParameterType]
):
pass


app = App(app_ui, server) # pyright: ignore[reportUnknownArgumentType]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from playwright.sync_api import Page

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def test_accordion_kitchensink(page: Page, local_app: ShinyAppProc) -> None:
page.goto(local_app.url)

accordion1 = controller.Accordion(page, "accordion_1")
accordion1.expect_width("600px")
accordion1.expect_height("300px")
accordion1.expect_class("bg-light", True)
accordion1.expect_multiple(False)
accordion1_panel1 = accordion1.accordion_panel("panel1")
accordion1_panel1.expect_open(True)
accordion1_panel1.expect_label("Panel 1")
# accordion1_panel1.expect_icon(False) # not sure why this is not working

accordion1_panel2 = accordion1.accordion_panel("panel2")
accordion1_panel2.expect_open(False)
accordion1_panel2.expect_label("Panel 2")
accordion1_panel2.expect_icon(True)
accordion1_panel2.set(True)
accordion1_panel2.expect_open(True)
accordion1_panel1.expect_open(False)

accordion2 = controller.Accordion(page, "accordion_2")
accordion2.expect_width(None)
accordion2.expect_height(None)
accordion2.expect_class("bg-light", False)
accordion2.expect_multiple(True)

accordion2_panel3 = accordion2.accordion_panel("panel3")
accordion2_panel3.expect_open(True)

accordion2_panel4 = accordion2.accordion_panel("panel4")
accordion2_panel4.expect_open(False)
accordion2_panel4.set(True)
accordion2_panel4.expect_open(True)
accordion2_panel3.expect_open(True)
Loading