Skip to content

Commit 14d820c

Browse files
tests(popover): Add kitchensink tests for popover and tooltip (#1683)
Co-authored-by: Barret Schloerke <barret@posit.co>
1 parent 695f9cb commit 14d820c

File tree

10 files changed

+164
-0
lines changed

10 files changed

+164
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

2222
* Added `.expect_widths()` to `NavsetPillList` in `shiny.playwright.controllers` for testing `ui.navset_pill_list(widths=)`. (#1668)
2323

24+
* Added `.expect_title()` for `Popover` controller (#1683)
25+
2426
### Bug fixes
2527

2628
* A few fixes for `ui.Chat()`, including:

shiny/playwright/controller/_overlay.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,21 @@ def _toggle(self, timeout: Timeout = None) -> None:
212212
self.loc_trigger.scroll_into_view_if_needed(timeout=timeout)
213213
self.loc_trigger.click(timeout=timeout)
214214

215+
def expect_title(self, value: PatternOrStr, *, timeout: Timeout = None) -> None:
216+
"""
217+
Expects the popover title to have the specified text.
218+
219+
Parameters
220+
----------
221+
value
222+
The expected text pattern or string.
223+
timeout
224+
The maximum time to wait for the popover header to appear. Defaults to `None`.
225+
"""
226+
playwright_expect(
227+
self.get_loc_overlay_container().locator("> .popover-header")
228+
).to_have_text(value, timeout=timeout)
229+
215230

216231
class Tooltip(_OverlayBase):
217232
"""Controller for :func:`shiny.ui.tooltip`."""
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from shiny.express import ui
2+
3+
ui.page_opts(title="Popover Kitchen sink", id="page_navbar")
4+
5+
ui.br()
6+
ui.br()
7+
8+
with ui.popover(id="btn_popover_title", title="Popover title"):
9+
ui.input_action_button("btn", "A button")
10+
"Placement should be auto along with a title"
11+
12+
ui.br()
13+
ui.br()
14+
ui.br()
15+
ui.br()
16+
17+
with ui.popover(id="btn_popover_top", placement="top"):
18+
ui.input_action_button("btn2", "A button")
19+
"Popover placement should be on the top"
20+
21+
ui.br()
22+
ui.br()
23+
ui.br()
24+
ui.br()
25+
26+
27+
with ui.layout_columns(col_widths=[4, 4]):
28+
29+
with ui.popover(id="btn_popover_right", placement="right"):
30+
ui.input_action_button("btn3", "A button")
31+
"Popover placement should be on the right"
32+
33+
with ui.popover(id="btn_popover_left", placement="left"):
34+
ui.input_action_button("btn4", "A button")
35+
"Popover placement should be on the left"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from playwright.sync_api import Page
2+
3+
from shiny.playwright import controller
4+
from shiny.run import ShinyAppProc
5+
6+
7+
def test_popover_kitchensink(page: Page, local_app: ShinyAppProc) -> None:
8+
page.goto(local_app.url)
9+
10+
popover_auto = controller.Popover(page, "btn_popover_title")
11+
popover_auto.expect_active(False)
12+
popover_auto.set(True)
13+
popover_auto.expect_active(True)
14+
popover_auto.expect_body("Placement should be auto along with a title")
15+
popover_auto.expect_title("Popover title")
16+
popover_auto.expect_placement(
17+
"right"
18+
) # since there is no space on the top, it defaults to right
19+
popover_auto.set(False)
20+
popover_auto.expect_active(False)
21+
22+
popover_top = controller.Popover(page, "btn_popover_top")
23+
popover_top.expect_active(False)
24+
popover_top.set(True)
25+
popover_top.expect_active(True)
26+
popover_top.expect_body("Popover placement should be on the top")
27+
popover_top.expect_placement("top")
28+
popover_top.set(False)
29+
popover_top.expect_active(False)
30+
31+
popover_right = controller.Popover(page, "btn_popover_right")
32+
popover_right.expect_active(False)
33+
popover_right.set(True)
34+
popover_right.expect_active(True)
35+
popover_right.expect_body("Popover placement should be on the right")
36+
popover_right.expect_placement("right")
37+
popover_right.set(False)
38+
popover_right.expect_active(False)
39+
40+
popover_left = controller.Popover(page, "btn_popover_left")
41+
popover_left.expect_active(False)
42+
popover_left.set(True)
43+
popover_left.expect_active(True)
44+
popover_left.expect_body("Popover placement should be on the left")
45+
popover_left.expect_placement("left")
46+
popover_left.set(False)
47+
popover_left.expect_active(False)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from shiny.express import ui
2+
3+
with ui.tooltip(id="default_tooltip_auto"):
4+
ui.input_action_button("btn", "A button", class_="mt-3")
5+
"An auto message"
6+
7+
ui.br()
8+
ui.br()
9+
10+
with ui.tooltip(id="default_tooltip_top", placement="top"):
11+
ui.input_action_button("btn2", "A button", class_="mt-3")
12+
"A top message"
13+
14+
ui.br()
15+
ui.br()
16+
17+
with ui.tooltip(id="default_tooltip_right", placement="right"):
18+
ui.input_action_button("btn3", "A button", class_="mt-3")
19+
"A right message"
20+
21+
22+
ui.br()
23+
ui.br()
24+
25+
with ui.tooltip(id="default_tooltip_left", placement="left"):
26+
ui.input_action_button("btn4", "A button", class_="mt-3")
27+
"A left message"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from playwright.sync_api import Page
2+
3+
from shiny.playwright import controller
4+
from shiny.run import ShinyAppProc
5+
6+
7+
def test_tooltip_test_kitchen(page: Page, local_app: ShinyAppProc) -> None:
8+
page.goto(local_app.url)
9+
10+
tooltip_auto = controller.Tooltip(page, "default_tooltip_auto")
11+
tooltip_auto.expect_active(False)
12+
tooltip_auto.set(True)
13+
tooltip_auto.expect_active(True)
14+
tooltip_auto.expect_body("An auto message")
15+
tooltip_auto.expect_placement(
16+
"right"
17+
) # since there is no space on the top, it defaults to right
18+
19+
tooltip_top = controller.Tooltip(page, "default_tooltip_top")
20+
tooltip_top.expect_active(False)
21+
tooltip_top.set(True)
22+
tooltip_top.expect_active(True)
23+
tooltip_top.expect_body("A top message")
24+
tooltip_top.expect_placement("top")
25+
26+
tooltip_right = controller.Tooltip(page, "default_tooltip_right")
27+
tooltip_right.expect_active(False)
28+
tooltip_right.set(True)
29+
tooltip_right.expect_active(True)
30+
tooltip_right.expect_body("A right message")
31+
tooltip_right.expect_placement("right")
32+
33+
tooltip_left = controller.Tooltip(page, "default_tooltip_left")
34+
tooltip_left.expect_active(False)
35+
tooltip_left.set(True)
36+
tooltip_left.expect_active(True)
37+
tooltip_left.expect_body("A left message")
38+
tooltip_left.expect_placement("left")

0 commit comments

Comments
 (0)