|  | 
|  | 1 | +# test_input_text_update_on.py | 
|  | 2 | + | 
|  | 3 | +import time | 
|  | 4 | + | 
|  | 5 | +from playwright.sync_api import Page, expect | 
|  | 6 | + | 
|  | 7 | +from shiny.playwright import controller | 
|  | 8 | +from shiny.run import ShinyAppProc | 
|  | 9 | + | 
|  | 10 | + | 
|  | 11 | +def test_text_input_change(page: Page, local_app: ShinyAppProc): | 
|  | 12 | +    page.goto(local_app.url) | 
|  | 13 | + | 
|  | 14 | +    input = controller.InputText(page, "change-txt") | 
|  | 15 | +    update = controller.InputActionButton(page, "change-update_text") | 
|  | 16 | + | 
|  | 17 | +    # Test textInput() -- updateOn='change' | 
|  | 18 | +    the_value = "Hello" | 
|  | 19 | +    input.set(the_value) | 
|  | 20 | +    input.expect_value(the_value) | 
|  | 21 | + | 
|  | 22 | +    input.loc.press("End") | 
|  | 23 | +    input.loc.type(", world") | 
|  | 24 | + | 
|  | 25 | +    time.sleep(0.5) | 
|  | 26 | +    the_value = "Hello, world" | 
|  | 27 | +    input.expect_value(the_value) | 
|  | 28 | +    expect(input.loc).to_be_focused() | 
|  | 29 | + | 
|  | 30 | +    update.click() | 
|  | 31 | +    the_value = "serendipity ephemeral" | 
|  | 32 | +    input.expect_value(the_value) | 
|  | 33 | + | 
|  | 34 | + | 
|  | 35 | +def test_text_input_blur(page: Page, local_app: ShinyAppProc): | 
|  | 36 | +    page.goto(local_app.url) | 
|  | 37 | + | 
|  | 38 | +    # Test textInput() -- updateOn='blur' | 
|  | 39 | +    input = controller.InputText(page, "blur-txt") | 
|  | 40 | +    update = controller.InputActionButton(page, "blur-update_text") | 
|  | 41 | + | 
|  | 42 | +    the_value = "Hello" | 
|  | 43 | +    input.set(the_value) | 
|  | 44 | +    input.expect_value(the_value) | 
|  | 45 | + | 
|  | 46 | +    input.loc.focus() | 
|  | 47 | +    input.loc.press("End") | 
|  | 48 | +    input.loc.type(", world") | 
|  | 49 | + | 
|  | 50 | +    input.expect_value(the_value)  # has not changed yet! | 
|  | 51 | + | 
|  | 52 | +    the_value = "Hello, world" | 
|  | 53 | +    input.loc.blur() | 
|  | 54 | +    input.expect_value(the_value) | 
|  | 55 | + | 
|  | 56 | +    input.loc.focus() | 
|  | 57 | +    input.loc.press("End") | 
|  | 58 | +    input.loc.type("!") | 
|  | 59 | +    input.expect_value(the_value)  # still hasn't changed yet | 
|  | 60 | +    input.loc.press("Enter") | 
|  | 61 | + | 
|  | 62 | +    the_value = "Hello, world!" | 
|  | 63 | +    input.expect_value(the_value) | 
|  | 64 | + | 
|  | 65 | +    page.evaluate( | 
|  | 66 | +        "element => element.click()", update.loc | 
|  | 67 | +    )  # hopefully doesn't move focus | 
|  | 68 | +    input.expect_value(the_value) | 
|  | 69 | + | 
|  | 70 | +    page.evaluate( | 
|  | 71 | +        "element => element.click()", update.loc | 
|  | 72 | +    )  # hopefully doesn't move focus | 
|  | 73 | +    input.expect_value(the_value) | 
|  | 74 | + | 
|  | 75 | +    input.loc.press("Enter")  # now it changes | 
|  | 76 | +    the_value = "ephemeral mellifluous" | 
|  | 77 | +    input.expect_value(the_value) | 
|  | 78 | + | 
|  | 79 | + | 
|  | 80 | +# Add similar tests for textAreaInput(), numericInput(), and passwordInput() | 
|  | 81 | +# following the same pattern as above. | 
|  | 82 | + | 
|  | 83 | + | 
|  | 84 | +def test_text_area_input_change(page: Page, local_app: ShinyAppProc): | 
|  | 85 | +    # Implement test for textAreaInput() with updateOn='change' | 
|  | 86 | +    pass | 
|  | 87 | + | 
|  | 88 | + | 
|  | 89 | +def test_text_area_input_blur(page: Page, local_app: ShinyAppProc): | 
|  | 90 | +    # Implement test for textAreaInput() with updateOn='blur' | 
|  | 91 | +    pass | 
|  | 92 | + | 
|  | 93 | + | 
|  | 94 | +def test_numeric_input_change(page: Page, local_app: ShinyAppProc): | 
|  | 95 | +    # Implement test for numericInput() with updateOn='change' | 
|  | 96 | +    pass | 
|  | 97 | + | 
|  | 98 | + | 
|  | 99 | +def test_numeric_input_blur(page: Page, local_app: ShinyAppProc): | 
|  | 100 | +    # Implement test for numericInput() with updateOn='blur' | 
|  | 101 | +    pass | 
|  | 102 | + | 
|  | 103 | + | 
|  | 104 | +def test_password_input_change(page: Page, local_app: ShinyAppProc): | 
|  | 105 | +    # Implement test for passwordInput() with updateOn='change' | 
|  | 106 | +    pass | 
|  | 107 | + | 
|  | 108 | + | 
|  | 109 | +def test_password_input_blur(page: Page, local_app: ShinyAppProc): | 
|  | 110 | +    # Implement test for passwordInput() with updateOn='blur' | 
|  | 111 | +    pass | 
0 commit comments