import unittest

from htmlnode import HtmlNode


class TestHtmlNode(unittest.TestCase):
    def test_it_should_not_require_any_properties(self):
        node = HtmlNode()

        self.assertIsNone(node.tag)
        self.assertIsNone(node.value)
        self.assertIsNone(node.children)
        self.assertIsNone(node.props)

    def test_it_should_have_properties(self):
        tag = "tag"
        value = "value"
        children = [HtmlNode()]
        props = {}

        node = HtmlNode(tag, value, children, props)

        self.assertEqual(node.tag, tag)
        self.assertEqual(node.value, value)

        assert node.children is not None
        self.assertListEqual(node.children, children)

        assert node.props is not None
        self.assertDictEqual(node.props, props)

    def test_to_html_when_called_it_should_raise_not_implemented_error(self):
        node = HtmlNode()

        with self.assertRaises(NotImplementedError):
            node.to_html()

    def test_props_to_html_when_called_and_props_none_it_should_return_empty_string(
        self,
    ):
        node = HtmlNode()

        result = node.props_to_html()

        self.assertEqual(result, "")

    def test_props_to_html_when_called_with_props_it_should_return_in_proper_format(
        self,
    ):
        node = HtmlNode(props={"href": "https://www.google.com", "target": "_blank"})

        result = node.props_to_html()

        self.assertEqual(
            result,
            ' href="https://www.google.com" target="_blank"',
        )

    def test_repr_when_called_it_should_return_expected_representation(self):
        tag = "tag"
        value = "value"
        children = [HtmlNode()]
        props = {}

        node = HtmlNode(tag, value, children, props)

        result = repr(node)

        self.assertEqual(
            result, f"{HtmlNode.__name__}({tag}, {value}, {children}, {props})"
        )
