Skip to content

Commit 91a56cb

Browse files
authored
tests(input_date): add tests for input_date and date_range (#1696)
1 parent 4f5b666 commit 91a56cb

File tree

11 files changed

+165
-59
lines changed

11 files changed

+165
-59
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535

3636
* `ui.Theme()` now works correctly on Windows when the theme requires Sass compilation. (thanks @yuuuxt, #1684)
3737

38-
* Fixed the `InputSlider` controller's `.expect_width()` to check the `width` property within the `style` attribute. (#1691)
38+
* Fixed the `InputSlider` playwright controller's `.expect_width()` to check the `width` property within the `style` attribute. (#1691)
39+
40+
* Fixed the `InputDate` and `InputDateRange` playwright controllers to check the `width` property within the `style` attribute. (#1696)
3941

4042
## [1.1.0] - 2024-09-03
4143

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,43 @@
33
from shiny import App, Inputs, Outputs, Session, ui
44

55
app_ui = ui.page_fluid(
6-
ui.input_date("date1", "Date:", value="2016-02-29"),
6+
ui.input_date("date1", "Has default date:", value="2016-02-29"),
77
# Default value is the date in client's time zone
8-
ui.input_date("date2", "Date:"),
8+
ui.input_date("date2", "Client's current date:"),
99
# value is always yyyy-mm-dd, even if the display format is different
10-
ui.input_date("date3", "Date:", value="2016-02-29", format="mm/dd/yy"),
10+
ui.input_date("date3", "Format mm/dd/yy:", value="2016-02-29", format="mm/dd/yy"),
1111
# Pass in a Date object
12-
ui.input_date("date4", "Date:", value=date(2016, 2, 29)),
12+
ui.input_date("date4", "Default uses date object:", value=date(2016, 2, 29)),
1313
# Use different language and different first day of week
14-
ui.input_date("date5", "Date:", language="ru", weekstart=1),
14+
ui.input_date(
15+
"date5",
16+
"Language is German and the week starts on Monday:",
17+
language="ru",
18+
weekstart=1,
19+
),
1520
# Start with decade view instead of default month view
16-
ui.input_date("date6", "Date:", startview="decade"),
21+
ui.input_date("date6", "Start Date picker in Decade view:", startview="decade"),
1722
# Disable Mondays and Tuesdays.
18-
ui.input_date("date7", "Date:", daysofweekdisabled=[1, 2]),
23+
ui.input_date("date7", "Disable Monday and Tuesday:", daysofweekdisabled=[1, 2]),
1924
# Disable specific dates.
2025
ui.input_date(
2126
"date8",
22-
"Date:",
27+
"Disable specific dates:",
2328
value="2016-02-29",
2429
datesdisabled=["2016-03-01", "2016-03-02"],
2530
),
31+
# Set min and max dates.
32+
ui.input_date(
33+
"date9",
34+
"Set min and max dates:",
35+
value="2016-02-03",
36+
min="2016-02-01",
37+
max="2016-02-29",
38+
),
39+
# Set width of the date field
40+
ui.input_date("date10", "Set width of text input:", width="600px"),
41+
# Set autoclose to false
42+
ui.input_date("date11", "Auto close is disabled:", autoclose=False),
2643
)
2744

2845

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,40 @@
22

33
from shiny.express import ui
44

5-
ui.input_date("date1", "Date:", value="2016-02-29")
5+
ui.input_date("date1", "Has default date:", value="2016-02-29")
66
# Default value is the date in client's time zone
7-
ui.input_date("date2", "Date:")
7+
ui.input_date("date2", "Client's current date:")
88
# value is always yyyy-mm-dd, even if the display format is different
9-
ui.input_date("date3", "Date:", value="2016-02-29", format="mm/dd/yy")
9+
ui.input_date("date3", "Format mm/dd/yy:", value="2016-02-29", format="mm/dd/yy")
1010
# Pass in a Date object
11-
ui.input_date("date4", "Date:", value=date(2016, 2, 29))
11+
ui.input_date("date4", "Default uses date object:", value=date(2016, 2, 29))
1212
# Use different language and different first day of week
13-
ui.input_date("date5", "Date:", language="ru", weekstart=1)
13+
ui.input_date(
14+
"date5",
15+
"Language is German and the week starts on Monday:",
16+
language="ru",
17+
weekstart=1,
18+
)
1419
# Start with decade view instead of default month view
15-
ui.input_date("date6", "Date:", startview="decade")
20+
ui.input_date("date6", "Start Date picker in Decade view:", startview="decade")
1621
# Disable Mondays and Tuesdays.
17-
ui.input_date("date7", "Date:", daysofweekdisabled=[1, 2])
22+
ui.input_date("date7", "Disable Monday and Tuesday:", daysofweekdisabled=[1, 2])
1823
# Disable specific dates.
1924
ui.input_date(
2025
"date8",
21-
"Date:",
26+
"Disable specific dates:",
2227
value="2016-02-29",
2328
datesdisabled=["2016-03-01", "2016-03-02"],
2429
)
30+
# Set min and max dates.
31+
ui.input_date(
32+
"date9",
33+
"Set min and max dates:",
34+
value="2016-02-03",
35+
min="2016-02-01",
36+
max="2016-02-29",
37+
)
38+
# Set width of the date field
39+
ui.input_date("date10", "Set width of text input:", width="600px")
40+
# Set autoclose to false
41+
ui.input_date("date11", "Auto close is disabled:", autoclose=False)

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
from shiny import App, Inputs, Outputs, Session, ui
44

55
app_ui = ui.page_fluid(
6+
# Default start and end is the current date in the client's time zone
7+
ui.input_date_range("daterange1", "Date range:"),
8+
# Set start and end dates
69
ui.input_date_range(
7-
"daterange1", "Date range:", start="2001-01-01", end="2010-12-31"
10+
"daterange2", "Set start and end date:", start="2001-01-01", end="2010-12-31"
811
),
9-
# Default start and end is the current date in the client's time zone
10-
ui.input_date_range("daterange2", "Date range:"),
11-
# start and end are always specified in yyyy-mm-dd, even if the display
12+
# Start and end are always specified in yyyy-mm-dd, even if the display
1213
# format is different
1314
ui.input_date_range(
1415
"daterange3",
15-
"Date range:",
16+
"Min, max, start, and end dates are set with custom format and separator:",
1617
start="2001-01-01",
1718
end="2010-12-31",
1819
min="2001-01-01",
@@ -22,12 +23,26 @@
2223
),
2324
# Pass in Date objects
2425
ui.input_date_range(
25-
"daterange4", "Date range:", start=date(2001, 1, 1), end=date(2010, 12, 31)
26+
"daterange4",
27+
"Default start and end use date objects:",
28+
start=date(2001, 1, 1),
29+
end=date(2010, 12, 31),
2630
),
2731
# Use different language and different first day of week
28-
ui.input_date_range("daterange5", "Date range:", language="de", weekstart=1),
32+
ui.input_date_range(
33+
"daterange5",
34+
"Language is German and we starts on Monday:",
35+
language="de",
36+
weekstart=1,
37+
),
2938
# Start with decade view instead of default month view
30-
ui.input_date_range("daterange6", "Date range:", startview="decade"),
39+
ui.input_date_range(
40+
"daterange6", "Start Date picker in Decade view:", startview="decade"
41+
),
42+
# Set width of the daterange field
43+
ui.input_date_range("daterange7", "Set width of text input:", width="600px"),
44+
# Set autoclose to false
45+
ui.input_date_range("daterange8", "Auto close is disabled:", autoclose=False),
3146
)
3247

3348

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
from shiny.express import ui
44

5-
ui.input_date_range("daterange1", "Date range:", start="2001-01-01", end="2010-12-31")
65
# Default start and end is the current date in the client's time zone
7-
ui.input_date_range("daterange2", "Date range:")
8-
# start and end are always specified in yyyy-mm-dd, even if the display
6+
ui.input_date_range("daterange1", "Date range:")
7+
# Set start and end dates
8+
ui.input_date_range(
9+
"daterange2", "Set start and end date:", start="2001-01-01", end="2010-12-31"
10+
)
11+
# Start and end are always specified in yyyy-mm-dd, even if the display
912
# format is different
1013
ui.input_date_range(
1114
"daterange3",
12-
"Date range:",
15+
"Min, max, start, and end dates are set with custom format and separator:",
1316
start="2001-01-01",
1417
end="2010-12-31",
1518
min="2001-01-01",
@@ -19,9 +22,23 @@
1922
)
2023
# Pass in Date objects
2124
ui.input_date_range(
22-
"daterange4", "Date range:", start=date(2001, 1, 1), end=date(2010, 12, 31)
25+
"daterange4",
26+
"Default start and end use date objects:",
27+
start=date(2001, 1, 1),
28+
end=date(2010, 12, 31),
2329
)
2430
# Use different language and different first day of week
25-
ui.input_date_range("daterange5", "Date range:", language="de", weekstart=1)
31+
ui.input_date_range(
32+
"daterange5",
33+
"Language is German and we starts on Monday:",
34+
language="de",
35+
weekstart=1,
36+
)
2637
# Start with decade view instead of default month view
27-
ui.input_date_range("daterange6", "Date range:", startview="decade")
38+
ui.input_date_range(
39+
"daterange6", "Start Date picker in Decade view:", startview="decade"
40+
)
41+
# Set width of the daterange field
42+
ui.input_date_range("daterange7", "Set width of text input:", width="600px")
43+
# Set autoclose to false
44+
ui.input_date_range("daterange8", "Auto close is disabled:", autoclose=False)

shiny/playwright/controller/_accordion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def expect_width(self, value: StyleValue, *, timeout: Timeout = None) -> None:
229229
value
230230
The expected width.
231231
timeout
232-
The maximum time to wait for the width to be visible and interactable. Defaults to `None`.
232+
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
233233
"""
234234
_expect_style_to_have_value(self.loc_container, "width", value, timeout=timeout)
235235

shiny/playwright/controller/_input_buttons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def expect_width(self, value: StyleValue, *, timeout: Timeout = None) -> None:
420420
value
421421
The expected value of the width.
422422
timeout
423-
The timeout for the expectation. Defaults to `None`.
423+
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
424424
"""
425425
_expect_style_to_have_value(self.loc_container, "width", value, timeout=timeout)
426426

shiny/playwright/controller/_input_controls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def expect_width(self, value: str, *, timeout: Timeout = None) -> None:
211211
value
212212
The expected width.
213213
timeout
214-
The maximum time to wait for the width to be visible and interactable. Defaults to `None`.
214+
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
215215
"""
216216
_expect_style_to_have_value(self.loc_container, "width", value, timeout=timeout)
217217

shiny/playwright/controller/_input_fields.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,40 @@
1717
from ._base import (
1818
Resize,
1919
UiBaseP,
20+
UiWithContainerP,
2021
UiWithLabel,
21-
WidthContainerM,
2222
WidthLocM,
2323
all_missing,
2424
not_is_missing,
2525
set_text,
2626
)
2727

2828

29+
class InputDateWidthM:
30+
"""
31+
A mixin class for input date width.
32+
This mixin class provides methods to expect the width of input date elements.
33+
"""
34+
35+
def expect_width(
36+
self: UiWithContainerP,
37+
value: AttrValue,
38+
*,
39+
timeout: Timeout = None,
40+
) -> None:
41+
"""
42+
Expect the input select to have a specific width.
43+
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: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Literal
66

77
from conftest import create_doc_example_core_fixture
8-
from playwright.sync_api import Page, expect
8+
from playwright.sync_api import Page
99

1010
from shiny.playwright import controller
1111
from shiny.run import ShinyAppProc
@@ -17,7 +17,6 @@ def expect_date(
1717
date: controller.InputDate,
1818
value: str | Literal["today"] = "today",
1919
*,
20-
label: str = "Date:",
2120
autoclose: bool = True,
2221
datesdisabled: typing.Optional[list[str]] = None,
2322
daysofweekdisabled: typing.Optional[list[int]] = None,
@@ -47,9 +46,7 @@ def test_input_date_kitchen(page: Page, app: ShinyAppProc) -> None:
4746
page.goto(app.url)
4847

4948
date1 = controller.InputDate(page, "date1")
50-
51-
date1.expect_label("Date:")
52-
expect(date1.loc_label).to_have_text("Date:")
49+
date1.expect_label("Has default date:")
5350

5451
expect_date(date1, "2016-02-29")
5552

@@ -75,3 +72,14 @@ def test_input_date_kitchen(page: Page, app: ShinyAppProc) -> None:
7572
"2016-02-29",
7673
datesdisabled=["2016-03-01", "2016-03-02"],
7774
)
75+
76+
expect_date(
77+
controller.InputDate(page, "date9"),
78+
"2016-02-03",
79+
min_date="2016-02-01",
80+
max_date="2016-02-29",
81+
)
82+
83+
expect_date(controller.InputDate(page, "date10"), width="600px")
84+
85+
expect_date(controller.InputDate(page, "date11"), autoclose=False)

0 commit comments

Comments
 (0)