Flatten monitoring cards and align frame subtitle with Console

This commit is contained in:
way
2026-10-17 23:31:38 +08:00
parent f45eefa31b
commit c1459aef45
6 changed files with 39 additions and 8 deletions
+7 -1
View File
@@ -6,6 +6,8 @@ try {
const source=fs.readFileSync(path.join(__dirname,'../plugin/ui/index.js'),'utf8').replace(/^import .*;\n/gm,'').replace('export function hostCard','function hostCard');
const labels={service_ready:{zh:'服务就绪',en:'Service ready'},device_online:{zh:'画框在线',en:'Frame online'},battery_percent:{zh:'电量',en:'Battery'}};
const entry={host:{name:'Frame Flow'},dataCurrent:true,snapshot:{resources:[{id:'service',name:'Frame Flow',type:'service'},{id:'device:living-room',name:'渡口浪人的相框',type:'device'}],metrics:[{resource_id:'service',key:'service_ready',value:1,unit:'boolean',label:labels.service_ready},{resource_id:'device:living-room',key:'device_online',value:1,unit:'boolean',label:labels.device_online},{resource_id:'device:living-room',key:'battery_percent',value:28,unit:'percent',label:labels.battery_percent}],alerts:[]}};
entry.snapshot.resources.push({id:'job:slideshow',name:'家庭照片轮播',type:'job'});
entry.snapshot.metrics.push({resource_id:'job:slideshow',key:'job_enabled',value:1,unit:'boolean'},{resource_id:'job:slideshow',key:'last_run_success',value:1,unit:'boolean'});
for(const lang of ['zh','en'])for(const width of [1440,820,390]) {
const page=await browser.newPage({viewport:{width,height:1000}});
await page.goto('http://192.168.89.19/');
@@ -14,12 +16,16 @@ const result=await page.evaluate(({source,entry,lang})=>{
const esc=v=>String(v??'').replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
const html=eval(source+'\nhostCard(entry)');
document.body.innerHTML=`<main style="max-width:100%;padding:16px">${html}</main>`;
return {text:document.body.innerText,overflow:document.documentElement.scrollWidth>innerWidth};
return {text:document.body.innerText,overflow:document.documentElement.scrollWidth>innerWidth,subtitle:document.querySelector(".host-head .device-details")?.textContent,nested:document.querySelectorAll(".group .metric, .metric .metric").length,status:document.querySelector(".metric [data-semantic]")?.textContent};
},{source,entry,lang});
assert(result.text.includes('渡口浪人的相框'));
assert(!result.text.includes('living-room'));
assert(result.text.includes(lang==='zh'?'服务就绪':'Service ready'));
assert.equal(result.overflow,false);
assert.equal(result.nested,0);
assert.equal(result.subtitle,'渡口浪人的相框');
assert.equal(result.status,lang==='zh'?'正常':'Normal');
assert(result.text.includes(lang==='zh'?'轮播任务':'Slideshow task'));
await page.close();
}
console.log('6 browser checks passed');