Skip to content

Commit 5be9d98

Browse files
committed
Tests for datepicker
1 parent 36a70d0 commit 5be9d98

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

tests/playwright/shiny/components/datepicker/app.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
value=None,
4949
min=None,
5050
max=None,
51-
format="dd-mm-yyyy",
51+
format="yyyy-mm-dd",
5252
language="en",
5353
),
5454
ui.output_text("none_format"),
@@ -68,23 +68,23 @@
6868
def server(input: Inputs, output: Outputs, session: Session):
6969
@render.text
7070
def start():
71-
return "Start Date Picker Value: " + str(input.start_date_picker())
71+
return "Date Picker Value: " + str(input.start_date_picker())
7272

7373
@render.text
7474
def min():
75-
return "Min Date Picker Value: " + str(input.min_date_picker())
75+
return "Date Picker Value: " + str(input.min_date_picker())
7676

7777
@render.text
7878
def str_format():
79-
return "String Date Picker Value: " + str(input.str_date_picker())
79+
return "Date Picker Value: " + str(input.str_date_picker())
8080

8181
@render.text
8282
def none_format():
83-
return "None Date Picker Value: " + str(input.none_date_picker())
83+
return "Date Picker Value: " + str(input.none_date_picker())
8484

8585
@render.text
8686
def empty_format():
87-
return "Empty Date Picker Value: " + str(input.empty_date_picker())
87+
return "Date Picker Value: " + str(input.empty_date_picker())
8888

8989

9090
app = App(ui, server, debug=True)

tests/playwright/shiny/components/datepicker/test_datepicker.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from shiny.playwright import controller
44
from shiny.run import ShinyAppProc
5+
import datetime
56

67

78
def test_dynamic_navs(page: Page, local_app: ShinyAppProc) -> None:
@@ -10,3 +11,40 @@ def test_dynamic_navs(page: Page, local_app: ShinyAppProc) -> None:
1011
# Check the initial state of the date picker where value = max
1112
date1 = controller.InputDate(page, "start_date_picker")
1213
date1.expect_value("14.11.2011")
14+
15+
# Can't find a way to inspect the actual display date in the datepicker,
16+
# as even in the broken example, the correct attribute was still set.
17+
# To work around this, we will check the displayed value to ensure the
18+
# correct value is being passed to the server.
19+
date_output = controller.OutputText(page, "start")
20+
date_output.expect_value("Date Picker Value: 2011-11-14")
21+
22+
# Test the date picker with the min date = initial value (unchanged case)
23+
date2 = controller.InputDate(page, "min_date_picker")
24+
date2.expect_value("04.11.2011")
25+
26+
date_output2 = controller.OutputText(page, "min")
27+
date_output2.expect_value("Date Picker Value: 2011-11-04")
28+
29+
# Test the date picker with the date set as a string instead of as a date object
30+
date3 = controller.InputDate(page, "str_date_picker")
31+
date3.expect_value("01-10-2023")
32+
33+
date_output3 = controller.OutputText(page, "str_format")
34+
date_output3.expect_value("Date Picker Value: 2023-10-01")
35+
36+
# Test the date picker with a None value inputted
37+
# None defaults to today's date
38+
input = datetime.date.today().strftime("%Y-%m-%d")
39+
date4 = controller.InputDate(page, "none_date_picker")
40+
date4.expect_value(input)
41+
42+
date_output4 = controller.OutputText(page, "none_format")
43+
date_output4.expect_value("Date Picker Value: " + input)
44+
45+
# Test the default value when an empty string is passed is correctly blank
46+
date5 = controller.InputDate(page, "empty_date_picker")
47+
date5.expect_value("")
48+
49+
date_output5 = controller.OutputText(page, "empty_format")
50+
date_output5.expect_value("Date Picker Value: None")

0 commit comments

Comments
 (0)