17
17
from ..expect ._internal import expect_style_to_have_value as _expect_style_to_have_value
18
18
from ._base import (
19
19
InitLocator ,
20
+ UiWithContainerP ,
20
21
UiWithLabel ,
21
22
WidthContainerM ,
22
23
WidthLocM ,
23
- _expect_multiple ,
24
24
all_missing ,
25
25
not_is_missing ,
26
26
)
@@ -923,30 +923,40 @@ def __init__(
923
923
)
924
924
925
925
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.
937
- """
938
- loc_choice_groups : Locator
926
+ class InputSelectWidthM :
939
927
"""
940
- Playwright `Locator` for the choice groups of the input select.
928
+ A base class representing the input `select` and `selectize` widths.
929
+
930
+ This class provides methods to expect the width attribute of a DOM element.
941
931
"""
942
932
943
- def __init__ (
944
- self ,
945
- page : Page ,
946
- id : str ,
933
+ def expect_width (
934
+ self : UiWithContainerP ,
935
+ value : AttrValue ,
947
936
* ,
948
- select_class : str = "" ,
937
+ timeout : Timeout = None ,
949
938
) -> None :
939
+ """
940
+ Expect the input select to have a specific width.
941
+
942
+ Parameters
943
+ ----------
944
+ value
945
+ The expected width.
946
+ timeout
947
+ The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
948
+ """
949
+ _expect_style_to_have_value (self .loc_container , "width" , value , timeout = timeout )
950
+
951
+
952
+ class InputSelect (InputSelectWidthM , UiWithLabel ):
953
+ """
954
+ Controller for :func:`shiny.ui.input_select`.
955
+
956
+ If you have defined your app's select input (`ui.input_select()`) with `selectize=TRUE`, use `InputSelectize` to test your app's UI.
957
+ """
958
+
959
+ def __init__ (self , page : Page , id : str ) -> None :
950
960
"""
951
961
Initializes the input select.
952
962
@@ -956,13 +966,11 @@ def __init__(
956
966
The page where the input select is located.
957
967
id
958
968
The id of the input select.
959
- select_class
960
- The class of the select element. Defaults to "".
961
969
"""
962
970
super ().__init__ (
963
971
page ,
964
972
id = id ,
965
- loc = f"select#{ id } .shiny-bound-input{ select_class } " ,
973
+ loc = f"select#{ id } .shiny-bound-input.form-select " ,
966
974
)
967
975
self .loc_selected = self .loc .locator ("option:checked" )
968
976
self .loc_choices = self .loc .locator ("option" )
@@ -988,9 +996,29 @@ def set(
988
996
selected = [selected ]
989
997
self .loc .select_option (value = selected , timeout = timeout )
990
998
999
+ # If `selectize=` parameter does not become deprecated, uncomment this
1000
+ # # selectize: bool = False,
1001
+ # def expect_selectize(self, value: bool, *, timeout: Timeout = None) -> None:
1002
+ # """
1003
+ # Expect the input select to be selectize.
1004
+
1005
+ # Parameters
1006
+ # ----------
1007
+ # value
1008
+ # Whether the input select is selectize.
1009
+ # timeout
1010
+ # The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
1011
+ # """
1012
+ # # class_=None if selectize else "form-select",
1013
+ # _expect_class_to_have_value(
1014
+ # self.loc,
1015
+ # "form-select",
1016
+ # has_class=not value,
1017
+ # timeout=timeout,
1018
+ # )
1019
+
991
1020
def expect_choices (
992
1021
self ,
993
- # TODO-future; support patterns?
994
1022
choices : ListPatternOrStr ,
995
1023
* ,
996
1024
timeout : Timeout = None ,
@@ -1111,10 +1139,9 @@ def expect_choice_labels(
1111
1139
return
1112
1140
playwright_expect (self .loc_choices ).to_have_text (value , timeout = timeout )
1113
1141
1114
- # multiple: bool = False,
1115
1142
def expect_multiple (self , value : bool , * , timeout : Timeout = None ) -> None :
1116
1143
"""
1117
- Expect the input select to allow multiple selections.
1144
+ Expect the input selectize to allow multiple selections.
1118
1145
1119
1146
Parameters
1120
1147
----------
@@ -1123,7 +1150,12 @@ def expect_multiple(self, value: bool, *, timeout: Timeout = None) -> None:
1123
1150
timeout
1124
1151
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
1125
1152
"""
1126
- _expect_multiple (self .loc , value , timeout = timeout )
1153
+ _expect_attribute_to_have_value (
1154
+ self .loc ,
1155
+ "multiple" ,
1156
+ value = "" if value else None ,
1157
+ timeout = timeout ,
1158
+ )
1127
1159
1128
1160
def expect_size (self , value : AttrValue , * , timeout : Timeout = None ) -> None :
1129
1161
"""
@@ -1144,50 +1176,7 @@ def expect_size(self, value: AttrValue, *, timeout: Timeout = None) -> None:
1144
1176
)
1145
1177
1146
1178
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
- ):
1179
+ class InputSelectize (InputSelectWidthM , UiWithLabel ):
1191
1180
"""Controller for :func:`shiny.ui.input_selectize`."""
1192
1181
1193
1182
def __init__ (self , page : Page , id : str ) -> None :
0 commit comments