Skip to content

Commit 59e3a38

Browse files
committed
Slightly more complete test for Shiny UI in startup message
1 parent b8dfce0 commit 59e3a38

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed
Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
11
from shiny import reactive
22
from shiny.express import input, ui
33

4-
ui.page_opts(
5-
title="Hello input bindings in Chat",
6-
fillable=True,
7-
fillable_mobile=True,
8-
)
9-
10-
welcome = f"""
11-
**Hello! Here are some inputs:**
4+
ui.page_opts(title="Testing input bindings in Chat", gap="3rem")
125

13-
{ui.input_select("select", "", choices=["a", "b", "c"])}
14-
{ui.input_slider("slider", "", min=0, max=100, value=50)}
15-
"""
6+
welcome = ui.TagList(
7+
"**Hello! Here are a couple inputs:**",
8+
ui.div(
9+
ui.input_select("select", "", choices=["a", "b", "c"], width="fit-content"),
10+
ui.input_switch("toggle", "Toggle", width="fit-content"),
11+
ui.input_action_button("insert_input", "Insert input"),
12+
class_="d-flex gap-5",
13+
),
14+
ui.div(
15+
ui.head_content(ui.tags.style("#chat { color: #29465B; }")),
16+
),
17+
)
1618

1719
chat = ui.Chat(
1820
id="chat",
1921
messages=[welcome],
2022
)
21-
chat.ui()
23+
chat.ui(class_="mb-5")
24+
25+
26+
@reactive.effect
27+
async def _():
28+
await chat.append_message(f"Now selected: {input.select()} and {input.toggle()}")
29+
30+
31+
@reactive.effect
32+
@reactive.event(input.insert_input)
33+
async def _():
34+
await chat.append_message_stream(
35+
[
36+
"Here's ",
37+
"another ",
38+
"input: ",
39+
ui.input_numeric("numeric", "", value=0),
40+
]
41+
)
42+
ui.update_action_button("insert_input", disabled=True)
2243

2344

2445
@reactive.effect
46+
@reactive.event(input.numeric, ignore_init=True)
2547
async def _():
26-
await chat.append_message(f"Now selected: {input.select()} and {input.slider()}")
48+
await chat.append_message(f"Numeric value: {input.numeric()}")

tests/playwright/shiny/components/chat/shiny_input/test_chat_shiny_input.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,29 @@ def test_validate_chat_shiny_output(page: Page, local_app: ShinyAppProc) -> None
1313

1414
chat = controller.Chat(page, "chat")
1515
expect(chat.loc).to_be_visible(timeout=TIMEOUT)
16+
expect(chat.loc).to_have_css("color", "rgb(41, 70, 91)")
1617

1718
select = controller.InputSelect(page, "select")
18-
slider = controller.InputSlider(page, "slider")
19+
toggle = controller.InputSwitch(page, "toggle")
1920
expect(select.loc).to_be_visible(timeout=TIMEOUT)
20-
expect(slider.loc).to_be_visible(timeout=TIMEOUT)
21+
expect(toggle.loc).to_be_visible(timeout=TIMEOUT)
2122

22-
chat.expect_latest_message("Now selected: a and 50")
23+
chat.expect_latest_message("Now selected: a and False")
2324

2425
select.set("b")
25-
chat.expect_latest_message("Now selected: b and 50")
26+
chat.expect_latest_message("Now selected: b and False")
2627

27-
slider.set("5")
28-
chat.expect_latest_message("Now selected: b and 5")
28+
toggle.set(True)
29+
chat.expect_latest_message("Now selected: b and True")
30+
31+
btn = controller.InputActionButton(page, "insert_input")
32+
expect(btn.loc).to_be_visible(timeout=TIMEOUT)
33+
btn.click()
34+
35+
chat.expect_latest_message("Numeric value: 0")
36+
37+
numeric = controller.InputNumeric(page, "numeric")
38+
expect(numeric.loc).to_be_visible(timeout=TIMEOUT)
39+
numeric.set("42")
40+
41+
chat.expect_latest_message("Numeric value: 42")

0 commit comments

Comments
 (0)