Skip to content
Merged
12 changes: 4 additions & 8 deletions shiny/playwright/controller/_accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,7 @@ def expect_width(self, value: StyleValue, *, timeout: Timeout = None) -> None:
_expect_style_to_have_value(self.loc_container, "width", value, timeout=timeout)

def expect_open(
self,
value: list[PatternOrStr],
*,
timeout: Timeout = None,
self, value: list[PatternOrStr], *, timeout: Timeout = None, **kwargs
) -> None:
expect_locator_values_in_list(
page=self.page,
Expand All @@ -255,13 +252,11 @@ def expect_open(
arr=value,
key="data-value",
timeout=timeout,
**kwargs,
)

def expect_panels(
self,
value: list[PatternOrStr],
*,
timeout: Timeout = None,
self, value: list[PatternOrStr], *, timeout: Timeout = None, **kwargs
) -> None:
"""
Expects the accordion to have the specified panels.
Expand All @@ -281,6 +276,7 @@ def expect_panels(
arr=value,
key="data-value",
timeout=timeout,
**kwargs,
)

def set(
Expand Down
11 changes: 9 additions & 2 deletions shiny/playwright/controller/_expect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from time import sleep

from playwright.sync_api import Locator, Page
from playwright.sync_api import expect as playwright_expect

Expand Down Expand Up @@ -146,6 +148,7 @@ def expect_locator_values_in_list(
is_checked: bool | MISSING_TYPE = MISSING,
timeout: Timeout = None,
key: str = "value",
**kwargs,
) -> None:
"""
Expect the locator to contain the values in the list.
Expand Down Expand Up @@ -218,9 +221,13 @@ def expect_locator_values_in_list(
# and all elements all unique, then it should have a count of `len(arr)`
loc_inputs = loc_container.locator(loc_item)
try:
playwright_expect(loc_inputs).to_have_count(len(arr), timeout=timeout)
if kwargs.get("alt_verify"):
sleep(1) # to make up for not using to_have_count
assert loc_inputs.count() == len(arr)
else:
playwright_expect(loc_inputs).to_have_count(len(arr), timeout=timeout)
except AssertionError as e:
# Debug expections
# Debug expectations

# Expecting container to exist (count = 1)
playwright_expect(loc_container_orig).to_have_count(1, timeout=timeout)
Expand Down
9 changes: 4 additions & 5 deletions tests/playwright/shiny/components/accordion/test_accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ def test_accordion(page: Page, local_app: ShinyAppProc) -> None:
"input.acc(): ('updated_section_a', 'Section C', 'Section D')"
)

# TODO-karan-future; Remove return when test is able to pass. Currently it hangs indefinitely and no notification as to why.
return

toggle_efg_button.click()
acc.expect_panels(
[
Expand All @@ -92,7 +89,8 @@ def test_accordion(page: Page, local_app: ShinyAppProc) -> None:
"Section E",
"Section F",
"Section G",
]
],
alt_verify=True,
)
acc.expect_open(
[
Expand All @@ -102,7 +100,8 @@ def test_accordion(page: Page, local_app: ShinyAppProc) -> None:
"Section E",
"Section F",
"Section G",
]
],
alt_verify=True,
)
# Should be uncommented once https://github.com/rstudio/bslib/issues/565 is fixed
# output_txt_verbatim.expect_value(
Expand Down
Loading