From 4ebf974fe1c51d1836b98e8a950c68784bd0c9e5 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Thu, 12 Sep 2024 09:52:08 -0700 Subject: [PATCH 1/5] tests(popover): Add kitchensink tests for popover and tooltip --- .../popover/popover_test_kitchen/app.py | 35 ++++++++++++++ .../test_popover_kitchensink.py | 47 +++++++++++++++++++ .../tooltip/tooltip_test_kitchen/app.py | 27 +++++++++++ .../test_tooltip_test_kitchen.py | 38 +++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 tests/playwright/shiny/components/popover/popover_test_kitchen/app.py create mode 100644 tests/playwright/shiny/components/popover/popover_test_kitchen/test_popover_kitchensink.py create mode 100644 tests/playwright/shiny/components/tooltip/tooltip_test_kitchen/app.py create mode 100644 tests/playwright/shiny/components/tooltip/tooltip_test_kitchen/test_tooltip_test_kitchen.py diff --git a/tests/playwright/shiny/components/popover/popover_test_kitchen/app.py b/tests/playwright/shiny/components/popover/popover_test_kitchen/app.py new file mode 100644 index 000000000..41b4c2105 --- /dev/null +++ b/tests/playwright/shiny/components/popover/popover_test_kitchen/app.py @@ -0,0 +1,35 @@ +from shiny.express import ui + +ui.page_opts(title="Popover Kitchen sink", id="page_navbar") + +ui.br() +ui.br() + +with ui.popover(id="btn_popover_title", title="Popover title"): + ui.input_action_button("btn", "A button") + "Placement should be auto along with a title" + +ui.br() +ui.br() +ui.br() +ui.br() + +with ui.popover(id="btn_popover_top", placement="top"): + ui.input_action_button("btn2", "A button") + "Popover placement should be on the top" + +ui.br() +ui.br() +ui.br() +ui.br() + + +with ui.layout_columns(col_widths=[4, 4]): + + with ui.popover(id="btn_popover_right", placement="right"): + ui.input_action_button("btn3", "A button") + "Popover placement should be on the right" + + with ui.popover(id="btn_popover_left", placement="left"): + ui.input_action_button("btn4", "A button") + "Popover placement should be on the left" diff --git a/tests/playwright/shiny/components/popover/popover_test_kitchen/test_popover_kitchensink.py b/tests/playwright/shiny/components/popover/popover_test_kitchen/test_popover_kitchensink.py new file mode 100644 index 000000000..568642ec1 --- /dev/null +++ b/tests/playwright/shiny/components/popover/popover_test_kitchen/test_popover_kitchensink.py @@ -0,0 +1,47 @@ +from playwright.sync_api import Page + +from shiny.playwright import controller +from shiny.run import ShinyAppProc + + +def test_popover_kitchensink(page: Page, local_app: ShinyAppProc) -> None: + page.goto(local_app.url) + + popover_auto = controller.Popover(page, "btn_popover_title") + popover_auto.expect_active(False) + popover_auto.set(True) + popover_auto.expect_active(True) + popover_auto.expect_body("Placement should be auto along with a title") + # popover_auto.expect_title("Popover title") # TODO-need to fix this + popover_auto.expect_placement( + "right" + ) # since there is no space on the top, it defaults to right + popover_auto.set(False) + popover_auto.expect_active(False) + + popover_top = controller.Popover(page, "btn_popover_top") + popover_top.expect_active(False) + popover_top.set(True) + popover_top.expect_active(True) + popover_top.expect_body("Popover placement should be on the top") + popover_top.expect_placement("top") + popover_top.set(False) + popover_top.expect_active(False) + + popover_right = controller.Popover(page, "btn_popover_right") + popover_right.expect_active(False) + popover_right.set(True) + popover_right.expect_active(True) + popover_right.expect_body("Popover placement should be on the right") + popover_right.expect_placement("right") + popover_right.set(False) + popover_right.expect_active(False) + + popover_left = controller.Popover(page, "btn_popover_left") + popover_left.expect_active(False) + popover_left.set(True) + popover_left.expect_active(True) + popover_left.expect_body("Popover placement should be on the left") + popover_left.expect_placement("left") + popover_left.set(False) + popover_left.expect_active(False) diff --git a/tests/playwright/shiny/components/tooltip/tooltip_test_kitchen/app.py b/tests/playwright/shiny/components/tooltip/tooltip_test_kitchen/app.py new file mode 100644 index 000000000..4f1decdb4 --- /dev/null +++ b/tests/playwright/shiny/components/tooltip/tooltip_test_kitchen/app.py @@ -0,0 +1,27 @@ +from shiny.express import ui + +with ui.tooltip(id="default_tooltip_auto"): + ui.input_action_button("btn", "A button", class_="mt-3") + "An auto message" + +ui.br() +ui.br() + +with ui.tooltip(id="default_tooltip_top", placement="top"): + ui.input_action_button("btn2", "A button", class_="mt-3") + "A top message" + +ui.br() +ui.br() + +with ui.tooltip(id="default_tooltip_right", placement="right"): + ui.input_action_button("btn3", "A button", class_="mt-3") + "A right message" + + +ui.br() +ui.br() + +with ui.tooltip(id="default_tooltip_left", placement="left"): + ui.input_action_button("btn4", "A button", class_="mt-3") + "A left message" diff --git a/tests/playwright/shiny/components/tooltip/tooltip_test_kitchen/test_tooltip_test_kitchen.py b/tests/playwright/shiny/components/tooltip/tooltip_test_kitchen/test_tooltip_test_kitchen.py new file mode 100644 index 000000000..de43eab91 --- /dev/null +++ b/tests/playwright/shiny/components/tooltip/tooltip_test_kitchen/test_tooltip_test_kitchen.py @@ -0,0 +1,38 @@ +from playwright.sync_api import Page + +from shiny.playwright import controller +from shiny.run import ShinyAppProc + + +def test_tooltip_test_kitchen(page: Page, local_app: ShinyAppProc) -> None: + page.goto(local_app.url) + + tooltip_auto = controller.Tooltip(page, "default_tooltip_auto") + tooltip_auto.expect_active(False) + tooltip_auto.set(True) + tooltip_auto.expect_active(True) + tooltip_auto.expect_body("An auto message") + tooltip_auto.expect_placement( + "right" + ) # since there is no space on the top, it defaults to right + + tooltip_top = controller.Tooltip(page, "default_tooltip_top") + tooltip_top.expect_active(False) + tooltip_top.set(True) + tooltip_top.expect_active(True) + tooltip_top.expect_body("A top message") + tooltip_top.expect_placement("top") + + tooltip_right = controller.Tooltip(page, "default_tooltip_right") + tooltip_right.expect_active(False) + tooltip_right.set(True) + tooltip_right.expect_active(True) + tooltip_right.expect_body("A right message") + tooltip_right.expect_placement("right") + + tooltip_left = controller.Tooltip(page, "default_tooltip_left") + tooltip_left.expect_active(False) + tooltip_left.set(True) + tooltip_left.expect_active(True) + tooltip_left.expect_body("A left message") + tooltip_left.expect_placement("left") From 3072c2b9d3b17edeef113fa2c055befea092b087 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Thu, 12 Sep 2024 10:45:58 -0700 Subject: [PATCH 2/5] add tests for popover title --- shiny/playwright/controller/_overlay.py | 15 +++++++++++++++ .../test_popover_kitchensink.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/shiny/playwright/controller/_overlay.py b/shiny/playwright/controller/_overlay.py index e0f825c03..e1a283e1b 100644 --- a/shiny/playwright/controller/_overlay.py +++ b/shiny/playwright/controller/_overlay.py @@ -212,6 +212,21 @@ def _toggle(self, timeout: Timeout = None) -> None: self.loc_trigger.scroll_into_view_if_needed(timeout=timeout) self.loc_trigger.click(timeout=timeout) + def expect_title(self, value: PatternOrStr, *, timeout: Timeout = None) -> None: + """ + Expects the popover title to have the specified text. + + Parameters + ---------- + value + The expected text pattern or string. + timeout + The maximum time to wait for the popover header to appear. Defaults to `None`. + """ + playwright_expect( + self.get_loc_overlay_container().locator("> .popover-header") + ).to_have_text(value, timeout=timeout) + class Tooltip(_OverlayBase): """Controller for :func:`shiny.ui.tooltip`.""" diff --git a/tests/playwright/shiny/components/popover/popover_test_kitchen/test_popover_kitchensink.py b/tests/playwright/shiny/components/popover/popover_test_kitchen/test_popover_kitchensink.py index 568642ec1..b0b9944e9 100644 --- a/tests/playwright/shiny/components/popover/popover_test_kitchen/test_popover_kitchensink.py +++ b/tests/playwright/shiny/components/popover/popover_test_kitchen/test_popover_kitchensink.py @@ -12,7 +12,7 @@ def test_popover_kitchensink(page: Page, local_app: ShinyAppProc) -> None: popover_auto.set(True) popover_auto.expect_active(True) popover_auto.expect_body("Placement should be auto along with a title") - # popover_auto.expect_title("Popover title") # TODO-need to fix this + popover_auto.expect_title("Popover title") popover_auto.expect_placement( "right" ) # since there is no space on the top, it defaults to right From d1e5b732a0987d1411c285cfbbc56acb8b2f166c Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Thu, 12 Sep 2024 11:17:36 -0700 Subject: [PATCH 3/5] move update overlay tests to its own dir --- .../shiny/components/popover/{ => update_popover}/app.py | 0 .../shiny/components/popover/{ => update_popover}/test_popover.py | 0 .../shiny/components/tooltip/{ => update_tooltip}/app.py | 0 .../shiny/components/tooltip/{ => update_tooltip}/test_tooltip.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename tests/playwright/shiny/components/popover/{ => update_popover}/app.py (100%) rename tests/playwright/shiny/components/popover/{ => update_popover}/test_popover.py (100%) rename tests/playwright/shiny/components/tooltip/{ => update_tooltip}/app.py (100%) rename tests/playwright/shiny/components/tooltip/{ => update_tooltip}/test_tooltip.py (100%) diff --git a/tests/playwright/shiny/components/popover/app.py b/tests/playwright/shiny/components/popover/update_popover/app.py similarity index 100% rename from tests/playwright/shiny/components/popover/app.py rename to tests/playwright/shiny/components/popover/update_popover/app.py diff --git a/tests/playwright/shiny/components/popover/test_popover.py b/tests/playwright/shiny/components/popover/update_popover/test_popover.py similarity index 100% rename from tests/playwright/shiny/components/popover/test_popover.py rename to tests/playwright/shiny/components/popover/update_popover/test_popover.py diff --git a/tests/playwright/shiny/components/tooltip/app.py b/tests/playwright/shiny/components/tooltip/update_tooltip/app.py similarity index 100% rename from tests/playwright/shiny/components/tooltip/app.py rename to tests/playwright/shiny/components/tooltip/update_tooltip/app.py diff --git a/tests/playwright/shiny/components/tooltip/test_tooltip.py b/tests/playwright/shiny/components/tooltip/update_tooltip/test_tooltip.py similarity index 100% rename from tests/playwright/shiny/components/tooltip/test_tooltip.py rename to tests/playwright/shiny/components/tooltip/update_tooltip/test_tooltip.py From 6ca439e6d25a2e6339cc32b416e04afb16aa0093 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Thu, 12 Sep 2024 14:46:30 -0700 Subject: [PATCH 4/5] Add changelog entry about new method --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c2bf330c..94651a01e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `shiny create` now uses the template `id` rather than the directory name as the default directory. (#1666) +### Other changes + +* Added `.expect_title()` for `Popover` controller (#1683) + ## [1.1.0] - 2024-09-03 ### New features From 44a00a0e02dbf53726ef5d8f82c9daf7379596a5 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Thu, 12 Sep 2024 20:23:56 -0400 Subject: [PATCH 5/5] Consolidate sections --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a788ba90..d385a1105 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `.expect_widths()` to `NavsetPillList` in `shiny.playwright.controllers` for testing `ui.navset_pill_list(widths=)`. (#1668) +* Added `.expect_title()` for `Popover` controller (#1683) + ### Bug fixes * A few fixes for `ui.Chat()`, including: @@ -30,10 +32,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `shiny create` now uses the template `id` rather than the directory name as the default directory. (#1666) -### Other changes - -* Added `.expect_title()` for `Popover` controller (#1683) - ## [1.1.0] - 2024-09-03 ### New features