1717from ..expect ._internal import expect_style_to_have_value as _expect_style_to_have_value
1818from ._base import (
1919 InitLocator ,
20+ UiWithContainerP ,
2021 UiWithLabel ,
2122 WidthContainerM ,
22- WidthLocM ,
23- _expect_multiple ,
2423 all_missing ,
2524 not_is_missing ,
2625)
3029)
3130
3231
33- class _InputSliderBase (WidthLocM , UiWithLabel ):
32+ class _InputSliderBase (UiWithLabel ):
3433
3534 loc_irs : Locator
3635 """
@@ -203,6 +202,19 @@ def expect_max(self, value: AttrValue, *, timeout: Timeout = None) -> None:
203202 self .loc , "data-max" , value = value , timeout = timeout
204203 )
205204
205+ def expect_width (self , value : str , * , timeout : Timeout = None ) -> None :
206+ """
207+ Expects the slider to have the specified width.
208+
209+ Parameters
210+ ----------
211+ value
212+ The expected width.
213+ timeout
214+ The maximum time to wait for the width to be visible and interactable. Defaults to `None`.
215+ """
216+ _expect_style_to_have_value (self .loc_container , "width" , value , timeout = timeout )
217+
206218 def expect_step (self , value : AttrValue , * , timeout : Timeout = None ) -> None :
207219 """
208220 Expect the input element to have the expected `step` attribute value.
@@ -923,30 +935,40 @@ def __init__(
923935 )
924936
925937
926- class _InputSelectBase (
927- WidthLocM ,
928- UiWithLabel ,
929- ):
930- loc_selected : Locator
931- """
932- Playwright `Locator` for the selected option of the input select.
933- """
934- loc_choices : Locator
935- """
936- Playwright `Locator` for the choices of the input select.
938+ class InputSelectWidthM :
937939 """
938- loc_choice_groups : Locator
939- """
940- Playwright `Locator` for the choice groups of the input select .
940+ A base class representing the input `select` and `selectize` widths.
941+
942+ This class provides methods to expect the width attribute of a DOM element .
941943 """
942944
943- def __init__ (
944- self ,
945- page : Page ,
946- id : str ,
945+ def expect_width (
946+ self : UiWithContainerP ,
947+ value : AttrValue ,
947948 * ,
948- select_class : str = "" ,
949+ timeout : Timeout = None ,
949950 ) -> None :
951+ """
952+ Expect the input select to have a specific width.
953+
954+ Parameters
955+ ----------
956+ value
957+ The expected width.
958+ timeout
959+ The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
960+ """
961+ _expect_style_to_have_value (self .loc_container , "width" , value , timeout = timeout )
962+
963+
964+ class InputSelect (InputSelectWidthM , UiWithLabel ):
965+ """
966+ Controller for :func:`shiny.ui.input_select`.
967+
968+ If you have defined your app's select input (`ui.input_select()`) with `selectize=TRUE`, use `InputSelectize` to test your app's UI.
969+ """
970+
971+ def __init__ (self , page : Page , id : str ) -> None :
950972 """
951973 Initializes the input select.
952974
@@ -956,13 +978,11 @@ def __init__(
956978 The page where the input select is located.
957979 id
958980 The id of the input select.
959- select_class
960- The class of the select element. Defaults to "".
961981 """
962982 super ().__init__ (
963983 page ,
964984 id = id ,
965- loc = f"select#{ id } .shiny-bound-input{ select_class } " ,
985+ loc = f"select#{ id } .shiny-bound-input.form-select " ,
966986 )
967987 self .loc_selected = self .loc .locator ("option:checked" )
968988 self .loc_choices = self .loc .locator ("option" )
@@ -988,9 +1008,29 @@ def set(
9881008 selected = [selected ]
9891009 self .loc .select_option (value = selected , timeout = timeout )
9901010
1011+ # If `selectize=` parameter does not become deprecated, uncomment this
1012+ # # selectize: bool = False,
1013+ # def expect_selectize(self, value: bool, *, timeout: Timeout = None) -> None:
1014+ # """
1015+ # Expect the input select to be selectize.
1016+
1017+ # Parameters
1018+ # ----------
1019+ # value
1020+ # Whether the input select is selectize.
1021+ # timeout
1022+ # The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
1023+ # """
1024+ # # class_=None if selectize else "form-select",
1025+ # _expect_class_to_have_value(
1026+ # self.loc,
1027+ # "form-select",
1028+ # has_class=not value,
1029+ # timeout=timeout,
1030+ # )
1031+
9911032 def expect_choices (
9921033 self ,
993- # TODO-future; support patterns?
9941034 choices : ListPatternOrStr ,
9951035 * ,
9961036 timeout : Timeout = None ,
@@ -1111,10 +1151,9 @@ def expect_choice_labels(
11111151 return
11121152 playwright_expect (self .loc_choices ).to_have_text (value , timeout = timeout )
11131153
1114- # multiple: bool = False,
11151154 def expect_multiple (self , value : bool , * , timeout : Timeout = None ) -> None :
11161155 """
1117- Expect the input select to allow multiple selections.
1156+ Expect the input selectize to allow multiple selections.
11181157
11191158 Parameters
11201159 ----------
@@ -1123,7 +1162,12 @@ def expect_multiple(self, value: bool, *, timeout: Timeout = None) -> None:
11231162 timeout
11241163 The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
11251164 """
1126- _expect_multiple (self .loc , value , timeout = timeout )
1165+ _expect_attribute_to_have_value (
1166+ self .loc ,
1167+ "multiple" ,
1168+ value = "" if value else None ,
1169+ timeout = timeout ,
1170+ )
11271171
11281172 def expect_size (self , value : AttrValue , * , timeout : Timeout = None ) -> None :
11291173 """
@@ -1144,50 +1188,7 @@ def expect_size(self, value: AttrValue, *, timeout: Timeout = None) -> None:
11441188 )
11451189
11461190
1147- class InputSelect (_InputSelectBase ):
1148- """Controller for :func:`shiny.ui.input_select`."""
1149-
1150- def __init__ (self , page : Page , id : str ) -> None :
1151- """
1152- Initializes the input select.
1153-
1154- Parameters
1155- ----------
1156- page
1157- The page where the input select is located.
1158- id
1159- The id of the input select.
1160- """
1161- super ().__init__ (
1162- page ,
1163- id = id ,
1164- select_class = ".form-select" ,
1165- )
1166-
1167- # selectize: bool = False,
1168- def expect_selectize (self , value : bool , * , timeout : Timeout = None ) -> None :
1169- """
1170- Expect the input select to be selectize.
1171-
1172- Parameters
1173- ----------
1174- value
1175- Whether the input select is selectize.
1176- timeout
1177- The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
1178- """
1179- # class_=None if selectize else "form-select",
1180- _expect_class_to_have_value (
1181- self .loc ,
1182- "form-select" ,
1183- has_class = not value ,
1184- timeout = timeout ,
1185- )
1186-
1187-
1188- class InputSelectize (
1189- UiWithLabel ,
1190- ):
1191+ class InputSelectize (InputSelectWidthM , UiWithLabel ):
11911192 """Controller for :func:`shiny.ui.input_selectize`."""
11921193
11931194 def __init__ (self , page : Page , id : str ) -> None :
0 commit comments