import {UI_URL, assertUiPortAvailable} from './ui-test-port.mjs'; const base=UI_URL; await assertUiPortAvailable(); // Appearance preview acceptance with an isolated database; no physical transports opened. import {mkdtemp} from 'node:fs/promises'; import {tmpdir} from 'node:os'; import path from 'node:path'; import {spawn} from 'node:child_process'; import {createRequire} from 'node:module'; import assert from 'node:assert/strict'; const {chromium}=createRequire(import.meta.url)('playwright'); const root=await mkdtemp(path.join(tmpdir(),'RID-appearance-preview-')); const exe=process.argv[2]||'D:/Rust_Contact/util/target/Rid_Drone_Receivev/release/fpv-rid-registry-fullstack.exe'; let child,browser,output='';const errors=[]; const wait=ms=>new Promise(r=>setTimeout(r,ms)); function start(){child=spawn(exe,['--data-root',root,'--simulation-api'],{env:{...process.env,PATH:'C:\\Windows\\System32'},windowsHide:true,stdio:['ignore','pipe','pipe']});child.stdout.on('data',b=>output+=b);child.stderr.on('data',b=>output+=b);child.on('error',e=>output+=e.message)} async function stop(){if(child&&child.exitCode===null){const done=new Promise(r=>child.once('exit',r));child.kill();await done}} async function ready(){for(let i=0;i<150;i++){if(child.exitCode!==null)throw Error(output);try{if((await fetch(base+'/api/appearance')).ok)return}catch{}await wait(100)}throw Error('server timeout '+output)} let report={}; try { start();await ready(); browser=await chromium.launch({headless:true,channel:'msedge'}); const page=await browser.newPage({viewport:{width:1600,height:1000}}); page.on('pageerror',e=>errors.push(e.message)); await page.goto(base);await page.locator('#home-app-settings').click(); assert.equal(await page.locator('.glass-material-note').count(),0); const caption=await page.locator('#appearance-wallpapers').boundingBox(); const heading=await page.locator('.setting-content .setting-panel-head').boundingBox(); assert.ok(caption.y-heading.y-heading.height<35); for(const [wall,name] of [['B5','晴空流光'],['B6','晨雾青山'],['B7','暖沙光影']]){ await page.locator(`[data-wall=${wall}]`).click(); await page.locator('#wall-message').filter({hasText:'已保存到本机应用'}).waitFor(); assert.equal((await (await fetch(base+'/api/appearance')).json()).wallpaper,wall); for(const id of ['appearance-wallpaper','workspace-wallpaper']){ assert.equal(await page.locator('#'+id).getAttribute('src'),`/wallpapers/${wall}-wallpaper.svg`); await page.waitForFunction(id=>{const e=document.getElementById(id);return e.complete&&e.naturalWidth>0},id); } assert.equal(await page.locator('#appearance-wallpaper-name').innerText(),name); } const preview=page.locator('#desktop-sample'); await page.locator('.reference-rail [data-open=display]').click(); const before=await preview.screenshot(); await page.locator('#dim').fill('45');await page.locator('#dim').dispatchEvent('input'); await page.locator('#wall-message').filter({hasText:'已保存到本机应用'}).waitFor(); assert.equal(await page.locator('#appearance-dim-value').innerText(),'45%'); assert.notDeepEqual(await preview.screenshot(),before); await page.locator('#blur').fill('8');await page.locator('#blur').dispatchEvent('input'); await page.locator('#wall-message').filter({hasText:'已保存到本机应用'}).waitFor(); assert.equal(await page.locator('#appearance-wallpaper').evaluate(e=>getComputedStyle(e).filter),'blur(8px)'); await page.locator('#fit').selectOption('contain'); await page.locator('#wall-message').filter({hasText:'已保存到本机应用'}).waitFor(); assert.equal(await page.locator('#appearance-wallpaper').evaluate(e=>getComputedStyle(e).objectFit),'contain'); await page.reload();await page.locator('#home-app-settings').click(); await page.locator('#desktop-sample').waitFor(); assert.equal(await page.locator('#appearance-wallpaper-name').innerText(),'暖沙光影'); assert.equal(await page.locator('#appearance-dim-value').innerText(),'45%'); assert.equal(await page.locator('#appearance-blur-value').innerText(),'8 px'); assert.equal(await page.locator('#appearance-fit-value').innerText(),'完整显示'); await page.locator('.reference-rail [data-open=settings]').click(); await page.locator('[data-wall=B5]').click(); await page.locator('.reference-rail [data-open=display]').click(); await page.locator('#dim').fill('14');await page.locator('#dim').dispatchEvent('input'); await page.locator('#blur').fill('0');await page.locator('#blur').dispatchEvent('input'); await page.locator('#fit').selectOption('cover'); await page.locator('#wall-message').filter({hasText:'已保存到本机应用'}).waitFor(); await page.screenshot({path:path.join(root,'appearance-wide.png')}); for(const width of [1000,700]){ await page.setViewportSize({width,height:1000}); assert.equal(await page.locator('#desktop-sample').isVisible(),true); assert.ok(await page.evaluate(()=>document.getElementById('appearance-view').scrollWidth<=document.getElementById('appearance-view').clientWidth+1)); } assert.deepEqual(errors,[]);report={passed:true,root,checks:['bright wallpapers','preview pixels change','dim','blur','fit','reload persistence','responsive widths']}; } finally { await browser?.close();await stop();console.log(JSON.stringify(report)); }