# retoor <retoor@molodetz.nl>

from playwright.sync_api import expect
from tests.conftest import BASE_URL


def test_regenerate_avatar_updates_preview(alice):
    page, user = alice
    page.goto(
        f"{BASE_URL}/profile/{user['username']}", wait_until="domcontentloaded"
    )
    preview = page.locator("#profile-avatar-preview")
    expect(preview).to_be_visible()
    before = preview.get_attribute("src")

    page.locator("[data-regenerate-avatar]").click()
    page.locator(".dialog-overlay.visible .dialog-confirm").click()

    expect(preview).not_to_have_attribute("src", before)
    after = preview.get_attribute("src")
    assert after.startswith("/avatar/multiavatar/")


def test_regenerate_button_hidden_for_other_user(alice, bob):
    alice_page, alice_user = alice
    bob_page, _ = bob
    bob_page.goto(
        f"{BASE_URL}/profile/{alice_user['username']}", wait_until="domcontentloaded"
    )
    expect(bob_page.locator("[data-regenerate-avatar]")).to_have_count(0)
