|
| 1 | +from playwright.sync_api import Page, expect |
| 2 | + |
| 3 | +from shiny.playwright import controller |
| 4 | +from shiny.run import ShinyAppProc |
| 5 | + |
| 6 | + |
| 7 | +def test_input_selectize_update_options(page: Page, local_app: ShinyAppProc) -> None: |
| 8 | + page.goto(local_app.url) |
| 9 | + |
| 10 | + single = controller.InputSelectize(page, "single") |
| 11 | + multiple = controller.InputSelectize(page, "multiple") |
| 12 | + |
| 13 | + single_out = controller.OutputCode(page, "single_out") |
| 14 | + multiple_out = controller.OutputCode(page, "multiple_out") |
| 15 | + |
| 16 | + # Confirm starting state |
| 17 | + single.expect_selected(["Option 1"]) |
| 18 | + multiple.expect_selected(["Option 1", "Option 2"]) |
| 19 | + |
| 20 | + def click_clear_button(x: controller.InputSelectize): |
| 21 | + x.loc.locator("..").locator("> div.plugin-clear_button > a.clear").click() |
| 22 | + |
| 23 | + # Can clear single selection via clear_button (after options have been updated) |
| 24 | + click_clear_button(single) |
| 25 | + single.expect_selected([""]) |
| 26 | + single_out.expect_value("") |
| 27 | + |
| 28 | + # Can clear multiple selection via clear_button (after options have been updated) |
| 29 | + click_clear_button(multiple) |
| 30 | + multiple.expect_selected([]) |
| 31 | + multiple_out.expect_value("") |
| 32 | + |
| 33 | + multiple.set(["Option 2", "Option 3"]) |
| 34 | + |
| 35 | + # Can remove individual options |
| 36 | + def click_remove_button(x: controller.InputSelectize, option: str): |
| 37 | + x.loc.locator( |
| 38 | + f"+ div.plugin-remove_button > .has-options > .item[data-value='{option}'] > .remove:first-child" |
| 39 | + ).click() |
| 40 | + page.keyboard.press("Escape") |
| 41 | + |
| 42 | + click_remove_button(multiple, "Option 2") |
| 43 | + multiple.expect_selected(["Option 3"]) |
| 44 | + multiple_out.expect_value("Option 3") |
| 45 | + |
| 46 | + click_remove_button(multiple, "Option 3") |
| 47 | + multiple.expect_selected([]) |
| 48 | + multiple_out.expect_value("") |
0 commit comments