from GramAddict.core.perception.intent_resolver import IntentResolver
from GramAddict.core.perception.spatial_parser import SpatialNode


def test_intent_resolver_finds_bottom_tab():
    resolver = IntentResolver()

    # A tab at the top
    top_tab = SpatialNode(bounds=(0, 0, 100, 100), content_desc="Explore Tab", clickable=True)
    # A tab at the bottom
    bottom_tab = SpatialNode(bounds=(0, 2200, 100, 2300), content_desc="Explore Tab", clickable=True)

    # Intent resolver should prefer the one that geometrically matches the bottom navigation area
    best_match = resolver.resolve("tap explore tab", [top_tab, bottom_tab])

    assert best_match == bottom_tab


def test_intent_resolver_finds_button_by_text():
    resolver = IntentResolver()

    btn1 = SpatialNode(bounds=(0, 0, 100, 100), text="Follow", clickable=True)
    btn2 = SpatialNode(bounds=(200, 200, 300, 300), text="Message", clickable=True)

    best_match = resolver.resolve("tap follow button", [btn1, btn2])

    assert best_match == btn1


def test_intent_resolver_returns_none_if_no_match():
    resolver = IntentResolver()

    btn = SpatialNode(bounds=(0, 0, 100, 100), text="Like", clickable=True)

    best_match = resolver.resolve("tap follow button", [btn])

    assert best_match is None
