Skip to content

Commit 29c1752

Browse files
authored
Wrap bare value box value in p tag (#668)
1 parent 72eb5e4 commit 29c1752

File tree

5 files changed

+59
-19
lines changed

5 files changed

+59
-19
lines changed

CHANGELOG.md

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

1515
### Bug fixes
1616

17+
Fixes #646: Wrap bare value box value in `<p />` tags. (#668)
18+
1719
### Other changes
1820

1921

e2e/controls.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,6 @@ def expect_full_screen(
24452445

24462446
class ValueBox(
24472447
_WidthLocM,
2448-
_CardBodyM,
24492448
_CardFullScreenM,
24502449
_InputWithContainer,
24512450
):
@@ -2469,14 +2468,14 @@ def __init__(self, page: Page, id: str) -> None:
24692468
loc="> div > .value-box-grid",
24702469
)
24712470
value_box_grid = self.loc
2472-
self.loc = value_box_grid.locator(
2473-
"> div > .value-box-area > :not(:first-child)"
2474-
)
24752471
self.loc_showcase = value_box_grid.locator("> div > .value-box-showcase")
24762472
self.loc_title = value_box_grid.locator(
2477-
"> div > .value-box-area > :first-child"
2473+
"> div > .value-box-area > :nth-child(1)"
2474+
)
2475+
self.loc = value_box_grid.locator("> div > .value-box-area > :nth-child(2)")
2476+
self.loc_body = value_box_grid.locator(
2477+
"> div > .value-box-area > :not(:nth-child(1), :nth-child(2))"
24782478
)
2479-
self.loc_body = self.loc
24802479
self._loc_fullscreen = self.loc_container.locator(
24812480
"> bslib-tooltip > .bslib-full-screen-enter"
24822481
)
@@ -2505,6 +2504,29 @@ def expect_title(
25052504
timeout=timeout,
25062505
)
25072506

2507+
def expect_value(
2508+
self,
2509+
text: PatternOrStr,
2510+
*,
2511+
timeout: Timeout = None,
2512+
) -> None:
2513+
playwright_expect(self.loc).to_have_text(
2514+
text,
2515+
timeout=timeout,
2516+
)
2517+
2518+
def expect_body(
2519+
self,
2520+
text: PatternOrStr | list[PatternOrStr],
2521+
*,
2522+
timeout: Timeout = None,
2523+
) -> None:
2524+
"""Note: If testing against multiple elements, text should be an array"""
2525+
playwright_expect(self.loc_body).to_have_text(
2526+
text,
2527+
timeout=timeout,
2528+
)
2529+
25082530
# hard to test since it can be customized by user
25092531
# def expect_showcase_layout(self, layout, *, timeout: Timeout = None) -> None:
25102532
# raise NotImplementedError()

e2e/experimental/value_box/app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
id="valuebox1",
2323
),
2424
x.ui.value_box(
25-
"KPI Title",
26-
ui.h1(ui.HTML("$1 <i>Billion</i> Dollars")),
27-
ui.span(arrow_up, " 30% VS PREVIOUS 30 DAYS"),
25+
"title",
26+
"value",
27+
ui.p("content"),
28+
ui.p("more body"),
2829
showcase=piggy_bank,
2930
class_="bg-success",
3031
full_screen=True,

e2e/experimental/value_box/test_valuebox.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,27 @@
88
def test_valuebox(page: Page, local_app: ShinyAppProc, value_box_id: str) -> None:
99
page.goto(local_app.url)
1010

11-
value_box = ValueBox(page, value_box_id)
12-
value_box.expect_height(None)
13-
value_box.expect_title("KPI Title")
14-
value_box.expect_full_screen(False)
15-
value_box.open_full_screen()
16-
value_box.expect_full_screen(True)
17-
value_box.expect_body(["$1 Billion Dollars", "30% VS PREVIOUS 30 DAYS"])
18-
value_box.close_full_screen()
19-
value_box.expect_full_screen(False)
11+
value_box1 = ValueBox(page, "valuebox1")
12+
value_box1.expect_height(None)
13+
value_box1.expect_title("KPI Title")
14+
value_box1.expect_value("$1 Billion Dollars")
15+
value_box1.expect_full_screen(False)
16+
value_box1.open_full_screen()
17+
value_box1.expect_full_screen(True)
18+
value_box1.expect_body(["30% VS PREVIOUS 30 DAYS"])
19+
value_box1.close_full_screen()
20+
value_box1.expect_full_screen(False)
21+
22+
value_box2 = ValueBox(page, "valuebox2")
23+
value_box2.expect_height(None)
24+
value_box2.expect_title("title")
25+
value_box2.expect_value("value")
26+
value_box2.expect_full_screen(False)
27+
value_box2.open_full_screen()
28+
value_box2.expect_full_screen(True)
29+
value_box2.expect_body(["content", "more body"])
30+
value_box2.close_full_screen()
31+
value_box2.expect_full_screen(False)
32+
33+
title_tag_name = value_box2.loc_title.evaluate("el => el.tagName.toLowerCase()")
34+
assert title_tag_name == "p"

shiny/experimental/ui/_valuebox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def value_box(
9696
showcase_layout = showcase_left_center()
9797
if isinstance(title, (str, int, float)):
9898
title = tags.p(str(title), class_="h6 mb-1")
99-
if isinstance(title, (str, int, float)):
99+
if isinstance(value, (str, int, float)):
100100
value = tags.p(str(value), class_="h2 mb-2")
101101

102102
contents = div(

0 commit comments

Comments
 (0)