forked from retoor/devplacepy
Messages: Facebook-style Chats panel and docked chat windows
The topnav Messages icon opens a Chats panel (people search, recent conversations, New message, link to the full page). Picking a person opens a small chat window docked bottom-right; windows minimize to avatar heads with unread counts and survive navigation within the tab. Profile Send Message, the live message toast and message notifications on /notifications open the same window. Phones and /messages keep the full page. Each window is dp-chat in mode="window", sharing one WebSocket through chat/ChatSocketHub.js; chat/ConversationItem.js is the shared row builder. No server changes. The message input becomes [+] [text + emoji] [send] everywhere: + reveals the attach and GIF buttons, which tuck away while typing. Also fixes linked toasts never receiving clicks (pointer-events). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+137
-1
@@ -217,7 +217,7 @@ def test_paste_image_attaches_in_chat(alice):
|
||||
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="visible", timeout=10000
|
||||
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(
|
||||
@@ -550,3 +550,139 @@ def test_scroll_stays_pinned_to_bottom_for_active_reader(alice, bob):
|
||||
"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):
|
||||
page.evaluate(
|
||||
"async ([uid, text]) => {"
|
||||
" const body = new URLSearchParams({receiver_uid: uid, content: text});"
|
||||
" await fetch('/messages/send', {method: 'POST', body, headers: {Accept: 'application/json'}});"
|
||||
"}",
|
||||
[receiver_uid, content],
|
||||
)
|
||||
|
||||
|
||||
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(force=True)
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user