parastoo-dashboards/parastoo_dashboard/audit_gate2.py

63 lines
No EOL
3.1 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": 1600, "height": 1100}, device_scale_factor=1.5)
errs = []
pg.on("pageerror", lambda e: errs.append(f"PAGEERR {e}"))
pg.on("console", lambda m: errs.append(f"CONSOLE {m.text}") if m.type == "error" else None)
await pg.goto("https://parastoo.zebellkhan.com/", wait_until="networkidle", timeout=90000)
await pg.wait_for_timeout(3000)
# count overlays BEFORE
before = await pg.evaluate("() => document.querySelectorAll('.overlay').length")
# seed a pending row and call the gate; inspect ALL overlays
gate = await pg.evaluate("""async () => {
const t = {id:'gate-'+Date.now(), title:'تست دروازه تایید — طراحی استوری',
cat:'instagram', est:1, act:1.5, status:'done', pri:'mid', note:'',
adhoc:true, date:new Date().toISOString().slice(0,10),
synced_jira:true, synced_sheet:false};
tasks.push(t);
if (typeof renderSync==='function') renderSync();
syncSheet();
await new Promise(r => setTimeout(r, 1500));
const ovs = [...document.querySelectorAll('.overlay')];
return {
overlayCount: ovs.length,
titles: ovs.map(o => o.querySelector('.modal-title')?.innerText || '(none)'),
gateOverlay: (() => {
const g = ovs.find(o => (o.querySelector('.modal-title')?.innerText || '').includes('شیت گوگل'));
if (!g) return null;
return {
title: g.querySelector('.modal-title').innerText,
body: g.querySelector('.modal-body').innerText.replace(/\\s+/g,' ').slice(0,160),
confirm: !!g.querySelector('#cfmOk'),
cancel: !!g.querySelector('#cfmNo')
};
})()
};
}""")
print(json.dumps({"overlaysBefore": before, "gate": gate}, ensure_ascii=False, indent=2))
# click cancel on the GATE overlay specifically, then assert rollback
res = await pg.evaluate("""async () => {
const ovs = [...document.querySelectorAll('.overlay')];
const g = ovs.find(o => (o.querySelector('.modal-title')?.innerText||'').includes('شیت گوگل'));
if (!g) return {found:false};
g.querySelector('#cfmNo').click();
await new Promise(r => setTimeout(r, 900));
const remaining = [...document.querySelectorAll('.overlay')]
.map(o => o.querySelector('.modal-title')?.innerText || '(none)');
return {found:true, clickedCancel:true, remainingOverlays: remaining,
sheetStatus: document.getElementById('sheetStatus').innerText,
stillUnsynced: tasks.filter(t=>!t.synced_sheet).length};
}""")
print(json.dumps(res, ensure_ascii=False, indent=2))
print("errors:", errs[:5])
await b.close()
asyncio.run(main())