|
| 1 | +from playwright.sync_api import Page, expect |
| 2 | +from utils.deploy_utils import skip_on_webkit |
| 3 | + |
| 4 | +from shiny.playwright import controller |
| 5 | +from shiny.run import ShinyAppProc |
| 6 | + |
| 7 | + |
| 8 | +@skip_on_webkit |
| 9 | +def test_validate_chat_update_user_input(page: Page, local_app: ShinyAppProc) -> None: |
| 10 | + page.goto(local_app.url) |
| 11 | + |
| 12 | + chat = controller.Chat(page, "chat") |
| 13 | + |
| 14 | + # Starting state sanity check |
| 15 | + expect(chat.loc).to_be_visible(timeout=30 * 1000) |
| 16 | + chat.expect_user_input("") |
| 17 | + expect(chat.loc_input_button).to_be_disabled() |
| 18 | + |
| 19 | + # Locate action buttons |
| 20 | + set_input = controller.InputActionButton(page, "set_input") |
| 21 | + set_and_focus = controller.InputActionButton(page, "set_and_focus") |
| 22 | + submit = controller.InputActionButton(page, "submit") |
| 23 | + submit_and_focus = controller.InputActionButton(page, "submit_and_focus") |
| 24 | + |
| 25 | + # Just set the input ---- |
| 26 | + set_input.loc.focus() |
| 27 | + set_input.click() |
| 28 | + chat.expect_user_input("Input was set, but neither focused nor submitted.") |
| 29 | + expect(chat.loc_input_button).to_be_enabled() |
| 30 | + expect(chat.loc_input).not_to_be_focused() |
| 31 | + |
| 32 | + # Set the input and move focus ---- |
| 33 | + set_and_focus.click() |
| 34 | + chat.expect_user_input("Input was set and focused, but not submitted.") |
| 35 | + expect(chat.loc_input_button).to_be_enabled() |
| 36 | + expect(chat.loc_input).to_be_focused() |
| 37 | + |
| 38 | + # Auto submit ---- |
| 39 | + submit.loc.focus() |
| 40 | + submit.click() |
| 41 | + chat.expect_user_input("") |
| 42 | + chat.expect_latest_message("You said: This chat was sent on behalf of the user.") |
| 43 | + expect(chat.loc_input_button).to_be_disabled() |
| 44 | + expect(chat.loc_input).not_to_be_focused() |
| 45 | + |
| 46 | + # Auto submit and move focus ---- |
| 47 | + submit_and_focus.loc.focus() |
| 48 | + submit_and_focus.click() |
| 49 | + chat.expect_user_input("") |
| 50 | + chat.expect_latest_message( |
| 51 | + "You said: This chat was sent on behalf of the user. Input will still be focused." |
| 52 | + ) |
| 53 | + expect(chat.loc_input_button).to_be_disabled() |
| 54 | + expect(chat.loc_input).to_be_focused() |
0 commit comments