Skip to content

Commit 8f78b5b

Browse files
committed
tests: Add tests for auto-submit and focus
1 parent a1bbeb3 commit 8f78b5b

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

tests/playwright/shiny/components/chat/input-suggestion/app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
welcome = ui.HTML(
44
"""
5-
Here is the <span class='suggestion'>1st input suggestion</span>.
6-
And here is a <span data-suggestion='The actual suggestion'>2nd suggestion</span>.
7-
Finally, a <img data-suggestion='A 3rd, image-based, suggestion' src='shiny-hex.svg' height="50px" alt='Shiny logo'> image suggestion.
5+
<p>Here is the <span id="first" class='suggestion'>1st input suggestion</span>.
6+
And here is a <span id="second" data-suggestion='The actual suggestion'>2nd suggestion</span>.
7+
Finally, a <img id="third" data-suggestion='A 3rd, image-based, suggestion' src='shiny-hex.svg' height="50px" alt='Shiny logo'> image suggestion.</p>
8+
9+
<p>On the other hand, <span id="fourth" class="suggestion submit">this suggestion will auto-submit</span>.
10+
And <span id="fifth" data-suggestion="another suggestion" data-suggestion-submit="true">this suggestion will also auto-submit</span>.</p>
811
"""
912
)
1013

tests/playwright/shiny/components/chat/input-suggestion/test_chat_input_suggestion.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ def test_validate_chat_input_suggestion(page: Page, local_app: ShinyAppProc) ->
1717
expect(chat.loc_input_button).to_be_disabled()
1818

1919
# Locate input suggestions
20-
first = chat.loc.locator(".suggestion", has_text="1st input suggestion")
21-
second = chat.loc.locator("span[data-suggestion]")
22-
third = chat.loc.locator("img[data-suggestion]")
20+
first = chat.loc.locator("#first", has_text="1st input suggestion")
21+
second = chat.loc.locator("#second")
22+
third = chat.loc.locator("#third")
23+
fourth = chat.loc.locator("#fourth")
24+
fifth = chat.loc.locator("#fifth")
2325

2426
# Click on each suggestion and verify the input
2527
first.click()
@@ -39,3 +41,17 @@ def test_validate_chat_input_suggestion(page: Page, local_app: ShinyAppProc) ->
3941
chat.expect_latest_message("You said: A 3rd, image-based, suggestion")
4042
chat.expect_user_input("")
4143
expect(chat.loc_input_button).to_be_disabled()
44+
45+
# Test auto-submitting suggestions
46+
fourth.click()
47+
chat.expect_latest_message("You said: this suggestion will auto-submit")
48+
chat.expect_user_input("")
49+
expect(chat.loc_input_button).to_be_disabled()
50+
expect(chat.loc_input).not_to_be_focused()
51+
52+
fifth.focus()
53+
page.keyboard.press("Enter")
54+
chat.expect_latest_message("You said: another suggestion")
55+
chat.expect_user_input("")
56+
expect(chat.loc_input_button).to_be_disabled()
57+
expect(chat.loc_input).not_to_be_focused()

0 commit comments

Comments
 (0)