reflex/tests/units/components/typography/test_markdown.py
Thomas Brandého 3f538865b5
reorganize all tests in a single top folder (#3981)
* lift node version restraint to allow more recent version if already installed

* add node test for latest version

* change python version

* use purple for debug logs

* update workflow

* add playwright dev dependency

* update workflow

* change test

* oops

* improve test

* update test

* fix tests

* mv units tests to a subfolder

* reorganize tests

* fix install

* update test_state

* revert node changes and only keep new tests organization

* move integration tests in tests/integration

* fix integration workflow

* fix dockerfile workflow

* fix dockerfile workflow 2

* fix shared_state
2024-09-26 01:22:52 +02:00

50 lines
1.4 KiB
Python

import pytest
import reflex as rx
from reflex.components.markdown import Markdown
@pytest.mark.parametrize(
"tag,expected",
[
("h1", "Heading"),
("h2", "Heading"),
("h3", "Heading"),
("h4", "Heading"),
("h5", "Heading"),
("h6", "Heading"),
("p", "Text"),
("ul", "ul"),
("ol", "ol"),
("li", "li"),
("a", "Link"),
("code", "Code"),
],
)
def test_get_component(tag, expected):
"""Test getting a component from the component map.
Args:
tag: The tag to get.
expected: The expected component.
"""
md = Markdown.create("# Hello")
assert tag in md.component_map # type: ignore
assert md.get_component(tag).tag == expected # type: ignore
def test_set_component_map():
"""Test setting the component map."""
component_map = {
"h1": lambda value: rx.box(rx.heading(value, as_="h1"), padding="1em"),
"p": lambda value: rx.box(rx.text(value), padding="1em"),
}
md = Markdown.create("# Hello", component_map=component_map)
# Check that the new tags have been added.
assert md.get_component("h1").tag == "Box" # type: ignore
assert md.get_component("p").tag == "Box" # type: ignore
# Make sure the old tags are still there.
assert md.get_component("h2").tag == "Heading" # type: ignore