Skip to content

Commit 5a65eba

Browse files
committed
Fixed some of the failing tests
1 parent 86726df commit 5a65eba

22 files changed

+50
-169
lines changed

shiny/playwright/controller/_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ def set_text(
120120
# TODO-future; Composable set() method
121121
loc.fill("", timeout=timeout) # Reset the value
122122
loc.type(text, delay=delay, timeout=timeout) # Type the value
123-
loc.press("Enter", timeout=timeout)
124123

125124

126125
def _expect_multiple(loc: Locator, multiple: bool, timeout: Timeout = None) -> None:

shiny/playwright/controller/_input_buttons.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ def expect_disabled(self, value: bool, *, timeout: Timeout = None):
6767

6868

6969
class InputBookmarkButton(
70-
WidthLocStlyeM,
71-
InputActionBase,
70+
InputActionButton,
7271
):
7372
"""Controller for :func:`shiny.ui.input_bookmark_button`."""
7473

7574
def __init__(
7675
self,
7776
page: Page,
78-
id: str = "`._bookmark_`",
77+
id: str = "._bookmark_",
7978
) -> None:
8079
"""
8180
Initializes the input bookmark button.
@@ -90,7 +89,6 @@ def __init__(
9089
super().__init__(
9190
page,
9291
id=id,
93-
loc=f"button#{id}.action-button.shiny-bound-input",
9492
)
9593

9694
def expect_disabled(self, value: bool, *, timeout: Timeout = None):
@@ -104,9 +102,7 @@ def expect_disabled(self, value: bool, *, timeout: Timeout = None):
104102
timeout
105103
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
106104
"""
107-
_expect_attribute_to_have_value(
108-
self.loc, "disabled", re.compile(".*") if value else None, timeout=timeout
109-
)
105+
super().expect_disabled(value, timeout=timeout)
110106

111107

112108
class InputDarkMode(UiBase):

shiny/playwright/controller/_input_fields.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,20 @@ def expect_daysofweekdisabled(
647647
timeout=timeout,
648648
)
649649

650+
def set(self, value: str, *, timeout: Timeout = None) -> None:
651+
"""
652+
Sets the text value
653+
654+
Parameters
655+
----------
656+
value
657+
The text to set.
658+
timeout
659+
The maximum time to wait for the text to be set. Defaults to `None`.
660+
"""
661+
set_text(self.loc, value, timeout=timeout)
662+
self.loc.press("Enter", timeout=timeout)
663+
650664

651665
class InputDate(_DateBase):
652666
def __init__(self, page: Page, id: str) -> None:

shiny/ui/_input_select.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ def input_select(
200200

201201
resolved_id = resolve_id(id)
202202

203-
choices_ = restore_input(resolved_id, choices)
203+
choices_ = _normalize_choices(choices)
204+
205+
selected = restore_input(resolved_id, selected)
204206
if selected is None and not multiple:
205207
selected = _find_first_option(choices_)
206208

shiny/ui/_input_slider.py

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

3+
from shiny.bookmark._restore_state import restore_input
4+
35
__all__ = (
46
"input_slider",
57
"SliderValueArg",
@@ -140,9 +142,10 @@ def input_slider(
140142
* :func:`~shiny.ui.update_slider`
141143
"""
142144

145+
resolved_id = resolve_id(id)
146+
value = restore_input(resolved_id, value)
143147
# Thanks to generic typing, max, value, etc. should be of the same type
144148
data_type = _slider_type(min)
145-
146149
# Make sure min, max, value, and step are all numeric
147150
# (converts dates/datetimes to milliseconds since epoch...this is the value JS wants)
148151
min_num = _as_numeric(min)
@@ -201,7 +204,6 @@ def input_slider(
201204
# ionRangeSlider wants attr = 'true'/'false'
202205
props = {k: str(v).lower() if isinstance(v, bool) else v for k, v in props.items()}
203206

204-
resolved_id = resolve_id(id)
205207
slider_tag = div(
206208
shiny_input_label(resolved_id, label),
207209
tags.input(**props),

shiny/ui/_input_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def input_text_area(
182182

183183
resolved_id = resolve_id(id)
184184
area = tags.textarea(
185-
value=restore_input(resolved_id, value),
185+
restore_input(resolved_id, value),
186186
id=resolved_id,
187187
class_=" ".join(classes),
188188
style=css(width=None if width else "100%", height=height, resize=resize),

tests/playwright/ai_generated_apps/bookmark_tests/bookmark_exclusion/app-core.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,10 @@ def excluded_module_text():
3939
async def _():
4040
await session.bookmark()
4141

42-
@session.bookmark.on_bookmark
43-
async def _(state: BookmarkState):
44-
# 3. Store the value directly
45-
state.values["module_num"] = input.num_in()
46-
47-
@session.bookmark.on_restore
48-
def _(state: RestoreState):
49-
# 4. Fix: Correct key name and input access
50-
if "module_num" in state.values:
51-
ui.update_numeric("num_in", value=state.values["module_num"])
52-
53-
# 5. Fix: Correct input access for module
54-
if "text_in" in state.input:
55-
print(f"module on_restore: text: {state.input['text_in']}")
56-
5742

5843
def app_ui(request: Request):
5944
return ui.page_fluid(
6045
mod_ui("mod1"),
61-
ui.input_bookmark_button(),
6246
)
6347

6448

tests/playwright/ai_generated_apps/bookmark_tests/bookmark_exclusion/test_bookmark_exclusion.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ def test_bookmark_exclusion(page: Page, app: ShinyAppProc) -> None:
2929
mod1_excluded.set("Hello excluded")
3030
mod1_excluded_txt.expect_value("Excluded text: Hello excluded")
3131

32-
# click bookmark button
33-
page.get_by_role("button", name="🔗 Bookmark...").click()
34-
3532
# reload page
3633
page.reload()
3734

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ def test_checkbox_demo(page: Page, app: ShinyAppProc) -> None:
3333
module_checkbox.expect_checked(True)
3434
module_text.expect_value("Checkbox value: True")
3535

36-
# TODO-Karan: Implement bookmark button controller
37-
# bookmark_button = controller.InputBookmarkButton(page)
38-
# bookmark_button.click()
39-
40-
page.get_by_role("button", name="🔗 Bookmark...").click()
36+
bookmark_button = controller.InputBookmarkButton(page)
37+
bookmark_button.click()
4138

4239
# reload the page to test bookmark
4340
page.reload()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def test_checkbox_group_demo(page: Page, app: ShinyAppProc) -> None:
3636
module_text.expect_value("Checkbox group values: ('Choice A', 'Choice C')")
3737

3838
# Bookmark the state
39-
page.get_by_role("button", name="🔗 Bookmark...").click()
39+
bookmark_button = controller.InputBookmarkButton(page)
40+
bookmark_button.click()
4041

4142
# Reload the page to test bookmark
4243
page.reload()

0 commit comments

Comments
 (0)