Fix Console language support and named frame monitoring cards
This commit is contained in:
@@ -168,3 +168,13 @@ def test_current_frame_flow_api_contract(tmp_path):
|
||||
m["key"] == "service_ready" and m["value"] == 1 for m in snapshot["metrics"]
|
||||
)
|
||||
assert any(r["type"] == "device" for r in snapshot["resources"])
|
||||
|
||||
|
||||
def test_metric_and_alert_labels_follow_console_language(endpoint):
|
||||
device, _, _ = endpoint
|
||||
snapshot = worker.collect(device)
|
||||
assert all(set(metric["label"]) == {"zh", "en"} for metric in snapshot["metrics"])
|
||||
assert all(set(alert["label"]) == {"zh", "en"} for alert in snapshot["alerts"])
|
||||
frame = next(r for r in snapshot["resources"] if r["type"] == "device")
|
||||
assert frame["id"] == "device:frame"
|
||||
assert frame["name"] == "Frame"
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
const {chromium}=require('playwright');
|
||||
const fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict');
|
||||
(async()=>{
|
||||
const browser=await chromium.launch({headless:true,channel:'chrome'});
|
||||
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:[]}};
|
||||
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/');
|
||||
const result=await page.evaluate(({source,entry,lang})=>{
|
||||
const state={LANG:lang};const text=(zh,en)=>lang==='zh'?zh:en;
|
||||
const esc=v=>String(v??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[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};
|
||||
},{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);
|
||||
await page.close();
|
||||
}
|
||||
console.log('6 browser checks passed');
|
||||
} finally {await browser.close()}
|
||||
})().catch(e=>{console.error(e);process.exit(1)});
|
||||
Reference in New Issue
Block a user