test_editable.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import reflex as rx
  2. class S(rx.State):
  3. """Example state for debounce tests."""
  4. value: str = ""
  5. def on_change(self, v: str):
  6. """Dummy on_change handler.
  7. Args:
  8. v: The changed value.
  9. """
  10. pass
  11. def test_full_control_implicit_debounce_editable():
  12. """DebounceInput is used when value and on_change are used together."""
  13. tag = rx.editable(
  14. value=S.value,
  15. on_change=S.on_change,
  16. )._render()
  17. assert tag.props["debounceTimeout"].name == "50"
  18. assert len(tag.props["onChange"].events) == 1
  19. assert tag.props["onChange"].events[0].handler == S.on_change
  20. assert tag.contents == ""
  21. def test_full_control_explicit_debounce_editable():
  22. """DebounceInput is used when user specifies `debounce_timeout`."""
  23. tag = rx.editable(
  24. on_change=S.on_change,
  25. debounce_timeout=33,
  26. )._render()
  27. assert tag.props["debounceTimeout"].name == "33"
  28. assert len(tag.props["onChange"].events) == 1
  29. assert tag.props["onChange"].events[0].handler == S.on_change
  30. assert tag.contents == ""
  31. def test_editable_no_debounce():
  32. """DebounceInput is not used for regular editable."""
  33. tag = rx.editable(
  34. placeholder=S.value,
  35. )._render()
  36. assert "debounceTimeout" not in tag.props
  37. assert tag.contents == ""