Skip to content

Commit f8ff5dd

Browse files
committed
workaround for accordion tests
1 parent 499ce37 commit f8ff5dd

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

shiny/playwright/controller/_accordion.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,7 @@ def expect_width(self, value: StyleValue, *, timeout: Timeout = None) -> None:
238238
_expect_style_to_have_value(self.loc_container, "width", value, timeout=timeout)
239239

240240
def expect_open(
241-
self,
242-
value: list[PatternOrStr],
243-
*,
244-
timeout: Timeout = None,
241+
self, value: list[PatternOrStr], *, timeout: Timeout = None, **kwargs
245242
) -> None:
246243
expect_locator_values_in_list(
247244
page=self.page,
@@ -255,13 +252,11 @@ def expect_open(
255252
arr=value,
256253
key="data-value",
257254
timeout=timeout,
255+
**kwargs,
258256
)
259257

260258
def expect_panels(
261-
self,
262-
value: list[PatternOrStr],
263-
*,
264-
timeout: Timeout = None,
259+
self, value: list[PatternOrStr], *, timeout: Timeout = None, **kwargs
265260
) -> None:
266261
"""
267262
Expects the accordion to have the specified panels.
@@ -281,6 +276,7 @@ def expect_panels(
281276
arr=value,
282277
key="data-value",
283278
timeout=timeout,
279+
**kwargs,
284280
)
285281

286282
def set(

shiny/playwright/controller/_expect.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from time import sleep
4+
35
from playwright.sync_api import Locator, Page
46
from playwright.sync_api import expect as playwright_expect
57

@@ -146,6 +148,7 @@ def expect_locator_values_in_list(
146148
is_checked: bool | MISSING_TYPE = MISSING,
147149
timeout: Timeout = None,
148150
key: str = "value",
151+
**kwargs,
149152
) -> None:
150153
"""
151154
Expect the locator to contain the values in the list.
@@ -218,9 +221,13 @@ def expect_locator_values_in_list(
218221
# and all elements all unique, then it should have a count of `len(arr)`
219222
loc_inputs = loc_container.locator(loc_item)
220223
try:
221-
playwright_expect(loc_inputs).to_have_count(len(arr), timeout=timeout)
224+
if kwargs.get("alt_verify"):
225+
sleep(1) # to make up for not using to_have_count
226+
assert loc_inputs.count() == len(arr)
227+
else:
228+
playwright_expect(loc_inputs).to_have_count(len(arr), timeout=timeout)
222229
except AssertionError as e:
223-
# Debug expections
230+
# Debug expectations
224231

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

tests/playwright/shiny/components/accordion/test_accordion.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def test_accordion(page: Page, local_app: ShinyAppProc) -> None:
8989
"Section E",
9090
"Section F",
9191
"Section G",
92-
]
92+
],
93+
alt_verify=True,
9394
)
9495
acc.expect_open(
9596
[
@@ -99,7 +100,8 @@ def test_accordion(page: Page, local_app: ShinyAppProc) -> None:
99100
"Section E",
100101
"Section F",
101102
"Section G",
102-
]
103+
],
104+
alt_verify=True,
103105
)
104106
# Should be uncommented once https://github.com/rstudio/bslib/issues/565 is fixed
105107
# output_txt_verbatim.expect_value(

0 commit comments

Comments
 (0)