parastoo-dashboards/parastoo_dashboard/test_server_tasks.py

45 lines
No EOL
1.9 KiB
Python

import asyncio, json
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
b = await p.chromium.launch(args=["--no-sandbox"])
pg = await b.new_page(viewport={"width": 1440, "height": 950})
errs = []
pg.on("pageerror", lambda e: errs.append(str(e)))
logs = []
pg.on("console", lambda m: logs.append(f"[{m.type}] {m.text}"))
await pg.goto("https://parastoo.zebellkhan.com/", wait_until="networkidle", timeout=90000)
# wait for pullServerTasks (fires at 1200ms after init)
await pg.wait_for_timeout(6000)
merged = await pg.evaluate("""() => {
const srv = tasks.filter(t=>t.from_server);
return {serverTasks: srv.length, titles: srv.map(t=>t.title),
total: tasks.length};
}""")
print("MERGED FROM SERVER:", json.dumps(merged, ensure_ascii=False, indent=1))
print("pull logs:", [l for l in logs if 'pullServerTasks' in l])
# verify the tasks are visible in the calendar
await pg.click('#tabs button[data-view="calendar"]')
await pg.wait_for_timeout(1500)
cal = await pg.evaluate("""() => {
const t=document.querySelector('.day.today');
return {today: t?.querySelector('.day-num')?.innerText?.replace(/\\s+/g,' '),
tasks: [...(t?.querySelectorAll('.mini-task')||[])].map(x=>x.innerText.trim())};
}""")
print("\nCALENDAR TODAY:", json.dumps(cal, ensure_ascii=False, indent=1))
# and the server store should now be empty (acked)
acked = await pg.evaluate("""async () => {
const r = await fetch('/api/tasks/list',{cache:'no-store'});
const j = await r.json();
return {remaining: j.count};
}""")
print("\nSERVER STORE AFTER ACK:", json.dumps(acked, ensure_ascii=False))
print("JS ERRORS:", errs[:3])
await b.close()
asyncio.run(main())