|
8 | 8 | from shiny.run import ShinyAppProc |
9 | 9 |
|
10 | 10 |
|
| 11 | +def click_action_button(page: Page, x: controller.InputActionButton): |
| 12 | + """Click the button without moving focus (changes input, doesn't change value)""" |
| 13 | + page.evaluate( |
| 14 | + "([id]) => document.getElementById(id).click()", [x.id] |
| 15 | + ) |
| 16 | + |
11 | 17 | def test_text_input_change(page: Page, local_app: ShinyAppProc): |
12 | 18 | page.goto(local_app.url) |
13 | 19 |
|
14 | 20 | input = controller.InputText(page, "change-txt") |
| 21 | + output = controller.OutputTextVerbatim(page, "change-value_txt") |
15 | 22 | update = controller.InputActionButton(page, "change-update_text") |
16 | 23 |
|
17 | 24 | # Test textInput() -- updateOn='change' |
18 | 25 | the_value = "Hello" |
19 | 26 | input.set(the_value) |
20 | | - input.expect_value(the_value) |
| 27 | + output.expect_value(the_value) |
21 | 28 |
|
22 | 29 | input.loc.press("End") |
23 | 30 | input.loc.type(", world") |
24 | 31 |
|
25 | 32 | time.sleep(0.5) |
26 | 33 | the_value = "Hello, world" |
27 | | - input.expect_value(the_value) |
| 34 | + output.expect_value(the_value) |
28 | 35 | expect(input.loc).to_be_focused() |
29 | 36 |
|
30 | | - update.click() |
| 37 | + click_action_button(page, update) |
31 | 38 | the_value = "serendipity ephemeral" |
32 | | - input.expect_value(the_value) |
| 39 | + output.expect_value(the_value) |
33 | 40 |
|
34 | 41 |
|
35 | 42 | def test_text_input_blur(page: Page, local_app: ShinyAppProc): |
36 | 43 | page.goto(local_app.url) |
37 | 44 |
|
38 | 45 | # Test textInput() -- updateOn='blur' |
39 | 46 | input = controller.InputText(page, "blur-txt") |
| 47 | + output = controller.OutputTextVerbatim(page, "blur-value_txt") |
40 | 48 | update = controller.InputActionButton(page, "blur-update_text") |
41 | 49 |
|
42 | 50 | the_value = "Hello" |
43 | 51 | input.set(the_value) |
44 | | - input.expect_value(the_value) |
| 52 | + output.expect_value(the_value) |
45 | 53 |
|
46 | 54 | input.loc.focus() |
47 | 55 | input.loc.press("End") |
48 | 56 | input.loc.type(", world") |
49 | 57 |
|
50 | | - input.expect_value(the_value) # has not changed yet! |
| 58 | + output.expect_value(the_value) # has not changed yet! |
51 | 59 |
|
52 | 60 | the_value = "Hello, world" |
53 | 61 | input.loc.blur() |
54 | | - input.expect_value(the_value) |
| 62 | + output.expect_value(the_value) # changes on blur |
55 | 63 |
|
56 | 64 | input.loc.focus() |
57 | 65 | input.loc.press("End") |
58 | 66 | input.loc.type("!") |
59 | | - input.expect_value(the_value) # still hasn't changed yet |
60 | | - input.loc.press("Enter") |
| 67 | + output.expect_value(the_value) # still hasn't changed yet |
61 | 68 |
|
62 | 69 | the_value = "Hello, world!" |
63 | | - input.expect_value(the_value) |
| 70 | + input.loc.press("Enter") |
| 71 | + output.expect_value(the_value) # changes after Enter |
64 | 72 |
|
65 | | - page.evaluate( |
66 | | - "element => element.click()", update.loc |
67 | | - ) # hopefully doesn't move focus |
68 | | - input.expect_value(the_value) |
| 73 | + click_action_button(page, update) |
| 74 | + input.expect_value("serendipity ephemeral") |
| 75 | + output.expect_value(the_value) |
69 | 76 |
|
70 | | - page.evaluate( |
71 | | - "element => element.click()", update.loc |
72 | | - ) # hopefully doesn't move focus |
73 | | - input.expect_value(the_value) |
| 77 | + click_action_button(page, update) |
| 78 | + input.expect_value("ephemeral mellifluous") |
| 79 | + output.expect_value(the_value) |
74 | 80 |
|
75 | | - input.loc.press("Enter") # now it changes |
76 | 81 | the_value = "ephemeral mellifluous" |
77 | | - input.expect_value(the_value) |
| 82 | + input.loc.press("Enter") # changes again after Enter |
| 83 | + output.expect_value(the_value) |
78 | 84 |
|
79 | 85 |
|
80 | 86 | # Add similar tests for textAreaInput(), numericInput(), and passwordInput() |
|
0 commit comments