forked from retoor/devplacepy
Comment and post layouts stay full width on small screens. Secondary actions live in the More menu. Notifications can be grouped and throttled, and Enter can submit when that profile setting is on. Emulated-tool models accept large catalogs, with reserved names aliased on the wire and the catalog cached per owner. A dropped service-worker navigation is retried once. The test server waits 120s to finish importing before it is stopped.
929 lines
35 KiB
Python
929 lines
35 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
import re
|
|
import time
|
|
from playwright.sync_api import expect
|
|
from tests.conftest import BASE_URL, paste_image
|
|
from devplacepy.database import get_table
|
|
def _seed_news_seo():
|
|
from datetime import datetime, timezone
|
|
from devplacepy.database import get_table
|
|
from devplacepy.utils import generate_uid, make_combined_slug
|
|
|
|
uid = generate_uid()
|
|
title = f"SEO Test News Article {uid.split('-')[-1]}"
|
|
slug = make_combined_slug(title, uid)
|
|
get_table("news").insert(
|
|
{
|
|
"deleted_at": None,
|
|
"deleted_by": None,
|
|
"uid": uid,
|
|
"slug": slug,
|
|
"title": title,
|
|
"description": "A seeded news article for SEO tests.",
|
|
"content": "Body content for the seeded article.",
|
|
"url": "https://example.com/article",
|
|
"source_name": "ExampleSource",
|
|
"status": "published",
|
|
"synced_at": datetime.now(timezone.utc).isoformat(),
|
|
"show_on_landing": 0,
|
|
"grade": 8,
|
|
}
|
|
)
|
|
return slug, uid
|
|
def _seed_owner():
|
|
from datetime import datetime, timezone
|
|
from uuid import uuid4
|
|
from devplacepy.database import get_table
|
|
|
|
uid = str(uuid4())
|
|
get_table("users").insert(
|
|
{
|
|
"uid": uid,
|
|
"username": f"seo_{uid[:8]}",
|
|
"terms_version": "1",
|
|
"email": f"{uid[:8]}@seo.test",
|
|
"password_hash": "x",
|
|
"role": "Member",
|
|
"is_active": True,
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
}
|
|
)
|
|
return uid
|
|
def _seed_post_seo(image=None):
|
|
from datetime import datetime, timezone
|
|
from uuid import uuid4
|
|
from devplacepy.database import get_table
|
|
from devplacepy.utils import make_combined_slug
|
|
|
|
owner = _seed_owner()
|
|
uid = str(uuid4())
|
|
slug = make_combined_slug("SEO Detail Post", uid)
|
|
get_table("posts").insert(
|
|
{
|
|
"deleted_at": None,
|
|
"deleted_by": None,
|
|
"uid": uid,
|
|
"user_uid": owner,
|
|
"slug": slug,
|
|
"title": "SEO Detail Post",
|
|
"content": "Body text for the SEO detail post.",
|
|
"topic": "general",
|
|
"project_uid": None,
|
|
"image": image,
|
|
"stars": 0,
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
}
|
|
)
|
|
return slug, uid
|
|
def _seed_gist():
|
|
from datetime import datetime, timezone
|
|
from uuid import uuid4
|
|
from devplacepy.database import get_table
|
|
from devplacepy.utils import make_combined_slug
|
|
|
|
owner = _seed_owner()
|
|
uid = str(uuid4())
|
|
slug = make_combined_slug("SEO Detail Gist", uid)
|
|
get_table("gists").insert(
|
|
{
|
|
"deleted_at": None,
|
|
"deleted_by": None,
|
|
"uid": uid,
|
|
"user_uid": owner,
|
|
"slug": slug,
|
|
"title": "SEO Detail Gist",
|
|
"description": "Gist description for SEO tests.",
|
|
"source_code": "print('seo')",
|
|
"language": "python",
|
|
"stars": 0,
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
}
|
|
)
|
|
return slug, uid
|
|
def _seed_project():
|
|
from datetime import datetime, timezone
|
|
from uuid import uuid4
|
|
from devplacepy.database import get_table
|
|
from devplacepy.utils import make_combined_slug
|
|
|
|
owner = _seed_owner()
|
|
uid = str(uuid4())
|
|
slug = make_combined_slug("SEO Detail Project", uid)
|
|
get_table("projects").insert(
|
|
{
|
|
"deleted_at": None,
|
|
"deleted_by": None,
|
|
"uid": uid,
|
|
"user_uid": owner,
|
|
"slug": slug,
|
|
"title": "SEO Detail Project",
|
|
"description": "Project description for SEO tests.",
|
|
"project_type": "software",
|
|
"platforms": "Linux",
|
|
"status": "Released",
|
|
"stars": 0,
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
}
|
|
)
|
|
return slug, uid
|
|
def _seed_news_image(news_uid):
|
|
from devplacepy.database import get_table
|
|
|
|
get_table("news_images").insert(
|
|
{
|
|
"deleted_at": None,
|
|
"deleted_by": None,
|
|
"news_uid": news_uid,
|
|
"url": "https://example.com/seo-news-image.jpg",
|
|
}
|
|
)
|
|
def _seed_feed_posts(count):
|
|
from datetime import datetime, timezone, timedelta
|
|
from uuid import uuid4
|
|
from devplacepy.database import get_table
|
|
from devplacepy.utils import make_combined_slug
|
|
|
|
owner = _seed_owner()
|
|
topic = f"seopag{owner[:8]}"
|
|
base = datetime(2026, 1, 1, tzinfo=timezone.utc)
|
|
posts = get_table("posts")
|
|
for i in range(count):
|
|
uid = str(uuid4())
|
|
posts.insert(
|
|
{
|
|
"deleted_at": None,
|
|
"deleted_by": None,
|
|
"uid": uid,
|
|
"user_uid": owner,
|
|
"slug": make_combined_slug(f"seo pag {i}", uid),
|
|
"title": None,
|
|
"content": f"seo pag post {i}",
|
|
"topic": topic,
|
|
"project_uid": None,
|
|
"image": None,
|
|
"stars": 0,
|
|
"created_at": (base - timedelta(seconds=i)).isoformat(),
|
|
}
|
|
)
|
|
return topic
|
|
|
|
|
|
def test_send_message_appears_in_thread(alice):
|
|
page, _ = alice
|
|
bob = get_table("users").find_one(username="bob_test")
|
|
page.goto(
|
|
f"{BASE_URL}/messages?with_uid={bob['uid']}", wait_until="domcontentloaded"
|
|
)
|
|
msg = f"Hello bob {int(time.time() * 1000)}"
|
|
page.fill("textarea[name='content']", msg)
|
|
page.locator(".messages-send-btn").click()
|
|
page.wait_for_url("**/messages**", wait_until="domcontentloaded")
|
|
page.locator(f".message-bubble:has-text('{msg}')").first.wait_for(state="visible")
|
|
|
|
|
|
def test_admin_deletes_own_message_in_chat(alice):
|
|
page, _ = alice
|
|
bob = get_table("users").find_one(username="bob_test")
|
|
page.goto(
|
|
f"{BASE_URL}/messages?with_uid={bob['uid']}", wait_until="domcontentloaded"
|
|
)
|
|
msg = f"Delete me {int(time.time() * 1000)}"
|
|
page.fill("textarea[name='content']", msg)
|
|
page.locator(".messages-send-btn").click()
|
|
bubble = page.locator(f".message-bubble.mine:has-text('{msg}')").first
|
|
bubble.wait_for(state="visible")
|
|
bubble.locator(".message-delete-btn").wait_for(state="attached")
|
|
bubble.locator(".message-delete-btn").click()
|
|
page.locator(".dialog-overlay.visible .dialog-confirm").click()
|
|
expect(page.locator(f".message-bubble:has-text('{msg}')")).to_have_count(0)
|
|
|
|
|
|
def test_member_sees_no_delete_control_in_chat(bob):
|
|
page, _ = bob
|
|
alice = get_table("users").find_one(username="alice_test")
|
|
page.goto(
|
|
f"{BASE_URL}/messages?with_uid={alice['uid']}", wait_until="domcontentloaded"
|
|
)
|
|
page.locator(".messages-thread").wait_for(state="visible")
|
|
expect(page.locator(".message-delete-btn")).to_have_count(0)
|
|
|
|
|
|
def test_paste_image_attaches_in_chat(alice):
|
|
page, _ = alice
|
|
bob = get_table("users").find_one(username="bob_test")
|
|
page.goto(
|
|
f"{BASE_URL}/messages?with_uid={bob['uid']}", wait_until="domcontentloaded"
|
|
)
|
|
page.locator(".messages-input-area dp-upload .dp-upload-btn").first.wait_for(
|
|
state="attached", timeout=10000
|
|
)
|
|
paste_image(page, ".messages-input-area textarea[name='content']")
|
|
page.locator(".messages-input-area dp-upload .dp-upload-count").first.wait_for(
|
|
state="visible", timeout=15000
|
|
)
|
|
expect(
|
|
page.locator(".messages-input-area dp-upload input[name='attachment_uids']")
|
|
).to_have_value(re.compile(r".+"))
|
|
|
|
|
|
def test_messages_page_loads(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
assert page.is_visible(".messages-layout")
|
|
|
|
|
|
def test_chat_presence_is_driven_by_the_shared_roster(alice, bob):
|
|
bob_page, _ = bob
|
|
bob_page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
bob_uid = get_table("users").find_one(username="bob_test")["uid"]
|
|
page, _ = alice
|
|
page.goto(
|
|
f"{BASE_URL}/messages?with_uid={bob_uid}", wait_until="domcontentloaded"
|
|
)
|
|
presence = page.locator("#messages-presence")
|
|
expect(presence).to_be_visible()
|
|
expect(presence).to_have_class(re.compile(r"\bonline\b"))
|
|
# the chat header and the feed roster read the same subscribed uid, never a
|
|
# second client-side clock over a frozen last_seen
|
|
assert presence.get_attribute("data-presence-uid") == bob_uid
|
|
dots = page.locator(f".presence-dot[data-presence-uid='{bob_uid}']")
|
|
assert dots.count() >= 1
|
|
expect(dots.first).to_have_class(re.compile(r"\bonline\b"))
|
|
|
|
|
|
def test_messages_search_input(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
search = page.locator("#message-search")
|
|
assert search.is_visible()
|
|
assert search.get_attribute("placeholder") == "Search conversations..."
|
|
|
|
|
|
def test_messages_empty_state(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
assert page.is_visible(".messages-layout") or page.is_visible(
|
|
"text=No conversations yet"
|
|
)
|
|
|
|
|
|
def test_messages_search_for_bob(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
page.fill("#message-search", "bob_test")
|
|
result = page.locator(".search-dropdown-item:has-text('bob_test')")
|
|
result.wait_for(state="visible", timeout=5000)
|
|
assert result.is_visible()
|
|
|
|
|
|
def test_messages_search_first_result_highlighted(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
page.fill("#message-search", "bob_test")
|
|
result = page.locator(".search-dropdown-item:has-text('bob_test')")
|
|
result.wait_for(state="visible", timeout=5000)
|
|
expect(result.first).to_have_class(re.compile(r"\bactive\b"))
|
|
|
|
|
|
def test_messages_search_enter_opens_conversation(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
page.fill("#message-search", "bob_test")
|
|
page.locator(".search-dropdown-item:has-text('bob_test')").wait_for(
|
|
state="visible", timeout=5000
|
|
)
|
|
page.locator("#message-search").press("Enter")
|
|
page.wait_for_url(re.compile(r"with_uid="), wait_until="domcontentloaded")
|
|
|
|
|
|
def test_messages_search_arrow_then_enter_opens_conversation(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
page.fill("#message-search", "bob_test")
|
|
page.locator(".search-dropdown-item:has-text('bob_test')").wait_for(
|
|
state="visible", timeout=5000
|
|
)
|
|
search = page.locator("#message-search")
|
|
search.press("ArrowDown")
|
|
search.press("Enter")
|
|
page.wait_for_url(re.compile(r"with_uid="), wait_until="domcontentloaded")
|
|
|
|
|
|
def test_messages_search_escape_closes_dropdown(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
page.fill("#message-search", "bob_test")
|
|
result = page.locator(".search-dropdown-item:has-text('bob_test')")
|
|
result.wait_for(state="visible", timeout=5000)
|
|
page.locator("#message-search").press("Escape")
|
|
expect(result).to_be_hidden()
|
|
|
|
|
|
def test_messages_header_visible(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
assert page.is_visible("text=Home")
|
|
assert page.is_visible("text=Projects")
|
|
|
|
|
|
def test_messages_bell_icon(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
bell = page.locator(".topnav-icon[href='/notifications']")
|
|
assert bell.is_visible()
|
|
|
|
|
|
def test_messages_topnav_user(alice):
|
|
page, user = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
assert page.is_visible(f"text={user['username']}")
|
|
|
|
|
|
def test_messages_avatar_on_page(alice):
|
|
page, user = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
avatar = page.locator("img.avatar-img").first
|
|
assert avatar.is_visible()
|
|
|
|
|
|
def test_messages_page_is_noindex(alice):
|
|
page, user = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
page.wait_for_url("**/messages", wait_until="domcontentloaded")
|
|
meta = page.locator('meta[name="robots"]')
|
|
content = meta.get_attribute("content")
|
|
assert content and "noindex" in content
|
|
|
|
|
|
def test_optimistic_send_pending_then_reconciles_no_double_render(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_a = get_table("users").find_one(username=user_a["username"])["uid"]
|
|
uid_b = get_table("users").find_one(username=user_b["username"])["uid"]
|
|
|
|
page_a.goto(
|
|
f"{BASE_URL}/messages?with_uid={uid_b}", wait_until="domcontentloaded"
|
|
)
|
|
page_b.goto(
|
|
f"{BASE_URL}/messages?with_uid={uid_a}", wait_until="domcontentloaded"
|
|
)
|
|
|
|
msg = f"Optimistic hello {int(time.time() * 1000)}"
|
|
textarea = page_a.locator(".messages-input-area textarea[name='content']")
|
|
textarea.wait_for(state="visible")
|
|
textarea.fill(msg)
|
|
page_a.locator(".messages-send-btn").click()
|
|
|
|
bubble = page_a.locator(f".message-bubble.mine:has-text('{msg}')").first
|
|
bubble.wait_for(state="visible", timeout=10000)
|
|
client_id = bubble.get_attribute("data-client-id")
|
|
assert client_id
|
|
|
|
reconciled = page_a.locator(
|
|
f".message-bubble.mine[data-client-id='{client_id}'][data-msg-uid]:not(.pending)"
|
|
)
|
|
reconciled.wait_for(state="visible", timeout=10000)
|
|
assert page_a.locator(f".message-bubble.mine:has-text('{msg}')").count() == 1
|
|
|
|
received = page_b.locator(f".message-bubble.theirs:has-text('{msg}')")
|
|
received.wait_for(state="visible", timeout=10000)
|
|
assert received.count() == 1
|
|
|
|
|
|
def test_mobile_single_pane_back_button(mobile_page):
|
|
page, user = mobile_page
|
|
bob = get_table("users").find_one(username="bob_test")
|
|
page.goto(
|
|
f"{BASE_URL}/messages?with_uid={bob['uid']}", wait_until="domcontentloaded"
|
|
)
|
|
|
|
thread = page.locator(".messages-main")
|
|
conv_list = page.locator(".messages-list")
|
|
thread.wait_for(state="visible")
|
|
expect(conv_list).to_be_hidden()
|
|
|
|
page.locator("#messages-back-btn").click()
|
|
|
|
expect(conv_list).to_be_visible()
|
|
expect(thread).to_be_hidden()
|
|
assert page.url == f"{BASE_URL}/messages"
|
|
|
|
|
|
def test_live_incoming_message_shows_report_button(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_a = get_table("users").find_one(username=user_a["username"])["uid"]
|
|
uid_b = get_table("users").find_one(username=user_b["username"])["uid"]
|
|
|
|
page_a.goto(
|
|
f"{BASE_URL}/messages?with_uid={uid_b}", wait_until="domcontentloaded"
|
|
)
|
|
page_b.goto(
|
|
f"{BASE_URL}/messages?with_uid={uid_a}", wait_until="domcontentloaded"
|
|
)
|
|
|
|
msg = f"Flag me {int(time.time() * 1000)}"
|
|
textarea = page_a.locator(".messages-input-area textarea[name='content']")
|
|
textarea.wait_for(state="visible")
|
|
textarea.fill(msg)
|
|
page_a.locator(".messages-send-btn").click()
|
|
|
|
bubble = page_b.locator(f".message-bubble.theirs:has-text('{msg}')")
|
|
bubble.wait_for(state="visible", timeout=10000)
|
|
expect(bubble.locator(".message-report-btn")).to_be_visible()
|
|
|
|
|
|
def test_send_button_locks_during_send_and_prevents_duplicate(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_b = get_table("users").find_one(username=user_b["username"])["uid"]
|
|
|
|
page_a.goto(
|
|
f"{BASE_URL}/messages?with_uid={uid_b}", wait_until="domcontentloaded"
|
|
)
|
|
|
|
msg = f"Locked send {int(time.time() * 1000)}"
|
|
textarea = page_a.locator(".messages-input-area textarea[name='content']")
|
|
textarea.wait_for(state="visible")
|
|
textarea.fill(msg)
|
|
|
|
send_btn = page_a.locator(".messages-send-btn")
|
|
send_btn.click()
|
|
|
|
# the composer refuses a duplicate submit while this send is unconfirmed
|
|
expect(send_btn).to_be_disabled()
|
|
|
|
bubble = page_a.locator(f".message-bubble.mine:has-text('{msg}')")
|
|
reconciled = page_a.locator(
|
|
f".message-bubble.mine:has-text('{msg}')[data-msg-uid]:not(.pending)"
|
|
)
|
|
reconciled.first.wait_for(state="visible", timeout=10000)
|
|
|
|
expect(send_btn).to_be_enabled()
|
|
assert bubble.count() == 1
|
|
|
|
|
|
def test_scroll_up_is_not_yanked_by_incoming_message(alice, bob):
|
|
from datetime import datetime, timedelta, timezone
|
|
from devplacepy.utils import generate_uid
|
|
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_a = get_table("users").find_one(username=user_a["username"])["uid"]
|
|
uid_b = get_table("users").find_one(username=user_b["username"])["uid"]
|
|
|
|
base = datetime.now(timezone.utc) - timedelta(minutes=5)
|
|
for i in range(40):
|
|
get_table("messages").insert(
|
|
{
|
|
"uid": generate_uid(),
|
|
"sender_uid": uid_a if i % 2 == 0 else uid_b,
|
|
"receiver_uid": uid_b if i % 2 == 0 else uid_a,
|
|
"content": f"scroll history line {i}",
|
|
"read": True,
|
|
"created_at": (base + timedelta(seconds=i)).isoformat(),
|
|
"updated_at": None,
|
|
}
|
|
)
|
|
|
|
page_a.goto(
|
|
f"{BASE_URL}/messages?with_uid={uid_b}", wait_until="domcontentloaded"
|
|
)
|
|
page_b.goto(
|
|
f"{BASE_URL}/messages?with_uid={uid_a}", wait_until="domcontentloaded"
|
|
)
|
|
|
|
thread = page_a.locator(".messages-thread")
|
|
thread.wait_for(state="visible")
|
|
thread.locator(".message-bubble").first.wait_for(state="visible")
|
|
|
|
thread.evaluate(
|
|
"el => { el.scrollTop = 0; el.dispatchEvent(new Event('scroll')); }"
|
|
)
|
|
page_a.wait_for_timeout(200)
|
|
scroll_before = thread.evaluate("el => el.scrollTop")
|
|
assert scroll_before < 50
|
|
|
|
msg = f"While scrolled up {int(time.time() * 1000)}"
|
|
textarea_b = page_b.locator(".messages-input-area textarea[name='content']")
|
|
textarea_b.wait_for(state="visible")
|
|
textarea_b.fill(msg)
|
|
page_b.locator(".messages-send-btn").click()
|
|
|
|
page_a.locator(f".message-bubble.theirs:has-text('{msg}')").first.wait_for(
|
|
state="visible", timeout=10000
|
|
)
|
|
scroll_after = thread.evaluate("el => el.scrollTop")
|
|
assert scroll_after < 50, (
|
|
"an incoming message must not yank a scrolled-up reader back to the bottom"
|
|
)
|
|
|
|
|
|
def test_scroll_stays_pinned_to_bottom_for_active_reader(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_a = get_table("users").find_one(username=user_a["username"])["uid"]
|
|
uid_b = get_table("users").find_one(username=user_b["username"])["uid"]
|
|
|
|
page_a.goto(
|
|
f"{BASE_URL}/messages?with_uid={uid_b}", wait_until="domcontentloaded"
|
|
)
|
|
page_b.goto(
|
|
f"{BASE_URL}/messages?with_uid={uid_a}", wait_until="domcontentloaded"
|
|
)
|
|
|
|
thread = page_a.locator(".messages-thread")
|
|
thread.wait_for(state="visible")
|
|
|
|
msg = f"Pinned bottom {int(time.time() * 1000)}"
|
|
textarea_b = page_b.locator(".messages-input-area textarea[name='content']")
|
|
textarea_b.wait_for(state="visible")
|
|
textarea_b.fill(msg)
|
|
page_b.locator(".messages-send-btn").click()
|
|
|
|
page_a.locator(f".message-bubble.theirs:has-text('{msg}')").first.wait_for(
|
|
state="visible", timeout=10000
|
|
)
|
|
at_bottom = thread.evaluate(
|
|
"el => el.scrollHeight - el.scrollTop - el.clientHeight < 100"
|
|
)
|
|
assert at_bottom, "an active-at-bottom reader must still auto-scroll to new messages"
|
|
|
|
|
|
def _uid(username):
|
|
return get_table("users").find_one(username=username)["uid"]
|
|
|
|
|
|
def _send_as(page, receiver_uid, content):
|
|
ok = page.evaluate(
|
|
"async ([uid, text]) => {"
|
|
" const body = new URLSearchParams({receiver_uid: uid, content: text});"
|
|
" const resp = await fetch('/messages/send', {method: 'POST', body, headers: {Accept: 'application/json'}});"
|
|
" return resp.ok;"
|
|
"}",
|
|
[receiver_uid, content],
|
|
)
|
|
assert ok, "seed message send must succeed"
|
|
|
|
|
|
def test_dock_icon_opens_chats_panel_then_a_docked_window(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_b = _uid(user_b["username"])
|
|
msg = f"Dock hello {int(time.time() * 1000)}"
|
|
_send_as(page_b, _uid(user_a["username"]), msg)
|
|
|
|
page_a.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
page_a.locator("[data-chat-panel-toggle]").first.click()
|
|
panel = page_a.locator(".chat-panel")
|
|
expect(panel).to_be_visible()
|
|
item = panel.locator(f".conversation-item[data-conv-uid='{uid_b}']")
|
|
item.wait_for(state="visible")
|
|
item.click()
|
|
|
|
expect(panel).to_be_hidden()
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
window.locator(f".message-bubble:has-text('{msg}')").wait_for(state="visible")
|
|
assert page_a.url.endswith("/feed")
|
|
|
|
|
|
def test_dock_window_sends_and_receives_live(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_a = _uid(user_a["username"])
|
|
uid_b = _uid(user_b["username"])
|
|
page_b.goto(f"{BASE_URL}/messages?with_uid={uid_a}", wait_until="domcontentloaded")
|
|
page_a.goto(f"{BASE_URL}/profile/{user_b['username']}", wait_until="domcontentloaded")
|
|
page_a.locator(f"[data-chat-open='{uid_b}']").click()
|
|
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
textarea = window.locator("textarea[name='content']")
|
|
textarea.wait_for(state="visible")
|
|
msg = f"From the dock {int(time.time() * 1000)}"
|
|
textarea.fill(msg)
|
|
textarea.press("Enter")
|
|
window.locator(f".message-bubble.mine[data-msg-uid]:not(.pending):has-text('{msg}')").wait_for(
|
|
state="visible", timeout=10000
|
|
)
|
|
page_b.locator(f".message-bubble.theirs:has-text('{msg}')").wait_for(state="visible", timeout=10000)
|
|
|
|
reply = f"Back to the dock {int(time.time() * 1000)}"
|
|
textarea_b = page_b.locator(".messages-input-area textarea[name='content']")
|
|
textarea_b.fill(reply)
|
|
page_b.locator(".messages-send-btn").click()
|
|
window.locator(f".message-bubble.theirs:has-text('{reply}')").wait_for(state="visible", timeout=10000)
|
|
assert page_a.url.endswith(f"/profile/{user_b['username']}")
|
|
|
|
|
|
def test_dock_minimized_head_counts_unread_and_survives_navigation(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_b = _uid(user_b["username"])
|
|
page_a.goto(f"{BASE_URL}/profile/{user_b['username']}", wait_until="domcontentloaded")
|
|
page_a.locator(f"[data-chat-open='{uid_b}']").click()
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
window.locator(".chat-window-minimize").click()
|
|
|
|
head = page_a.locator(f".chat-head[data-chat-uid='{uid_b}']")
|
|
head.wait_for(state="visible")
|
|
expect(window).to_have_count(0)
|
|
page_a.wait_for_function("() => document.querySelector('dp-chat-dock').hub.isOpen()")
|
|
msg = f"While minimized {int(time.time() * 1000)}"
|
|
_send_as(page_b, _uid(user_a["username"]), msg)
|
|
expect(head.locator(".chat-head-badge")).to_have_text("1", timeout=10000)
|
|
|
|
page_a.goto(f"{BASE_URL}/projects", wait_until="domcontentloaded")
|
|
head.wait_for(state="visible")
|
|
head.locator(".chat-head-open").click()
|
|
window.locator(f".message-bubble:has-text('{msg}')").wait_for(state="visible")
|
|
expect(head).to_have_count(0)
|
|
|
|
|
|
def test_dock_compose_window_starts_a_chat(alice, bob):
|
|
page, _ = alice
|
|
_, user_b = bob
|
|
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
page.locator("[data-chat-panel-toggle]").first.click()
|
|
page.locator(".chat-panel-compose").click()
|
|
compose = page.locator(".chat-window-compose")
|
|
compose.locator(".chat-compose-input").fill(user_b["username"])
|
|
compose.locator(f".conversation-item[data-conv-uid='{_uid(user_b['username'])}']").wait_for(state="visible")
|
|
page.keyboard.press("Enter")
|
|
|
|
expect(compose).to_have_count(0)
|
|
page.locator(f".chat-window[data-chat-uid='{_uid(user_b['username'])}'] textarea[name='content']").wait_for(
|
|
state="visible"
|
|
)
|
|
|
|
|
|
def test_dock_is_absent_on_messages_page(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
page.locator("dp-chat.messages-layout").wait_for(state="attached")
|
|
expect(page.locator("dp-chat-dock")).to_have_count(0)
|
|
|
|
|
|
def test_mobile_messages_icon_opens_the_messages_page(mobile_page):
|
|
page, _ = mobile_page
|
|
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
page.locator("[data-chat-panel-toggle]").first.click()
|
|
page.wait_for_url(f"{BASE_URL}/messages", wait_until="domcontentloaded")
|
|
|
|
|
|
def test_composer_plus_button_reveals_attach_tools(alice):
|
|
page, _ = alice
|
|
page.goto(f"{BASE_URL}/messages?with_uid={_uid('bob_test')}", wait_until="domcontentloaded")
|
|
area = page.locator(".messages-input-area")
|
|
upload = area.locator("dp-upload .dp-upload-btn")
|
|
more = area.locator(".composer-more-btn")
|
|
area.locator(".composer-field .emoji-toggle-btn").wait_for(state="visible")
|
|
expect(upload).to_be_hidden()
|
|
|
|
more.click()
|
|
expect(upload).to_be_visible()
|
|
expect(more).to_have_attribute("aria-expanded", "true")
|
|
|
|
area.locator("textarea[name='content']").fill("typing tucks the tools away")
|
|
expect(upload).to_be_hidden()
|
|
expect(more).to_have_attribute("aria-expanded", "false")
|
|
|
|
|
|
def test_dock_window_plus_button_reveals_attach_tools(alice, bob):
|
|
page_a, _ = alice
|
|
_, user_b = bob
|
|
uid_b = _uid(user_b["username"])
|
|
page_a.goto(f"{BASE_URL}/profile/{user_b['username']}", wait_until="domcontentloaded")
|
|
page_a.locator(f"[data-chat-open='{uid_b}']").click()
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
area = window.locator(".messages-input-area")
|
|
upload = area.locator("dp-upload .dp-upload-btn")
|
|
more = area.locator(".composer-more-btn")
|
|
expect(upload).to_be_hidden()
|
|
more.click()
|
|
expect(upload).to_be_visible()
|
|
expect(more).to_have_attribute("aria-expanded", "true")
|
|
area.locator("textarea[name='content']").fill("typing in the window")
|
|
expect(upload).to_be_hidden()
|
|
|
|
|
|
def test_dock_open_window_survives_navigation(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_b = _uid(user_b["username"])
|
|
msg = f"Restore me {int(time.time() * 1000)}"
|
|
_send_as(page_b, _uid(user_a["username"]), msg)
|
|
page_a.goto(f"{BASE_URL}/profile/{user_b['username']}", wait_until="domcontentloaded")
|
|
page_a.locator(f"[data-chat-open='{uid_b}']").click()
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
window.locator(f".message-bubble:has-text('{msg}')").wait_for(state="visible")
|
|
page_a.goto(f"{BASE_URL}/projects", wait_until="domcontentloaded")
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
window.locator(f".message-bubble:has-text('{msg}')").wait_for(state="visible")
|
|
expect(window.locator("textarea[name='content']")).to_be_visible()
|
|
|
|
|
|
def test_dock_panel_search_and_see_all(alice, bob):
|
|
page_a, _ = alice
|
|
_, user_b = bob
|
|
uid_b = _uid(user_b["username"])
|
|
page_a.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
page_a.locator("[data-chat-panel-toggle]").first.click()
|
|
panel = page_a.locator(".chat-panel")
|
|
expect(panel).to_be_visible()
|
|
expect(panel.locator(".chat-panel-footer")).to_have_attribute("href", "/messages")
|
|
panel.locator(".chat-panel-search-input").fill(user_b["username"])
|
|
item = panel.locator(f".conversation-item[data-conv-uid='{uid_b}']")
|
|
item.wait_for(state="visible")
|
|
item.click()
|
|
expect(panel).to_be_hidden()
|
|
expect(page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")).to_have_count(1)
|
|
|
|
|
|
def test_dock_panel_and_window_close_controls(alice, bob):
|
|
page_a, _ = alice
|
|
_, user_b = bob
|
|
uid_b = _uid(user_b["username"])
|
|
page_a.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
toggle = page_a.locator("[data-chat-panel-toggle]").first
|
|
panel = page_a.locator(".chat-panel")
|
|
toggle.click()
|
|
expect(panel).to_be_visible()
|
|
page_a.keyboard.press("Escape")
|
|
expect(panel).to_be_hidden()
|
|
toggle.click()
|
|
expect(panel).to_be_visible()
|
|
page_a.locator("body").click(position={"x": 700, "y": 500})
|
|
expect(panel).to_be_hidden()
|
|
|
|
page_a.goto(f"{BASE_URL}/profile/{user_b['username']}", wait_until="domcontentloaded")
|
|
page_a.locator(f"[data-chat-open='{uid_b}']").click()
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
window.locator(".chat-window-close").click()
|
|
expect(window).to_have_count(0)
|
|
|
|
page_a.locator(f"[data-chat-open='{uid_b}']").click()
|
|
window.locator(".chat-window-minimize").click()
|
|
head = page_a.locator(f".chat-head[data-chat-uid='{uid_b}']")
|
|
head.wait_for(state="visible")
|
|
head.locator(".chat-head-close").click()
|
|
expect(head).to_have_count(0)
|
|
|
|
|
|
def test_dock_caps_expanded_windows_at_three(alice, bob):
|
|
page_a, _ = alice
|
|
_, user_b = bob
|
|
from devplacepy.utils import generate_uid
|
|
|
|
partners = [_uid(user_b["username"])]
|
|
for name in ("dockcap1", "dockcap2", "dockcap3"):
|
|
row = get_table("users").find_one(username=name)
|
|
if not row:
|
|
get_table("users").insert(
|
|
{
|
|
"deleted_at": None,
|
|
"deleted_by": None,
|
|
"uid": generate_uid(),
|
|
"username": name,
|
|
"email": f"{name}@test.devplace",
|
|
"password_hash": "x",
|
|
"role": "Member",
|
|
"is_active": True,
|
|
"created_at": "2026-01-01T00:00:00+00:00",
|
|
}
|
|
)
|
|
row = get_table("users").find_one(username=name)
|
|
partners.append(row["uid"])
|
|
page_a.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
for uid in partners:
|
|
page_a.evaluate("(uid) => window.app.chatDock.open({ uid, username: 'x' }, { focus: false })", uid)
|
|
expect(page_a.locator(".chat-window:not(.chat-window-compose)")).to_have_count(3)
|
|
expect(page_a.locator(".chat-head")).to_have_count(1)
|
|
|
|
|
|
def test_dock_toast_click_opens_window(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, _ = bob
|
|
uid_a = _uid(user_a["username"])
|
|
uid_b = _uid("bob_test")
|
|
page_a.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
page_a.wait_for_function("() => !!window.app && !!window.app.chatDock")
|
|
msg = f"Toast hello {int(time.time() * 1000)}"
|
|
_send_as(page_b, uid_a, msg)
|
|
page_a.evaluate(
|
|
"(sender) => window.app.liveNotifications.onNotification("
|
|
" { uid: 'toast-test', type: 'message', message: 'bob_test sent you a message',"
|
|
" target_url: `/messages?with_uid=${sender}` })",
|
|
uid_b,
|
|
)
|
|
toast = page_a.locator(".dp-toast-link")
|
|
toast.first.wait_for(state="visible", timeout=10000)
|
|
toast.first.click()
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
window.locator(f".message-bubble:has-text('{msg}')").wait_for(state="visible", timeout=10000)
|
|
assert page_a.url.endswith("/feed")
|
|
|
|
|
|
def test_dock_window_live_message_shows_report_button(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_a = _uid(user_a["username"])
|
|
uid_b = _uid(user_b["username"])
|
|
page_a.goto(f"{BASE_URL}/profile/{user_b['username']}", wait_until="domcontentloaded")
|
|
page_a.locator(f"[data-chat-open='{uid_b}']").click()
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
window.locator("textarea[name='content']").wait_for(state="visible")
|
|
msg = f"Flag in window {int(time.time() * 1000)}"
|
|
_send_as(page_b, uid_a, msg)
|
|
bubble = window.locator(f".message-bubble.theirs:has-text('{msg}')")
|
|
bubble.wait_for(state="visible", timeout=10000)
|
|
expect(bubble.locator(".message-report-btn")).to_be_visible()
|
|
|
|
|
|
def test_dock_reading_on_messages_page_clears_head_badge(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_a = _uid(user_a["username"])
|
|
uid_b = _uid(user_b["username"])
|
|
page_a.goto(f"{BASE_URL}/profile/{user_b['username']}", wait_until="domcontentloaded")
|
|
page_a.locator(f"[data-chat-open='{uid_b}']").click()
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
window.locator(".chat-window-minimize").click()
|
|
head = page_a.locator(f".chat-head[data-chat-uid='{uid_b}']")
|
|
head.wait_for(state="visible")
|
|
_send_as(page_b, uid_a, f"Badge check {int(time.time() * 1000)}")
|
|
expect(head.locator(".chat-head-badge")).to_have_text("1", timeout=10000)
|
|
|
|
page_a.goto(f"{BASE_URL}/messages?with_uid={uid_b}", wait_until="domcontentloaded")
|
|
page_a.locator(".messages-thread .message-bubble").first.wait_for(state="visible")
|
|
page_a.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
|
head = page_a.locator(f".chat-head[data-chat-uid='{uid_b}']")
|
|
head.wait_for(state="visible")
|
|
expect(head.locator(".chat-head-badge")).to_be_hidden(timeout=10000)
|
|
|
|
|
|
def test_dock_hidden_tab_does_not_mark_read_until_visible(alice, bob):
|
|
page_a, user_a = alice
|
|
page_b, user_b = bob
|
|
uid_a = _uid(user_a["username"])
|
|
uid_b = _uid(user_b["username"])
|
|
page_a.goto(f"{BASE_URL}/profile/{user_b['username']}", wait_until="domcontentloaded")
|
|
page_a.locator(f"[data-chat-open='{uid_b}']").click()
|
|
window = page_a.locator(f".chat-window[data-chat-uid='{uid_b}']")
|
|
window.locator("textarea[name='content']").wait_for(state="visible")
|
|
page_a.wait_for_function("() => document.querySelector('dp-chat-dock').hub.isOpen()")
|
|
|
|
page_a.evaluate(
|
|
"() => { Object.defineProperty(document, 'visibilityState', { value: 'hidden', configurable: true });"
|
|
" document.dispatchEvent(new Event('visibilitychange')); }"
|
|
)
|
|
msg = f"Hidden tab {int(time.time() * 1000)}"
|
|
_send_as(page_b, uid_a, msg)
|
|
window.locator(f".message-bubble:has-text('{msg}')").wait_for(state="visible", timeout=10000)
|
|
page_a.wait_for_timeout(500)
|
|
unread = page_a.evaluate(
|
|
"async (uid) => { const r = await fetch('/messages/conversations', {headers: {Accept: 'application/json'}});"
|
|
" const d = await r.json(); const c = (d.conversations || []).find((x) => x.other_user.uid === uid);"
|
|
" return c ? c.unread : null; }",
|
|
uid_b,
|
|
)
|
|
assert unread is True, "a message to a window in a hidden tab must stay unread"
|
|
|
|
page_a.evaluate(
|
|
"() => { Object.defineProperty(document, 'visibilityState', { value: 'visible', configurable: true });"
|
|
" document.dispatchEvent(new Event('visibilitychange')); }"
|
|
)
|
|
page_a.wait_for_function(
|
|
"async (uid) => { const r = await fetch('/messages/conversations', {headers: {Accept: 'application/json'}});"
|
|
" const d = await r.json(); const c = (d.conversations || []).find((x) => x.other_user.uid === uid);"
|
|
" return !!c && c.unread === false; }",
|
|
arg=uid_b,
|
|
timeout=10000,
|
|
)
|
|
|
|
|
|
def test_dock_socket_does_not_resurrect_after_last_window_closes(alice, bob):
|
|
page_a, _ = alice
|
|
_, user_b = bob
|
|
uid_b = _uid(user_b["username"])
|
|
page_a.goto(f"{BASE_URL}/profile/{user_b['username']}", wait_until="domcontentloaded")
|
|
page_a.locator(f"[data-chat-open='{uid_b}']").click()
|
|
page_a.locator(f".chat-window[data-chat-uid='{uid_b}'] textarea[name='content']").wait_for(state="visible")
|
|
page_a.wait_for_function("() => document.querySelector('dp-chat-dock').hub.isOpen()")
|
|
result = page_a.evaluate(
|
|
"async (uid) => {"
|
|
" const dock = document.querySelector('dp-chat-dock');"
|
|
" const cs = dock.hub.socket;"
|
|
" let opens = 0; const orig = cs._open.bind(cs);"
|
|
" cs._open = () => { opens += 1; return orig(); };"
|
|
" cs.socket.close();"
|
|
" await new Promise((r) => setTimeout(r, 100));"
|
|
" dock.close(uid);"
|
|
" await new Promise((r) => setTimeout(r, 900));"
|
|
" return { opens, hubSocket: dock.hub.socket === null, state: cs.socket ? cs.socket.readyState : null };"
|
|
"}",
|
|
uid_b,
|
|
)
|
|
assert result["hubSocket"], "the hub must not hold a socket after the last window closes"
|
|
assert result["opens"] == 0, f"a closed socket must not reconnect with zero subscribers: {result}"
|