from GramAddict.core.perception.screen_identity import ScreenIdentity, ScreenType


def test_gallery_screen_is_modal():
    """
    Test that the Gallery/New Post screen is correctly identified as a MODAL,
    preventing it from being hallucinated as POST_DETAIL or HOME_FEED.
    """
    xml_dump = """<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<hierarchy rotation="0">
  <node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.instagram.android" bounds="[0,0][1080,2400]">
    <node index="0" text="New post" resource-id="" class="android.widget.TextView" bounds="[0,0][100,100]" />
    <node index="1" text="" resource-id="com.instagram.android:id/gallery_grid_item_thumbnail" class="android.widget.Button" content-desc="Selected media number 1 Photo thumbnail created on 3 May 2026 10:30" bounds="[0,100][500,600]" />
    <node index="2" text="" resource-id="com.instagram.android:id/next_button_textview" class="android.widget.Button" content-desc="Next" bounds="[900,0][1080,100]" />
  </node>
</hierarchy>
"""
    identity = ScreenIdentity("bot_user")
    result = identity.identify(xml_dump)

    assert result["screen_type"] == ScreenType.MODAL


def test_camera_screen_is_modal():
    """
    Test that the Camera creation screen is correctly identified as a MODAL.
    """
    xml_dump = """<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<hierarchy rotation="0">
  <node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.instagram.android" bounds="[0,0][1080,2400]">
    <node index="0" text="" resource-id="com.instagram.android:id/camera_cancel_button" class="android.widget.ImageView" bounds="[0,0][100,100]" />
    <node index="1" text="" resource-id="com.instagram.android:id/quick_capture" class="android.widget.FrameLayout" bounds="[0,100][1080,2400]" />
  </node>
</hierarchy>
"""
    identity = ScreenIdentity("bot_user")
    result = identity.identify(xml_dump)

    assert result["screen_type"] == ScreenType.MODAL
