Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions shiny/playwright/controller/_input_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ...types import MISSING, MISSING_TYPE, ListOrTuple
from .._types import AttrValue, ListPatternOrStr, PatternOrStr, Timeout
from ..expect._expect import _attr_match_str
from ..expect._expect import _attr_match_str, _xpath_match_str
from ..expect._internal import (
expect_attribute_to_have_value as _expect_attribute_to_have_value,
)
Expand All @@ -22,6 +22,7 @@
not_is_missing,
)
from ._expect import (
assert_arr_is_unique,
expect_locator_contains_values_in_list,
expect_locator_values_in_list,
)
Expand Down Expand Up @@ -923,20 +924,19 @@ def expect_selected(
timeout
The timeout for the expectation. Defaults to `None`.
"""
assert_arr_is_unique(value, "`selected` must be unique")

# Playwright doesn't like lists of size 0
if len(value) == 0:
playwright_expect(self.loc_selected).to_have_count(0, timeout=timeout)
return

expect_locator_values_in_list(
page=self.page,
loc_container=self.loc_container,
el_type="input[type=checkbox]",
arr_name="selected",
arr=value,
timeout=timeout,
is_checked=True,
)
playwright_expect(self.loc_selected).to_have_count(len(value), timeout=timeout)
for item in value:
selected_item = self.loc_selected.locator(
f'xpath=self::*[{_xpath_match_str("value", item)}]'
)
playwright_expect(selected_item).to_have_count(1, timeout=timeout)
Comment on lines +934 to +939
Comment on lines +927 to +939


class InputCheckbox(_InputCheckboxBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_checkbox_group_kitchen(page: Page, local_app: ShinyAppProc) -> None:
inline_txt.expect_value("()")
# Set in wrong order
inline.set(["Option D", "Option A"])
inline.expect_selected(["Option A", "Option D"])
inline.expect_selected(["Option D", "Option A"])
inline_txt.expect_value("('Option A', 'Option D')")

dict_values = controller.InputCheckboxGroup(page, "dict_values")
Expand Down
Loading