Skip to content

Commit

Permalink
fix props
Browse files Browse the repository at this point in the history
  • Loading branch information
jnumainville committed Apr 10, 2024
1 parent d2086b6 commit c6c2951
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/ui/src/deephaven/ui/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def create_props(args: dict[str, Any]) -> tuple[tuple[Any], dict[str, Any]]:
Returns:
A tuple of children and props
"""
children, props = args.pop("children"), args.pop("props")
children, props = args.pop("children", tuple()), args.pop("props", {})
props.update(args)
return children, props

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Literal

PageBehavior = Literal["single", "visible"]
HourCycle = Literal[12, 24]
ValidationBehavior = Literal["aria", "native"]
Alignment = Literal["start", "end"]
NecessityIndicator = Literal["label", "icon"]
ValidationState = Literal["valid", "invalid"]
79 changes: 79 additions & 0 deletions plugins/ui/test/deephaven/ui/test_date_picker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import unittest

from .BaseTest import BaseTestCase


class DatePickerTest(BaseTestCase):
def test_convert_date_props(self):
from deephaven.time import to_j_instant, to_j_zdt, to_j_local_date
from deephaven.ui.components.date_picker import _convert_date_picker_props
from deephaven.ui._internal.utils import get_jclass_name

def verify_is_local_date(date):
self.assertEqual(get_jclass_name(date), "java.time.LocalDate")

def verify_is_instant(date):
self.assertEqual(get_jclass_name(date), "java.time.Instant")

def verify_is_zdt(date):
self.assertEqual(get_jclass_name(date), "java.time.ZonedDateTime")

def empty_on_change():
pass

props1 = {
"placeholder_value": "2021-01-01",
"value": "2021-01-01 UTC",
"default_value": "2021-01-01 ET",
"unavailable_dates": [to_j_instant("2021-01-01 UTC")],
"min_value": to_j_zdt("2021-01-01 ET"),
"max_value": to_j_local_date("2021-01-01"),
}

props2 = {
"value": to_j_local_date("2021-01-01"),
"default_value": to_j_zdt("2021-01-01 ET"),
"placeholder_value": to_j_instant("2021-01-01 UTC"),
"on_change": verify_is_local_date,
}

props3 = {
"default_value": to_j_instant("2021-01-01 UTC"),
"placeholder_value": to_j_zdt("2021-01-01 ET"),
"on_change": verify_is_instant,
}

props4 = {
"placeholder_value": to_j_zdt("2021-01-01 ET"),
"on_change": verify_is_zdt,
}

props5 = {"on_change": verify_is_instant}

props6 = {"on_change": empty_on_change}

_convert_date_picker_props(props1)
_convert_date_picker_props(props2)
_convert_date_picker_props(props3)
_convert_date_picker_props(props4)
_convert_date_picker_props(props5)
_convert_date_picker_props(props6)

verify_is_local_date(props1["max_value"])
verify_is_zdt(props1["min_value"])
verify_is_instant(props1["unavailable_dates"][0])
verify_is_instant(props1["value"])
verify_is_instant(props1["default_value"])
verify_is_local_date(props1["placeholder_value"])

props2["on_change"]("2021-01-01")
props3["on_change"]("2021-01-01 UTC")
props4["on_change"]("2021-01-01 ET")
props5["on_change"]("2021-01-01 UTC")

# pass an Instant but it should be dropped with no error
props6["on_change"]("2021-01-01 UTC")


if __name__ == "__main__":
unittest.main()
44 changes: 44 additions & 0 deletions plugins/ui/test/deephaven/ui/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,50 @@ def test_func_with_all_args(a, /, b, *args, c=1, **kwargs):
# Test that wrapping a function without a signature doesn't throw an error
wrapped = wrap_callable(print)

def test_create_props(self):
from deephaven.ui._internal.utils import create_props

children1, props1 = create_props(
{
"foo": "bar",
"baz": 42,
"fizz": "buzz",
}
)

self.assertEqual(children1, tuple())
self.assertDictEqual(
props1,
{
"foo": "bar",
"baz": 42,
"fizz": "buzz",
},
)

children2, props2 = create_props(
{
"children": ["item1", "item2"],
"test": "value",
"props": {
"foo": "bar",
"baz": 42,
"fizz": "buzz",
},
}
)

self.assertEqual(children2, ["item1", "item2"])
self.assertDictEqual(
props2,
{
"foo": "bar",
"baz": 42,
"fizz": "buzz",
"test": "value",
},
)


if __name__ == "__main__":
unittest.main()

0 comments on commit c6c2951

Please sign in to comment.