forked from mtusi2026/mtusi2026lab6
14 lines
1.1 KiB
TypeScript
14 lines
1.1 KiB
TypeScript
export function dashboardMatches(actual:any,expected:any):boolean{
|
|
const panels=actual?.dashboard?.panels,configured=expected?.panels;
|
|
if(typeof expected?.uid!=='string'||actual?.dashboard?.uid!==expected.uid||!Array.isArray(panels)||!Array.isArray(configured)||!configured.length||panels.length!==configured.length)return false;
|
|
const valid=(p:any)=>Number.isSafeInteger(p?.id)&&p.id>0&&typeof p.title==='string'&&p.title.length>0;
|
|
if(!configured.every(valid)||!panels.every(valid))return false;
|
|
const wanted=new Map(configured.map(p=>[p.id,p.title]));
|
|
return wanted.size===configured.length&&new Set(panels.map(p=>p.id)).size===panels.length&&panels.every(p=>wanted.get(p.id)===p.title);
|
|
}
|
|
export function rulesMatch(actual:any,expected:string[]):boolean{
|
|
if(!Array.isArray(actual)||!Array.isArray(expected)||!expected.length||actual.length!==expected.length||!expected.every(v=>typeof v==='string'&&v.length>0))return false;
|
|
const wanted=new Set(expected),got=new Set(actual.map(row=>row?.uid));
|
|
return wanted.size===expected.length&&got.size===actual.length&&[...got].every(uid=>wanted.has(uid));
|
|
}
|