124 lines
5.6 KiB
Python
124 lines
5.6 KiB
Python
import asyncio, os, json
|
||
from playwright.async_api import async_playwright
|
||
|
||
OUT = "/workspace/parastoo_dashboard/audit"
|
||
os.makedirs(OUT, exist_ok=True)
|
||
|
||
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)
|
||
await pg.goto("https://parastoo.zebellkhan.com/", wait_until="networkidle", timeout=60000)
|
||
await pg.wait_for_timeout(2000)
|
||
|
||
report = {}
|
||
|
||
# --- 1. overflow / clipping detection (horizontal) ---
|
||
clip = await pg.evaluate("""() => {
|
||
const bad = [];
|
||
const sw = document.documentElement.scrollWidth;
|
||
const cw = document.documentElement.clientWidth;
|
||
if (sw > cw + 2) bad.push({el:'DOCUMENT', sw, cw, over: sw-cw});
|
||
document.querySelectorAll('.card,.kpi,.day,.task-row,.phase,.heat-cell,.col-box,.modal,.btn,.tag,.sync-box').forEach(el=>{
|
||
if(el.scrollWidth > el.clientWidth + 2 && getComputedStyle(el).overflowX === 'visible'){
|
||
bad.push({el: el.className.slice(0,42), tag: el.tagName,
|
||
sw: el.scrollWidth, cw: el.clientWidth, over: el.scrollWidth-el.clientWidth,
|
||
txt: (el.innerText||'').slice(0,44).replace(/\\n/g,' / ')});
|
||
}
|
||
});
|
||
return bad;
|
||
}""")
|
||
report['horizontal_overflow'] = clip
|
||
|
||
# --- 2. vertical text clipping: any element whose text overflows its box ---
|
||
vclip = await pg.evaluate("""() => {
|
||
const bad = [];
|
||
document.querySelectorAll('.kpi-val,.kpi-label,.day-num,.mini-task,.task-title,.card-title,.phase-title,.cal-range,.kpi-foot,.tag').forEach(el=>{
|
||
const cs = getComputedStyle(el);
|
||
if(el.scrollHeight > el.clientHeight + 3 && cs.overflowY === 'hidden'){
|
||
bad.push({cls: el.className, txt:(el.innerText||'').slice(0,40), sh: el.scrollHeight, ch: el.clientHeight});
|
||
}
|
||
});
|
||
return bad;
|
||
}""")
|
||
report['vertical_clipping'] = vclip
|
||
|
||
# --- 3. font actually loaded (not fallback) ---
|
||
font = await pg.evaluate("""async () => {
|
||
await document.fonts.ready;
|
||
const loaded = [];
|
||
document.fonts.forEach(f => loaded.push(f.family + ' ' + f.weight + ' ' + f.status));
|
||
const el = document.querySelector('.card-title');
|
||
const cs = getComputedStyle(el);
|
||
return {faces: loaded, computed: cs.fontFamily, size: cs.fontSize};
|
||
}""")
|
||
report['fonts'] = font
|
||
|
||
# --- 4. all Plotly charts have real traces ---
|
||
charts = await pg.evaluate("""() => {
|
||
const out = [];
|
||
document.querySelectorAll('.js-plotly-plot').forEach(el=>{
|
||
const visible = el.offsetParent !== null;
|
||
const traces = (el.data||[]).map(t=>({
|
||
type: t.type,
|
||
n: (t.x?t.x.length:0) || (t.labels?t.labels.length:0),
|
||
sum: t.y ? t.y.reduce((a,b)=>a+(Number(b)||0),0) : (t.values?t.values.reduce((a,b)=>a+(Number(b)||0),0):0)
|
||
}));
|
||
out.push({id: el.id, visible, traces, w: el.clientWidth, h: el.clientHeight});
|
||
});
|
||
return out;
|
||
}""")
|
||
report['charts'] = charts
|
||
|
||
# --- 5. KPI text exact values + unit rendering ---
|
||
kpis = await pg.evaluate("""() => {
|
||
const r = [];
|
||
document.querySelectorAll('#view-dashboard .kpi').forEach(k=>{
|
||
r.push({label: k.querySelector('.kpi-label')?.innerText,
|
||
val: k.querySelector('.kpi-val')?.innerText,
|
||
foot: k.querySelector('.kpi-foot')?.innerText});
|
||
});
|
||
return r;
|
||
}""")
|
||
report['kpis'] = kpis
|
||
|
||
# --- 6. Persian digits check everywhere ---
|
||
digits = await pg.evaluate("""() => {
|
||
const body = document.body.innerText;
|
||
const latin = (body.match(/[0-9]/g)||[]).length;
|
||
const persian = (body.match(/[۰-۹]/g)||[]).length;
|
||
const samples = [];
|
||
// find where latin digits are
|
||
document.querySelectorAll('*').forEach(el=>{
|
||
if(el.children.length===0 && el.innerText && /[0-9]/.test(el.innerText) && samples.length<8){
|
||
samples.push({cls: el.className.slice(0,30), txt: el.innerText.slice(0,40)});
|
||
}
|
||
});
|
||
return {latinCount: latin, persianCount: persian, latinSamples: samples};
|
||
}""")
|
||
report['digits'] = digits
|
||
|
||
# --- 7. per-view render health ---
|
||
viewhealth = {}
|
||
for vid in ["dashboard","calendar","weekly","monthly","roadmap","sync"]:
|
||
await pg.click(f'nav.tabs button[data-view="{vid}"]')
|
||
await pg.wait_for_timeout(1400)
|
||
h = await pg.evaluate("""(vid) => {
|
||
const v = document.getElementById('view-'+vid);
|
||
const visible = v.offsetParent !== null;
|
||
const emptyish = v.innerText.trim().length;
|
||
let maxOver = 0, worst = '';
|
||
v.querySelectorAll('.card,.kpi,.day,.task-row,.phase,.heat-cell,.col-box,table,.modal').forEach(el=>{
|
||
const o = el.scrollWidth - el.clientWidth;
|
||
if(o > 2 && getComputedStyle(el).overflowX==='visible' && o>maxOver){ maxOver=o; worst=el.className.slice(0,40); }
|
||
});
|
||
return {visible, textLen: emptyish, maxOverflow: maxOver, worstEl: worst,
|
||
height: v.scrollHeight};
|
||
}""", vid)
|
||
viewhealth[vid] = h
|
||
report['view_health'] = viewhealth
|
||
|
||
print(json.dumps(report, ensure_ascii=False, indent=2))
|
||
await b.close()
|
||
|
||
asyncio.run(main())
|