Skip to content

Commit 86d2672

Browse files
committed
add tests for input_date and date_range
1 parent 88ce2e3 commit 86d2672

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

shiny/api-examples/input_date/app-core.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
value="2016-02-29",
2424
datesdisabled=["2016-03-01", "2016-03-02"],
2525
),
26+
# Set min and max dates.
27+
ui.input_date(
28+
"date9", "Date:", value="2016-02-03", min="2016-02-01", max="2016-02-29"
29+
),
30+
# Set width of the date field
31+
ui.input_date("date10", "Date:", width="600px"),
32+
# Set autoclose to false
33+
ui.input_date("date11", "Date:", autoclose=False),
2634
)
2735

2836

shiny/api-examples/input_date_range/app-core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
ui.input_date_range("daterange5", "Date range:", language="de", weekstart=1),
2929
# Start with decade view instead of default month view
3030
ui.input_date_range("daterange6", "Date range:", startview="decade"),
31+
# Set width of the daterange field
32+
ui.input_date_range("daterange7", "Date range:", width="600px"),
33+
# Set autoclose to false
34+
ui.input_date_range("daterange8", "Date range:", autoclose=False),
3135
)
3236

3337

shiny/playwright/controller/_input_fields.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ._base import (
1818
Resize,
1919
UiBaseP,
20+
UiWithContainerP,
2021
UiWithLabel,
2122
WidthContainerM,
2223
WidthLocM,
@@ -26,6 +27,30 @@
2627
)
2728

2829

30+
class InputDateWidthM:
31+
"""
32+
A mixin class for input date width.
33+
This mixin class provides methods to expect the width of input date elements.
34+
"""
35+
36+
def expect_width(
37+
self: UiWithContainerP,
38+
value: AttrValue,
39+
*,
40+
timeout: Timeout = None,
41+
) -> None:
42+
"""
43+
Expect the input select to have a specific width.
44+
Parameters
45+
----------
46+
value
47+
The expected width.
48+
timeout
49+
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
50+
"""
51+
_expect_style_to_have_value(self.loc_container, "width", value, timeout=timeout)
52+
53+
2954
class _SetTextM:
3055
def set(self: UiBaseP, value: str, *, timeout: Timeout = None) -> None:
3156
"""
@@ -425,8 +450,8 @@ def expect_autoresize(
425450

426451

427452
class _DateBase(
453+
InputDateWidthM,
428454
_SetTextM,
429-
WidthContainerM,
430455
UiWithLabel,
431456
):
432457

@@ -669,7 +694,7 @@ def __init__(self, page: Page, id: str) -> None:
669694
)
670695

671696

672-
class InputDateRange(WidthContainerM, UiWithLabel):
697+
class InputDateRange(InputDateWidthM, UiWithLabel):
673698
"""Controller for :func:`shiny.ui.input_date_range`."""
674699

675700
loc_separator: Locator
@@ -933,8 +958,6 @@ def expect_separator(
933958
"""
934959
playwright_expect(self.loc_separator).to_have_text(value, timeout=timeout)
935960

936-
# width: Optional[str] = None,
937-
938961
# autoclose: bool = True,
939962
def expect_autoclose(
940963
self,

tests/playwright/shiny/inputs/test_input_date.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def expect_date(
3131
) -> None:
3232
date.expect_value(str(datetime.date.today()) if value == "today" else value)
3333
autoclose_str = "true" if autoclose else "false"
34+
date.expect_label(label)
3435
date.expect_autoclose(autoclose_str)
3536
date.expect_datesdisabled(datesdisabled)
3637
date.expect_daysofweekdisabled(daysofweekdisabled)
@@ -48,7 +49,6 @@ def test_input_date_kitchen(page: Page, app: ShinyAppProc) -> None:
4849

4950
date1 = controller.InputDate(page, "date1")
5051

51-
date1.expect_label("Date:")
5252
expect(date1.loc_label).to_have_text("Date:")
5353

5454
expect_date(date1, "2016-02-29")
@@ -75,3 +75,14 @@ def test_input_date_kitchen(page: Page, app: ShinyAppProc) -> None:
7575
"2016-02-29",
7676
datesdisabled=["2016-03-01", "2016-03-02"],
7777
)
78+
79+
expect_date(
80+
controller.InputDate(page, "date9"),
81+
"2016-02-03",
82+
min_date="2016-02-01",
83+
max_date="2016-02-29",
84+
)
85+
86+
expect_date(controller.InputDate(page, "date10"), width="600px")
87+
88+
expect_date(controller.InputDate(page, "date11"), autoclose=False)

tests/playwright/shiny/inputs/test_input_date_range.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ def expect_date_range(
1818
start_value: str | Literal["today"] = "today",
1919
end_value: str | Literal["today"] = "today",
2020
*,
21-
label: str = "Date:",
21+
label: str = "Date range:",
2222
autoclose: bool = True,
23-
datesdisabled: typing.Optional[list[str]] = None,
24-
daysofweekdisabled: typing.Optional[list[int]] = None,
2523
format: str = "yyyy-mm-dd",
2624
language: str = "en",
2725
max_date: typing.Optional[str] = None,
@@ -34,11 +32,9 @@ def expect_date_range(
3432
start_value = str(datetime.date.today()) if start_value == "today" else start_value
3533
end_value = str(datetime.date.today()) if end_value == "today" else end_value
3634
date.expect_value((start_value, end_value))
35+
date.expect_label(label)
3736
autoclose_str = "true" if autoclose else "false"
3837
date.expect_autoclose(autoclose_str)
39-
# # Not supported in `input_date_range()`
40-
# date.expect_datesdisabled(datesdisabled)
41-
# date.expect_daysofweekdisabled(daysofweekdisabled)
4238
date.expect_format(format)
4339
date.expect_language(language)
4440
date.expect_max_date(max_date)
@@ -88,3 +84,13 @@ def test_input_date_kitchen(page: Page, app: ShinyAppProc) -> None:
8884
controller.InputDateRange(page, "daterange6"),
8985
startview="decade",
9086
)
87+
88+
expect_date_range(
89+
controller.InputDateRange(page, "daterange7"),
90+
width="600px",
91+
)
92+
93+
expect_date_range(
94+
controller.InputDateRange(page, "daterange8"),
95+
autoclose=False,
96+
)

0 commit comments

Comments
 (0)