refactor(registry): 生产环境数据库访问迁移至 SQLx 并统一测试端口策略 将 rusqlite 从生产依赖移至 dev-dependencies,正式数据库操作全部 由 SQLx 完成;rusqlite 仅保留用于测试夹具及旧数据库兼容验证。 UI 验收脚本移除 HTTP 代理和动态端口分配,统一通过 ui-test-port.mjs 的 assertUiPortAvailable 直连 8787 端口, 确保测试与正式实例串行执行。 新增 doc/registry/rust/axum-sqlx-architecture.md 记录模块职责、 数据兼容、退出资源回收及验证维护规范。 修复接收器页面按钮缺少显式 height 导致的布局偏差。 ```
76 lines
5.2 KiB
JavaScript
76 lines
5.2 KiB
JavaScript
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));
|
|
}
|