Add tests for pc.icon
(#562)
This commit is contained in:
parent
12faa76279
commit
f88d4ce4b4
@ -27,6 +27,7 @@ class Icon(ChakraIconComponent):
|
|||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
AttributeError: The errors tied to bad usage of the Icon component.
|
AttributeError: The errors tied to bad usage of the Icon component.
|
||||||
|
ValueError: If the icon tag is invalid.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The created component.
|
The created component.
|
||||||
@ -37,5 +38,71 @@ class Icon(ChakraIconComponent):
|
|||||||
)
|
)
|
||||||
if "tag" not in props.keys():
|
if "tag" not in props.keys():
|
||||||
raise AttributeError("Missing 'tag' keyword-argument for Icon")
|
raise AttributeError("Missing 'tag' keyword-argument for Icon")
|
||||||
|
if props["tag"] not in ICON_LIST:
|
||||||
|
raise ValueError(
|
||||||
|
f"Invalid icon tag: {props['tag']}. Please use one of the following: {ICON_LIST}"
|
||||||
|
)
|
||||||
props["tag"] = utils.to_title_case(props["tag"]) + "Icon"
|
props["tag"] = utils.to_title_case(props["tag"]) + "Icon"
|
||||||
return super().create(*children, **props)
|
return super().create(*children, **props)
|
||||||
|
|
||||||
|
|
||||||
|
# List of all icons.
|
||||||
|
ICON_LIST = [
|
||||||
|
"add",
|
||||||
|
"arrow_back",
|
||||||
|
"arrow_down",
|
||||||
|
"arrow_forward",
|
||||||
|
"arrow_left",
|
||||||
|
"arrow_right",
|
||||||
|
"arrow_up",
|
||||||
|
"arrow_up_down",
|
||||||
|
"at_sign",
|
||||||
|
"attachment",
|
||||||
|
"bell",
|
||||||
|
"calendar",
|
||||||
|
"check_circle",
|
||||||
|
"check",
|
||||||
|
"chevron_down",
|
||||||
|
"chevron_left",
|
||||||
|
"chevron_right",
|
||||||
|
"chevron_up",
|
||||||
|
"close",
|
||||||
|
"copy",
|
||||||
|
"delete",
|
||||||
|
"download",
|
||||||
|
"drag_handle",
|
||||||
|
"edit",
|
||||||
|
"email",
|
||||||
|
"external_link",
|
||||||
|
"hamburger",
|
||||||
|
"info",
|
||||||
|
"info_outline",
|
||||||
|
"link",
|
||||||
|
"lock",
|
||||||
|
"minus",
|
||||||
|
"moon",
|
||||||
|
"not_allowed",
|
||||||
|
"phone",
|
||||||
|
"plus_square",
|
||||||
|
"question",
|
||||||
|
"question_outline",
|
||||||
|
"repeat",
|
||||||
|
"repeat_clock",
|
||||||
|
"search",
|
||||||
|
"search2",
|
||||||
|
"settings",
|
||||||
|
"small_add",
|
||||||
|
"small_close",
|
||||||
|
"spinner",
|
||||||
|
"star",
|
||||||
|
"sun",
|
||||||
|
"time",
|
||||||
|
"triangle_down",
|
||||||
|
"triangle_up",
|
||||||
|
"unlock",
|
||||||
|
"up_down",
|
||||||
|
"view",
|
||||||
|
"view_off",
|
||||||
|
"warning",
|
||||||
|
"warning_two",
|
||||||
|
]
|
||||||
|
1
tests/components/graphing/__init__.py
Normal file
1
tests/components/graphing/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"""Graphing component tests."""
|
1
tests/components/layout/__init__.py
Normal file
1
tests/components/layout/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"""Layout component tests."""
|
1
tests/components/media/__init__.py
Normal file
1
tests/components/media/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"""Media component tests."""
|
41
tests/components/media/test_icon.py
Normal file
41
tests/components/media/test_icon.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from pynecone import utils
|
||||||
|
from pynecone.components.media.icon import ICON_LIST, Icon
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_tag_errors():
|
||||||
|
"""Test that an icon without a tag raises an error."""
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
|
Icon.create()
|
||||||
|
|
||||||
|
|
||||||
|
def test_children_errors():
|
||||||
|
"""Test that an icon with children raises an error."""
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
|
Icon.create("child", tag="search")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"tag",
|
||||||
|
ICON_LIST,
|
||||||
|
)
|
||||||
|
def test_valid_icon(tag: str):
|
||||||
|
"""Test that a valid icon does not raise an error.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
tag: The icon tag.
|
||||||
|
"""
|
||||||
|
icon = Icon.create(tag=tag)
|
||||||
|
assert icon.tag == utils.to_title_case(tag) + "Icon"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("tag", ["", " ", "invalid", 123])
|
||||||
|
def test_invalid_icon(tag):
|
||||||
|
"""Test that an invalid icon raises an error.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
tag: The icon tag.
|
||||||
|
"""
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
Icon.create(tag=tag)
|
Loading…
Reference in New Issue
Block a user