Files
movim-rs/tests/e2e/browser_files.py
T
2026-10-24 17:46:20 +07:00

101 lines
4.7 KiB
Python

"""Search (clear and OMEMO messages) and the shared files drawer, on a phone screen."""
import asyncio, os
from playwright.async_api import async_playwright
from browser import login, BASE, OUT
S = os.path.dirname(os.path.abspath(__file__))
PHONE = {"width": 390, "height": 844}
async def upload(page, path):
await page.evaluate("Upload_ajaxGetPanel()")
await page.wait_for_selector("#upload", timeout=10000)
await page.set_input_files("input#file", path)
await page.wait_for_timeout(1500)
await page.click("#upload_button")
await page.wait_for_timeout(4000)
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
actx, alice, aerr = await login(browser, "alice@localhost", "alicepass", "filesalice")
bctx, bob, berr = await login(browser, "bob@localhost", "bobpass", "filesbob")
await alice.wait_for_timeout(4000)
# Clear text messages and files
await alice.goto(BASE + "/chat/bob@localhost")
await alice.wait_for_selector("#chat_textarea", timeout=15000)
await alice.wait_for_timeout(2000)
await alice.fill("#chat_textarea", "Xin chào Bob, hẹn gặp lại")
await alice.press("#chat_textarea", "Enter")
await alice.wait_for_timeout(1500)
await upload(alice, f"{S}/test.png")
await upload(alice, f"{S}/notes.txt")
# OMEMO messages and an encrypted picture
await alice.evaluate("ChatOmemo.enableContactState('bob@localhost', false)")
await alice.wait_for_timeout(5000)
print("alice omemo:", await alice.evaluate("Chat.getOmemoState()"))
await alice.fill("#chat_textarea", "Bí mật: CHÀO buổi sáng")
await alice.press("#chat_textarea", "Enter")
await alice.wait_for_timeout(3000)
await upload(alice, f"{S}/test.png")
# Bob reads them (decrypted into his browser), on a phone
await bob.set_viewport_size(PHONE)
await bob.goto(BASE + "/chat/alice@localhost")
await bob.wait_for_selector("#chat_textarea", timeout=15000)
await bob.wait_for_timeout(6000)
await bob.screenshot(path=f"{OUT}/files_1_chat_phone.png")
print("bob bubbles:", (await bob.locator("#chat_widget .bubble p").all_inner_texts())[-4:])
# Search, without accents: finds the clear and the encrypted message
await bob.evaluate("ChatActions_ajaxShowSearchDialog('alice@localhost', false)")
await bob.wait_for_selector("form[name=search] input", timeout=10000)
await bob.wait_for_timeout(1000)
await bob.fill("form[name=search] input", "chao")
await bob.wait_for_timeout(3000)
print("search 'chao':", await bob.locator("#chat_search #message_preview li p").all_inner_texts())
await bob.screenshot(path=f"{OUT}/files_2_search_phone.png")
await bob.evaluate("Drawer.clear()")
await bob.wait_for_timeout(1000)
# Shared files
await bob.evaluate("ChatActions_ajaxShowFiles('alice@localhost', false)")
await bob.wait_for_selector("#chat_files", timeout=10000)
await bob.wait_for_timeout(5000)
for tab in ("images", "videos", "recordings", "files"):
count = await bob.locator(f"#chat_files [data-list={tab}] > li").count()
print(f"files {tab}:", count)
await bob.screenshot(path=f"{OUT}/files_3_images_phone.png")
await bob.evaluate("ChatActions.filesTab('files')")
await bob.wait_for_timeout(500)
await bob.screenshot(path=f"{OUT}/files_4_files_phone.png")
await bob.evaluate("ChatActions.filesTab('videos')")
await bob.wait_for_timeout(500)
await bob.screenshot(path=f"{OUT}/files_5_empty_phone.png")
await bob.evaluate("Drawer.clear()")
await bob.wait_for_timeout(1000)
# On a phone the files button moves to the menu
await bob.click("#chat_widget header .show_context_menu")
await bob.wait_for_timeout(1000)
print("phone: header button", await bob.locator("#chat_widget header .files_button").first.is_visible(),
"| menu item", await bob.locator("#chat_widget li.files_menu").first.is_visible())
await bob.screenshot(path=f"{OUT}/files_6_menu_phone.png")
await bob.keyboard.press("Escape")
await bob.set_viewport_size({"width": 1400, "height": 900})
await bob.wait_for_timeout(1000)
print("desktop: header button", await bob.locator("#chat_widget header .files_button").first.is_visible())
await bob.set_viewport_size(PHONE)
width = await bob.evaluate("document.documentElement.scrollWidth")
print("page width:", width, "(viewport 390)")
for e in aerr + berr:
print(e)
await browser.close()
asyncio.run(main())