Skip to content
Merged
7 changes: 3 additions & 4 deletions shiny/playwright/controller/_accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,11 @@ def expect_open(
arr=value,
key="data-value",
timeout=timeout,
alt_verify=True,
)

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 +279,7 @@ def expect_panels(
arr=value,
key="data-value",
timeout=timeout,
alt_verify=True,
)

def set(
Expand Down
47 changes: 31 additions & 16 deletions shiny/playwright/controller/_expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def expect_locator_values_in_list(
is_checked: bool | MISSING_TYPE = MISSING,
timeout: Timeout = None,
key: str = "value",
alt_verify: bool = False,
) -> None:
"""
Expect the locator to contain the values in the list.
Expand All @@ -171,6 +172,11 @@ def expect_locator_values_in_list(
The timeout for the expectation. Defaults to `None`.
key
The key. Defaults to `"value"`.
alt_verify
Determines if multiple expectations should be performed.
Defaults to `False`, a single (and very complicated) locator is asserting.
`True` will perform multiple assersions, which have the possibility of being invalid.
Use in playwright bug situations only.
"""
# Make sure the locator has exactly `arr` values

Expand All @@ -195,6 +201,28 @@ def expect_locator_values_in_list(
return
loc_container_orig = loc_container

def perform_multiple_assertions():
# Expecting container to exist (count = 1)
playwright_expect(loc_container_orig).to_have_count(1, timeout=timeout)

# Expecting the container to contain {len(arr)} items
playwright_expect(loc_container_orig.locator(loc_item)).to_have_count(
len(arr), timeout=timeout
)

for item, i in zip(arr, range(len(arr))):
# Expecting item `{i}` to be `{item}`
playwright_expect(
loc_container_orig.locator(loc_item).nth(i)
).to_have_attribute(key, item, timeout=timeout)
return

if alt_verify:
# Accordion has issues where the single locator assertion waits forever within playwright.
# Perform multiple assertions until playwright fixes bug.
perform_multiple_assertions()
return

# Find all items in set
for item, i in zip(arr, range(len(arr))):
# Get all elements of type
Expand All @@ -220,21 +248,8 @@ def expect_locator_values_in_list(
try:
playwright_expect(loc_inputs).to_have_count(len(arr), timeout=timeout)
except AssertionError as e:
# Debug expections

# Expecting container to exist (count = 1)
playwright_expect(loc_container_orig).to_have_count(1, timeout=timeout)

# Expecting the container to contain {len(arr)} items
playwright_expect(loc_container_orig.locator(loc_item)).to_have_count(
len(arr), timeout=timeout
)

for item, i in zip(arr, range(len(arr))):
# Expecting item `{i}` to be `{item}`
playwright_expect(
loc_container_orig.locator(loc_item).nth(i)
).to_have_attribute(key, item, timeout=timeout)

# Debug expectations
perform_multiple_assertions()

# Could not find the reason why. Raising the original error.
raise e
7 changes: 2 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,7 @@ def test_accordion(page: Page, local_app: ShinyAppProc) -> None:
"Section E",
"Section F",
"Section G",
]
],
)
acc.expect_open(
[
Expand All @@ -102,7 +99,7 @@ def test_accordion(page: Page, local_app: ShinyAppProc) -> None:
"Section E",
"Section F",
"Section G",
]
],
)
# Should be uncommented once https://github.com/rstudio/bslib/issues/565 is fixed
# output_txt_verbatim.expect_value(
Expand Down
Loading