# SPDX-License-Identifier: MIT # Copyright (c) 2026 Rug Munch Media LLC # # Part of Pry — https://git.rugmunch.io/RugMunchMedia/pryscraper # Licensed under MIT. See LICENSE. """Tests for shadow DOM flattening.""" from shadow_dom import ShadowDOMProcessor, flatten_shadow_dom, has_shadow_dom def test_has_shadow_dom_detected() -> None: html = '' assert has_shadow_dom(html) is True def test_has_shadow_dom_not_detected() -> None: html = "

Regular content

" assert has_shadow_dom(html) is False def test_flatten_shadow_dom_open() -> None: html = '
' result = flatten_shadow_dom(html) assert "template" not in result assert "Shadow content" in result def test_flatten_shadow_dom_closed() -> None: html = '
' result = flatten_shadow_dom(html) assert "template" not in result assert "Hidden" in result def test_flatten_shadow_dom_declarative_mode() -> None: html = '
' result = flatten_shadow_dom(html) assert "template" not in result assert "Declarative" in result def test_processor_regular_html() -> None: processor = ShadowDOMProcessor() html = "

Hello

" result = processor.process(html) assert result == html def test_processor_with_shadow() -> None: processor = ShadowDOMProcessor() html = '' result = processor.process(html) assert "In shadow" in result assert "template" not in result def test_has_shadow_dom_attach_shadow() -> None: html = "" assert has_shadow_dom(html) is True def test_has_shadow_dom_shadowroot_string() -> None: html = "" assert has_shadow_dom(html) is True