from GramAddict.core.utils import is_ad


def test_is_ad_false_positive_abroad():
    # Simulate an IG node with 'abroad' in the text
    xml_false_positive = """<?xml version="1.0"?>
    <hierarchy>
        <node resource-id="com.instagram.android:id/row_feed_profile_header" text="" content-desc="" />
        <node resource-id="com.instagram.android:id/secondary_label" text="brunette_abroad" content-desc="" />
    </hierarchy>"""

    assert not is_ad(xml_false_positive), "Bot flagged 'abroad' as an AD because it contains 'ad'!"


def test_is_ad_true_positive():
    xml_true_positive = """<?xml version="1.0"?>
    <hierarchy>
        <node resource-id="com.instagram.android:id/row_feed_profile_header" text="" content-desc="" />
        <node resource-id="com.instagram.android:id/secondary_label" text="Sponsored" content-desc="" />
    </hierarchy>"""

    assert is_ad(xml_true_positive), "Bot failed to flag 'Sponsored'"


def test_is_ad_true_positive_ad_word():
    xml_ad = """<?xml version="1.0"?>
    <hierarchy>
        <node resource-id="com.instagram.android:id/row_feed_profile_header" text="" content-desc="" />
        <node resource-id="com.instagram.android:id/secondary_label" text="Ad" content-desc="" />
    </hierarchy>"""

    assert is_ad(xml_ad), "Bot failed to flag standalone 'Ad'"
