from ploneintranet.workspace import html_cleaners
from ploneintranet.workspace.tests.base import BaseTestCase


class TestHTMLCleaners(BaseTestCase):
    def test_allow_iframes_youtube(self):
        text_input = """<p><iframe src="https://www.youtube.com/watch?v=GO1mRJkGXTA"></iframe></p>"""  # noqa: E501
        self.assertEqual(html_cleaners.sanitize_html(text_input), text_input)

    def test_wraps_iframes_in_paragraphs(self):
        # NOTE: Maybe this behavior should be changed.
        text_input = (
            """<iframe src="https://www.youtube.com/watch?v=GO1mRJkGXTA"></iframe>"""
        )
        self.assertEqual(
            html_cleaners.sanitize_html(text_input), f"<p>{text_input}</p>"
        )

    def test_allow_iframes_vimeo(self):
        text_input = """<p><iframe src="https://vimeo.com/14646739"></iframe></p>"""
        self.assertEqual(html_cleaners.sanitize_html(text_input), text_input)

    def test_disallow_other_iframe_urls(self):
        text_input = """<p><iframe src="https://example.com"></iframe></p>"""
        self.assertEqual(html_cleaners.sanitize_html(text_input), "")
