test_markdown.py 1.4 KB

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