import xml.etree.ElementTree as ET

import pytest

from GramAddict.core.sensors.honeypot_radome import HoneypotRadome


@pytest.fixture
def radome():
    # Provide dummy screen dimensions for the Radome
    return HoneypotRadome(display_width=1080, display_height=2400)


def create_node(bounds: str, clickable="true", visible_to_user="true", text="", cdesc="", res_id="") -> ET.Element:
    node = ET.Element(
        "node",
        {
            "bounds": bounds,
            "clickable": clickable,
            "visible-to-user": visible_to_user,
            "text": text,
            "content-desc": cdesc,
            "resource-id": res_id,
        },
    )
    return node


def test_zero_point_trap(radome):
    node = create_node("[0,0][0,0]")
    assert radome._is_honeypot(node) is True


def test_micro_pixel_trap(radome):
    node = create_node("[100,100][101,101]", clickable="true")
    assert radome._is_honeypot(node) is True


def test_safe_normal_button(radome):
    node = create_node("[500,500][600,600]", text="Like", clickable="true")
    assert radome._is_honeypot(node) is False


def test_transparent_interceptor_trap(radome):
    # A full screen clickable node with NO text/id/desc is a trap!
    node = create_node("[0,0][1080,2400]", text="", cdesc="", res_id="", clickable="true")
    assert radome._is_honeypot(node) is True

    # If it has text (e.g. a legit full screen modal), it's NOT flagged by this specific trap rule
    safe_modal = create_node("[0,0][1080,2400]", text="Warning", clickable="true")
    assert radome._is_honeypot(safe_modal) is False


def test_accessibility_trap(radome):
    # Visible-to-user is false but it is clickable
    node = create_node("[100,100][300,300]", visible_to_user="false", clickable="true")
    assert radome._is_honeypot(node) is True
