import unittest

from leafnode import LeafNode
from textnode import TextNode, TextType, text_node_to_html_node


class TestTextNode(unittest.TestCase):
    def test_eq(self):
        node = TextNode("This is a text node", TextType.BOLD)
        node2 = TextNode("This is a text node", TextType.BOLD)
        self.assertEqual(node, node2)

    def test_eq_when_type_is_different_it_should_not_be_equal(self):
        node = TextNode("This is a text node", TextType.LINK)
        node2 = TextNode("This is a text node", TextType.BOLD)
        self.assertNotEqual(node, node2)

    def test_eq_when_text_is_different_it_should_not_be_equal(self):
        node = TextNode("This is different", TextType.BOLD)
        node2 = TextNode("This is a text node", TextType.BOLD)
        self.assertNotEqual(node, node2)

    def test_eq_when_url_is_different_it_should_not_be_equal(self):
        node = TextNode("This is different", TextType.BOLD, "https://boot.dev")
        node2 = TextNode("This is a text node", TextType.BOLD)
        self.assertNotEqual(node, node2)

    def test_text_node_to_html_node_when_plain_it_should_return_correct_leaf(self):
        plain_text = "plain text"
        expected = LeafNode(None, plain_text)
        node = TextNode(plain_text, TextType.PLAIN)

        result = text_node_to_html_node(node)

        self.assertEqual(result.tag, expected.tag)
        self.assertEqual(result.value, expected.value)

    def test_text_node_to_html_node_when_bold_it_should_return_correct_leaf(self):
        bold_text = "bold text"
        expected = LeafNode("b", bold_text)
        node = TextNode(bold_text, TextType.BOLD)

        result = text_node_to_html_node(node)

        self.assertEqual(result.tag, expected.tag)
        self.assertEqual(result.value, expected.value)

    def test_text_node_to_html_node_when_italics_it_should_return_correct_leaf(self):
        italic_text = "italic text"
        expected = LeafNode("i", italic_text)
        node = TextNode(italic_text, TextType.ITALIC)

        result = text_node_to_html_node(node)

        self.assertEqual(result.tag, expected.tag)
        self.assertEqual(result.value, expected.value)

    def test_text_node_to_html_node_when_code_it_should_return_correct_leaf(self):
        code_text = "var a = b;"
        expected = LeafNode("code", code_text)
        node = TextNode(code_text, TextType.CODE)

        result = text_node_to_html_node(node)

        self.assertEqual(result.tag, expected.tag)
        self.assertEqual(result.value, expected.value)

    def test_text_node_to_html_node_when_link_it_should_return_correct_leaf(self):
        link_text = "click here"
        link_url = "https://stevanfreeborn.com"
        link_props = {"href": link_url}
        expected = LeafNode("a", link_text, link_props)
        node = TextNode(link_text, TextType.LINK, link_url)

        result = text_node_to_html_node(node)

        self.assertEqual(result.tag, expected.tag)
        self.assertEqual(result.value, expected.value)
        self.assertEqual(result.props, expected.props)

    def test_text_node_to_html_node_when_image_it_should_return_correct_leaf(self):
        image_alt_txt = "click here"
        image_url = "https://stevanfreeborn.com/image.png"
        image_props = {"src": image_url, "alt": image_alt_txt}
        expected = LeafNode("img", "", image_props)
        node = TextNode(image_alt_txt, TextType.IMAGE, image_url)

        result = text_node_to_html_node(node)

        self.assertEqual(result.tag, expected.tag)
        self.assertEqual(result.value, expected.value)
        self.assertEqual(result.props, expected.props)


if __name__ == "__main__":
    unittest.main()
