add some unit tests for coverage (#3947)
* add some unit tests for coverage * add test for page decorator * bump coverage threshold * check content
This commit is contained in:
parent
44a89b2e87
commit
cf69964cd6
@ -11,7 +11,7 @@ omit =
|
|||||||
[report]
|
[report]
|
||||||
show_missing = true
|
show_missing = true
|
||||||
# TODO bump back to 79
|
# TODO bump back to 79
|
||||||
fail_under = 60
|
fail_under = 70
|
||||||
precision = 2
|
precision = 2
|
||||||
|
|
||||||
# Regexes for lines to exclude from consideration
|
# Regexes for lines to exclude from consideration
|
||||||
|
@ -167,7 +167,7 @@ class ZAxis(Recharts):
|
|||||||
|
|
||||||
tag = "ZAxis"
|
tag = "ZAxis"
|
||||||
|
|
||||||
alias = "RechartszAxis"
|
alias = "RechartsZAxis"
|
||||||
|
|
||||||
# The key of data displayed in the axis.
|
# The key of data displayed in the axis.
|
||||||
data_key: Var[Union[str, int]]
|
data_key: Var[Union[str, int]]
|
||||||
|
@ -63,15 +63,3 @@ def page(
|
|||||||
return render_fn
|
return render_fn
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def get_decorated_pages() -> list[dict]:
|
|
||||||
"""Get the decorated pages.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The decorated pages.
|
|
||||||
"""
|
|
||||||
return sorted(
|
|
||||||
[page_data for _, page_data in DECORATED_PAGES[get_config().app_name]],
|
|
||||||
key=lambda x: x["route"],
|
|
||||||
)
|
|
||||||
|
15
tests/components/base/test_link.py
Normal file
15
tests/components/base/test_link.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from reflex.components.base.link import RawLink, ScriptTag
|
||||||
|
|
||||||
|
|
||||||
|
def test_raw_link():
|
||||||
|
raw_link = RawLink.create("https://example.com").render()
|
||||||
|
assert raw_link["name"] == "link"
|
||||||
|
assert raw_link["children"][0]["contents"] == '{"https://example.com"}'
|
||||||
|
|
||||||
|
|
||||||
|
def test_script_tag():
|
||||||
|
script_tag = ScriptTag.create("console.log('Hello, world!');").render()
|
||||||
|
assert script_tag["name"] == "script"
|
||||||
|
assert (
|
||||||
|
script_tag["children"][0]["contents"] == "{\"console.log('Hello, world!');\"}"
|
||||||
|
)
|
50
tests/components/recharts/test_cartesian.py
Normal file
50
tests/components/recharts/test_cartesian.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
from reflex.components.recharts import (
|
||||||
|
Area,
|
||||||
|
Bar,
|
||||||
|
Brush,
|
||||||
|
Line,
|
||||||
|
Scatter,
|
||||||
|
XAxis,
|
||||||
|
YAxis,
|
||||||
|
ZAxis,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_xaxis():
|
||||||
|
x_axis = XAxis.create("x").render()
|
||||||
|
assert x_axis["name"] == "RechartsXAxis"
|
||||||
|
|
||||||
|
|
||||||
|
def test_yaxis():
|
||||||
|
x_axis = YAxis.create("y").render()
|
||||||
|
assert x_axis["name"] == "RechartsYAxis"
|
||||||
|
|
||||||
|
|
||||||
|
def test_zaxis():
|
||||||
|
x_axis = ZAxis.create("z").render()
|
||||||
|
assert x_axis["name"] == "RechartsZAxis"
|
||||||
|
|
||||||
|
|
||||||
|
def test_brush():
|
||||||
|
brush = Brush.create().render()
|
||||||
|
assert brush["name"] == "RechartsBrush"
|
||||||
|
|
||||||
|
|
||||||
|
def test_area():
|
||||||
|
area = Area.create().render()
|
||||||
|
assert area["name"] == "RechartsArea"
|
||||||
|
|
||||||
|
|
||||||
|
def test_bar():
|
||||||
|
bar = Bar.create().render()
|
||||||
|
assert bar["name"] == "RechartsBar"
|
||||||
|
|
||||||
|
|
||||||
|
def test_line():
|
||||||
|
line = Line.create().render()
|
||||||
|
assert line["name"] == "RechartsLine"
|
||||||
|
|
||||||
|
|
||||||
|
def test_scatter():
|
||||||
|
scatter = Scatter.create().render()
|
||||||
|
assert scatter["name"] == "RechartsScatter"
|
50
tests/test_page.py
Normal file
50
tests/test_page.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
from reflex import text
|
||||||
|
from reflex.config import get_config
|
||||||
|
from reflex.page import DECORATED_PAGES, page
|
||||||
|
|
||||||
|
|
||||||
|
def test_page_decorator():
|
||||||
|
def foo_():
|
||||||
|
return text("foo")
|
||||||
|
|
||||||
|
assert len(DECORATED_PAGES) == 0
|
||||||
|
decorated_foo_ = page()(foo_)
|
||||||
|
assert decorated_foo_ == foo_
|
||||||
|
assert len(DECORATED_PAGES) == 1
|
||||||
|
page_data = DECORATED_PAGES.get(get_config().app_name, [])[0][1]
|
||||||
|
assert page_data == {}
|
||||||
|
DECORATED_PAGES.clear()
|
||||||
|
|
||||||
|
|
||||||
|
def test_page_decorator_with_kwargs():
|
||||||
|
def foo_():
|
||||||
|
return text("foo")
|
||||||
|
|
||||||
|
def load_foo():
|
||||||
|
return []
|
||||||
|
|
||||||
|
DECORATED_PAGES.clear()
|
||||||
|
assert len(DECORATED_PAGES) == 0
|
||||||
|
decorated_foo_ = page(
|
||||||
|
route="foo",
|
||||||
|
title="Foo",
|
||||||
|
image="foo.png",
|
||||||
|
description="Foo description",
|
||||||
|
meta=["foo-meta"],
|
||||||
|
script_tags=["foo-script"],
|
||||||
|
on_load=load_foo,
|
||||||
|
)(foo_)
|
||||||
|
assert decorated_foo_ == foo_
|
||||||
|
assert len(DECORATED_PAGES) == 1
|
||||||
|
page_data = DECORATED_PAGES.get(get_config().app_name, [])[0][1]
|
||||||
|
assert page_data == {
|
||||||
|
"description": "Foo description",
|
||||||
|
"image": "foo.png",
|
||||||
|
"meta": ["foo-meta"],
|
||||||
|
"on_load": load_foo,
|
||||||
|
"route": "foo",
|
||||||
|
"script_tags": ["foo-script"],
|
||||||
|
"title": "Foo",
|
||||||
|
}
|
||||||
|
|
||||||
|
DECORATED_PAGES.clear()
|
Loading…
Reference in New Issue
Block a user