71 lines
5.9 KiB
JavaScript
71 lines
5.9 KiB
JavaScript
// Run with existing Playwright tooling; no application dependency is added.
|
|
const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright');
|
|
import fs from 'node:fs';
|
|
const out='docs/hel-892/ui-evidence'; fs.mkdirSync(out,{recursive:true});
|
|
const browser=await chromium.launch({...(process.env.BROWSER_EXECUTABLE ? {executablePath:process.env.BROWSER_EXECUTABLE} : {}),headless:true});
|
|
const page=await browser.newPage({viewport:{width:1440,height:1000}});
|
|
const writes=[],errors=[];
|
|
page.on('request',r=>{if(r.url().includes('/api/')&&r.method()!=='GET')writes.push(r.method()+' '+r.url());});
|
|
page.on('pageerror',e=>errors.push(e.message));
|
|
const records=await (await fetch('http://127.0.0.1:8247/api/workflows')).json();
|
|
const api=records.find(x=>x.import_state==='pending_check'&&x.name.includes('4ref'))??records.find(x=>x.import_state==='pending_check');
|
|
const ui=records.find(x=>x.import_state==='needs_conversion'&&x.name.includes('Qwen'));
|
|
function assert(ok,label){if(!ok)throw new Error(label); console.log('PASS '+label);}
|
|
await page.goto('http://127.0.0.1:5173/connections',{waitUntil:'networkidle'});
|
|
assert(await page.getByRole('button',{name:'说明',exact:true}).count()===158,'156实际条目及2个旧数据夹具均有说明入口');
|
|
assert(await page.locator('button[title="待可靠转换,暂不可执行;可打开说明"]:disabled').count()===146,'146份待转换条目测试入口保持拦截');
|
|
assert(await page.locator('.wf-name').first().evaluate(el=>el.getBoundingClientRect().width>=150),'桌面列表名称保持可见宽度');
|
|
await page.screenshot({path:out+'/01-library.png'});
|
|
async function open(wf){
|
|
const row=page.locator('.wf-row').filter({has:page.locator('.wf-name').filter({hasText:wf.name})}).first();
|
|
const button=row.getByRole('button',{name:'说明',exact:true});
|
|
await button.focus(); await page.keyboard.press('Enter');
|
|
const dialog=page.getByRole('dialog',{name:'工作流说明'});await dialog.getByText('用途与来源',{exact:true}).waitFor();
|
|
await dialog.evaluate(el=>Promise.all(el.getAnimations().map(animation=>animation.finished)));
|
|
return {dialog,button,row};
|
|
}
|
|
let {dialog,button}=await open(api);
|
|
assert((await dialog.innerText()).includes('说明未定稿')&&(await dialog.innerText()).includes('未验证实跑'),'状态分立且无虚构完成');
|
|
assert((await dialog.innerText()).includes('未检查'),'依赖未检查如实展示');
|
|
await dialog.locator('summary').filter({hasText:'节点 166 · shift_video'}).click();
|
|
assert((await dialog.innerText()).includes('语义待确认'),'未确认参数分类');
|
|
await page.screenshot({path:out+'/02-api-parameter.png'});
|
|
await dialog.locator('.drawer-body').evaluate(el=>el.scrollTop=0);
|
|
await page.screenshot({path:out+'/05-api-overview.png'});
|
|
await page.keyboard.press('Escape');await dialog.waitFor({state:'hidden'});
|
|
await page.waitForFunction(el=>el===document.activeElement,await button.elementHandle());
|
|
assert(await button.evaluate(el=>el===document.activeElement),'Esc关闭并归还焦点');
|
|
({dialog,button}=await open(ui));
|
|
assert((await dialog.innerText()).includes('待转换 / 待补材料'),'UI待转换说明可阅读');
|
|
await page.screenshot({path:out+'/06-ui-overview.png'});
|
|
const body=dialog.locator('.drawer-body');await body.evaluate(el=>el.scrollTop=el.scrollHeight);
|
|
await page.screenshot({path:out+'/03-ui-notes.png'});
|
|
await page.keyboard.press('Escape');
|
|
for (const name of ['旧工作流回退(隔离测试夹具)','空说明回退(隔离测试夹具)']){
|
|
({dialog}=await open({name})); assert((await dialog.innerText()).includes('隔离库旧条目回退测试'),'旧/空说明回退 '+name);
|
|
await page.keyboard.press('Escape');
|
|
}
|
|
// A failed GET must be recoverable without showing stale content.
|
|
await page.route('**/api/workflows/'+api.id,route=>route.fulfill({status:500,body:'{"detail":"隔离失败夹具"}',contentType:'application/json'}));
|
|
await page.locator('.wf-row').filter({hasText:api.name}).first().getByRole('button',{name:'说明',exact:true}).click();
|
|
await page.getByRole('alert').waitFor({timeout:15000}); assert(await page.getByRole('button',{name:'重试',exact:true}).isVisible(),'读取失败可重试');
|
|
await page.unroute('**/api/workflows/'+api.id);await page.getByRole('button',{name:'重试',exact:true}).click();await page.getByRole('dialog').getByText('用途与来源',{exact:true}).waitFor();await page.keyboard.press('Escape');
|
|
await page.setViewportSize({width:390,height:844});
|
|
({dialog,button}=await open(api));
|
|
await dialog.locator('summary').filter({hasText:'模型引用('}).click();
|
|
await dialog.locator('summary').filter({hasText:'模型引用('}).scrollIntoViewIfNeeded();
|
|
assert(await dialog.evaluate(el=>el.scrollWidth<=el.clientWidth),'窄屏抽屉无横向溢出');
|
|
assert(await dialog.locator('.drawer-body').evaluate(el=>el.scrollWidth<=el.clientWidth),'窄屏正文长模型无横向溢出');
|
|
assert(await dialog.evaluate(el=>Math.round(el.getBoundingClientRect().width)===390),'窄屏全宽');
|
|
await page.screenshot({path:out+'/04-narrow-models.png'});
|
|
await dialog.getByRole('button',{name:'关闭',exact:true}).focus();await page.keyboard.press('Tab');
|
|
assert(await dialog.evaluate(el=>el.contains(document.activeElement)),'Tab焦点限制在抽屉');
|
|
await page.keyboard.press('Shift+Tab');assert(await dialog.evaluate(el=>el.contains(document.activeElement)),'Shift Tab焦点限制');
|
|
await page.keyboard.press('Escape');
|
|
assert(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),'窄屏列表无横向溢出');
|
|
await page.emulateMedia({reducedMotion:'reduce'});({dialog}=await open(ui));
|
|
assert(await dialog.evaluate(el=>getComputedStyle(el).animationName.includes('drawer-fade')),'减少动态偏好取消位移');
|
|
assert(writes.length===0,'阅读全程无写请求或生成请求');assert(errors.length===0,'浏览器无脚本错误');
|
|
fs.writeFileSync(out+'/browser-results.json',JSON.stringify({api:{id:api.id,name:api.name},ui:{id:ui.id,name:ui.name},rows:records.length,writes,errors},null,2));
|
|
await browser.close();
|