test_markdown.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import pytest
  2. import reflex as rx
  3. from reflex.components.markdown import Markdown
  4. @pytest.mark.parametrize(
  5. "tag,expected",
  6. [
  7. ("h1", "Heading"),
  8. ("h2", "Heading"),
  9. ("h3", "Heading"),
  10. ("h4", "Heading"),
  11. ("h5", "Heading"),
  12. ("h6", "Heading"),
  13. ("p", "Text"),
  14. ("ul", "ul"),
  15. ("ol", "ol"),
  16. ("li", "li"),
  17. ("a", "Link"),
  18. ("code", "Code"),
  19. ],
  20. )
  21. def test_get_component(tag, expected):
  22. """Test getting a component from the component map.
  23. Args:
  24. tag: The tag to get.
  25. expected: The expected component.
  26. """
  27. md = Markdown.create("# Hello")
  28. assert tag in md.component_map # pyright: ignore [reportAttributeAccessIssue]
  29. assert md.get_component(tag).tag == expected
  30. def test_set_component_map():
  31. """Test setting the component map."""
  32. component_map = {
  33. "h1": lambda value: rx.box(rx.heading(value, as_="h1"), padding="1em"),
  34. "p": lambda value: rx.box(rx.text(value), padding="1em"),
  35. }
  36. md = Markdown.create("# Hello", component_map=component_map)
  37. # Check that the new tags have been added.
  38. assert md.get_component("h1").tag == "Box"
  39. assert md.get_component("p").tag == "Box"
  40. # Make sure the old tags are still there.
  41. assert md.get_component("h2").tag == "Heading"