Initial commit: WidgetWorkbench HMI V4

This commit is contained in:
chris
2026-10-20 20:15:46 +00:00
commit 6eb3f8fa4f
118 changed files with 16523 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {pathToFileURL} from 'node:url';
import ts from 'typescript';
const source=fs.readFileSync(new URL('../src/widgets/mesClient.ts',import.meta.url),'utf8');
const javascript=ts.transpileModule(source,{fileName:'mesClient.ts',compilerOptions:{target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.ESNext}}).outputText;
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'mes-check-'));const file=path.join(dir,'client.mjs');fs.writeFileSync(file,javascript);
try{
globalThis.window={location:{origin:'https://demo.local'},setTimeout,clearTimeout};
globalThis.location={origin:'https://demo.local'};
globalThis.sessionStorage={getItem(k){return k==='globallogin'?JSON.stringify({result:{sessionContext:{sessionId:'T-1',persId:'P-1'}}}):k==='url'?'https://demo.local':null}};
const lib=await import(pathToFileURL(file).href);
assert.equal(lib.structuredRows([1,'A',2,'B'],['x','y']).length,2);
assert.throws(()=>lib.structuredRows([1,2,3],['x','y']),/Ergebnis-Keys/);
assert.equal(lib.normalizeLayer('TOP'),'0');assert.equal(lib.layerLabel('2'),'INDEPENDENT');
assert.equal(lib.stationValid('../bad'),false);assert.equal(lib.serialValid('36051005094090005'),true);
const actions=[];
globalThis.fetch=async(url,opts)=>{const name=String(url).split('/').at(-1);const request=JSON.parse(opts.body);actions.push([name,request]);
const response=name==='trGetSerialNumberHistoryData'?{return_value:0,bookingResultValues:['S1','0','Werk','01','ST','WO','Montage','1',1000,'0','5','2'],failureDataResultValues:[],failureSlipDataResultValues:[],measureDataResultValues:[]}:
{return_value:0,mergePartsResultValues:[],setupResultValues:[]};
return {ok:true,json:async()=>({result:response})};};
const h=await lib.getHistory('ST','S1');assert.equal(h.sections.booking.length,1);assert.equal(actions.length,3);assert.equal(actions[0][1].desolvingSerialNumber,'1');
globalThis.fetch=async()=>({ok:true,json:async()=>({result:{return_value:-110,errorString:'Serial not found'}})});
await assert.rejects(()=>lib.getHistory('ST','S1'),error=>error instanceof lib.MesError&&error.code===-110);
console.log('MES client tests passed (parsing, session, normalized layer, 6 data requests, error codes)');
}finally{fs.rmSync(dir,{recursive:true,force:true});}