# retoor <retoor@molodetz.nl>

from tests.conftest import BASE_URL
FOLLOW = "form[action='/follow/bob_test'] button"
UNFOLLOW = "form[action='/follow/unfollow/bob_test'] button"
from playwright.sync_api import expect


def test_follow_then_unfollow(alice):
    page, _ = alice
    page.goto(f"{BASE_URL}/profile/bob_test", wait_until="domcontentloaded")
    if page.is_visible(UNFOLLOW):
        page.click(UNFOLLOW)
        page.wait_for_url("**/profile/bob_test", wait_until="domcontentloaded")
    assert page.is_visible(FOLLOW)
    page.click(FOLLOW)
    page.wait_for_url("**/profile/bob_test", wait_until="domcontentloaded")
    assert page.is_visible(UNFOLLOW)
    page.click(UNFOLLOW)
    page.wait_for_url("**/profile/bob_test", wait_until="domcontentloaded")
    assert page.is_visible(FOLLOW)


def test_profile_viewing_other_user(bob, alice):
    page_b, user_b = bob
    page_b.goto(f"{BASE_URL}/profile/alice_test", wait_until="domcontentloaded")
    assert page_b.is_visible("text=alice_test")


def test_profile_message_button(bob, alice):
    page_b, _ = bob
    page_b.goto(f"{BASE_URL}/profile/alice_test", wait_until="domcontentloaded")
    message_btn = page_b.locator("a:has-text('Send Message')")
    assert message_btn.is_visible()
