|
# retoor <retoor@molodetz.nl>
|
|
|
|
import re
|
|
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
|
|
from tests.e2e.post import create_post
|
|
|
|
|
|
def test_profile_shows_online_presence(alice):
|
|
page, user = alice
|
|
page.goto(
|
|
f"{BASE_URL}/profile/{user['username']}", wait_until="domcontentloaded"
|
|
)
|
|
presence = page.locator(".profile-presence")
|
|
expect(presence).to_be_visible()
|
|
expect(presence).to_have_class(re.compile(r"\bonline\b"))
|
|
expect(presence).to_have_text("online")
|
|
|
|
|
|
def test_nav_avatar_shows_online_presence_dot(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
nav_dot = page.locator(".topnav-user .presence-dot")
|
|
expect(nav_dot).to_be_visible()
|
|
expect(nav_dot).to_have_class(re.compile(r"\bonline\b"))
|
|
|
|
|
|
def _post_comment(page, body):
|
|
textarea = page.locator(".comment-form textarea[name='content']")
|
|
textarea.fill(body)
|
|
page.locator(".comment-form button:has-text('Post')").click()
|
|
expect(page.locator(f".comment-text:has-text('{body}')")).to_be_visible()
|
|
|
|
|
|
def test_activity_comment_card_links_to_parent_post(alice):
|
|
page, user = alice
|
|
create_post(page, "devlog", "Post for activity comment link")
|
|
post_url = page.url
|
|
_post_comment(page, "Activity clickable comment body")
|
|
|
|
page.goto(
|
|
f"{BASE_URL}/profile/{user['username']}?tab=activity",
|
|
wait_until="domcontentloaded",
|
|
)
|
|
card_link = page.locator(
|
|
".activity-card.card-link-host a.card-link[href*='#comment-']"
|
|
).first
|
|
expect(card_link).to_have_count(1)
|
|
href = card_link.get_attribute("href")
|
|
assert "/posts/" in href and "#comment-" in href
|
|
|
|
card_link.click()
|
|
page.wait_for_url("**/posts/**", wait_until="domcontentloaded")
|
|
expect(
|
|
page.locator(".comment-text:has-text('Activity clickable comment body')")
|
|
).to_be_visible()
|
|
|
|
|
|
def test_activity_post_card_links_to_post(alice):
|
|
page, user = alice
|
|
create_post(page, "showcase", "Post for activity post link", title="Activity Post Title")
|
|
|
|
page.goto(
|
|
f"{BASE_URL}/profile/{user['username']}?tab=activity",
|
|
wait_until="domcontentloaded",
|
|
)
|
|
post_link = page.locator(
|
|
".activity-card.card-link-host a.card-link[href^='/posts/']:not([href*='#comment-'])"
|
|
).first
|
|
expect(post_link).to_have_count(1)
|
|
post_link.click()
|
|
page.wait_for_url("**/posts/**", wait_until="domcontentloaded")
|
|
expect(page.locator(".post-detail-title:has-text('Activity Post Title')")).to_be_visible()
|
|
|
|
|
|
def test_activity_inner_content_link_stays_clickable(alice, bob):
|
|
page, user = alice
|
|
create_post(page, "random", "Post for activity mention comment")
|
|
_post_comment(page, "Ping @bob_test in activity")
|
|
|
|
page.goto(
|
|
f"{BASE_URL}/profile/{user['username']}?tab=activity",
|
|
wait_until="domcontentloaded",
|
|
)
|
|
mention = page.locator(
|
|
".activity-card.card-link-host .activity-content a[href='/profile/bob_test']"
|
|
).first
|
|
expect(mention).to_have_count(1)
|
|
mention.click()
|
|
page.wait_for_url("**/profile/bob_test", wait_until="domcontentloaded")
|
|
|
|
|
|
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()
|