refactor: make less messy
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import unittest
|
||||
|
||||
from src.nodes.leaf import LeafNode
|
||||
|
||||
|
||||
class LeafNodeTest(unittest.TestCase):
|
||||
def test_to_html_when_leaf_no_value_it_should_raise_value_error(self):
|
||||
node = LeafNode("p", None)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
node.to_html()
|
||||
|
||||
def test_to_html_when_no_tag_it_should_return_value(self):
|
||||
expected = "Hello Chat"
|
||||
node = LeafNode(None, expected)
|
||||
|
||||
result = node.to_html()
|
||||
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_to_html_when_tag_and_value_it_should_return_html_tag(self):
|
||||
tag = "h1"
|
||||
value = "Hello Chat"
|
||||
expected = f"<{tag}>{value}</{tag}>"
|
||||
|
||||
node = LeafNode(None, expected)
|
||||
|
||||
result = node.to_html()
|
||||
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_repr_when_called_it_should_return_expected_representation(self):
|
||||
tag = "tag"
|
||||
value = "value"
|
||||
props = {}
|
||||
|
||||
node = LeafNode(tag, value, props)
|
||||
|
||||
result = repr(node)
|
||||
|
||||
self.assertEqual(result, f"{LeafNode.__name__}({tag}, {value}, {props})")
|
||||
Reference in New Issue
Block a user