from GramAddict.core.telepathic_engine import TelepathicEngine


def test_media_intent_rejects_grid_containers():
    """
    TDD Test: Reproduces the bug where intents containing "post" but
    targeting specific grid items (like "first image post in profile grid")
    were bypassing the MAX_CONTAINER_AREA guard, allowing massive
    RecyclerView parent containers to be selected.
    """
    engine = TelepathicEngine()
    screen_height = 2400

    # Mock node representing a massive RecyclerView containing the entire grid
    # Area is 1080 * 2400 = 2592000 > MAX_CONTAINER_AREA (500000)
    massive_grid_container = {
        "semantic_string": "id context: 'swipeable nav view pager inner recycler view'",
        "area": 2592000,
        "y": 1200,
        "class_name": "androidx.recyclerview.widget.RecyclerView",
        "resource_id": "com.instagram.android:id/swipeable_nav_view_pager_inner_recycler_view",
    }

    # Intent
    intent = "first image post in profile grid"

    # Expected behavior: Structural sanity check must REJECT this node because
    # although it's a "post" intent, it is specifically looking for an item within a grid/list,
    # meaning we should NOT click massive screen-sized containers.
    is_valid = engine._structural_sanity_check(massive_grid_container, intent, screen_height)

    assert (
        is_valid is False
    ), "Structural Guard failed to reject massive Grid Container when specifically looking for a grid item."
