Initial commit: update3
This commit is contained in:
19
hmi-frontend/tests/bootstrap-contract.mjs
Normal file
19
hmi-frontend/tests/bootstrap-contract.mjs
Normal file
@@ -0,0 +1,19 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
const read=(p)=>fs.readFileSync(new URL(p,import.meta.url),'utf8');
|
||||
const role=read('../../backend/src/main/java/com/workbenchclassic/hmi/HmiRolesResource.java');
|
||||
const claim=read('../../backend/src/main/java/com/workbenchclassic/hmi/HmiBootstrapResource.java');
|
||||
const logic=read('../../backend/src/main/java/com/workbenchclassic/hmi/HmiInitialAdmin.java');
|
||||
const schema=read('../../backend/src/main/java/com/workbenchclassic/hmi/HmiSchemaBootstrap.java');
|
||||
const ui=read('../src/App.vue');
|
||||
assert.match(role,/!HmiAuth\.admin\(request\)/,'Normal admin endpoint must still require an admin role');
|
||||
assert.match(claim,/HmiAuth\.user\(request\)/,'Bootstrap must require a logged-in MES identity');
|
||||
assert.match(claim,/HmiAuth\.csrf\(request\)/,'Bootstrap must enforce CSRF');
|
||||
assert.match(logic,/MessageDigest\.isEqual/,'One-time code must be compared in constant time');
|
||||
assert.match(logic,/BDE\.PERS_STAMM WHERE PERS_ID=/,'Bootstrap must confirm PERSON ID in MES datasource');
|
||||
assert.match(logic,/UPDLOCK, HOLDLOCK/,'SQL Server bootstrap claim must lock row');
|
||||
assert.match(logic,/FOR UPDATE/,'Oracle bootstrap claim must lock row');
|
||||
assert.match(logic,/codeDigest=null/,'Token must be cleared on success');
|
||||
assert.match(schema,/HMI_APP_BOOTSTRAP/,'Database bootstrap marker required');
|
||||
assert.match(ui,/identity\?\.bootstrapRequired/,'First-run setup must be surfaced in HMI');
|
||||
console.log('PASS bootstrap contract checks (source-level, not live database tests)');
|
||||
25
hmi-frontend/tests/futuristic-v54.mjs
Normal file
25
hmi-frontend/tests/futuristic-v54.mjs
Normal file
@@ -0,0 +1,25 @@
|
||||
import {readFileSync} from 'node:fs';
|
||||
import {resolve} from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
const src=f=>readFileSync(resolve(process.cwd(),f),'utf8');
|
||||
const catalog=src('src/widgets/catalog.ts');
|
||||
const allowlist=src('../backend/src/main/java/com/workbenchclassic/hmi/HmiApiResource.java');
|
||||
const renderer=src('src/widgets/WidgetRenderer.vue');
|
||||
const preset=src('src/widgets/presets.ts');
|
||||
const app=src('src/App.vue');
|
||||
const css=src('src/workbench-futuristic.css');
|
||||
const component=src('src/components/CurvedWorkbenchHeader.vue');
|
||||
for(const t of ['ui.curved-header','ui.neon-actions','ui.metal-panel']){
|
||||
assert.ok(catalog.includes(`type:'${t}'`),`${t} catalog`);
|
||||
assert.ok(allowlist.includes(`"${t}"`),`${t} Java allowlist`);
|
||||
assert.ok(renderer.includes(`widget.type==='${t}'`),`${t} renderer`);
|
||||
}
|
||||
assert.ok(app.includes("activeTheme==='neon'"),'global header only in neon');
|
||||
assert.ok(app.includes('ios'),'existing ios theme');
|
||||
assert.ok(preset.includes('neon-industrial'),'new preset');
|
||||
assert.ok(css.includes('prefers-reduced-motion'),'reduced-motion');
|
||||
assert.ok(css.includes(':focus-visible'),'visible keyboard focus');
|
||||
assert.ok(component.includes('<svg')&&component.includes('preserveAspectRatio="none"'),'scalable SVG header');
|
||||
assert.ok(src('src/widgets/NeonActionsWidget.vue').includes('FuturisticButton'),'uses shared button');
|
||||
assert.ok(!src('src/widgets/NeonActionsWidget.vue').includes('fetch('),'button widgets do not start REST requests');
|
||||
console.log('V5.4 futuristic theme registration checks: OK');
|
||||
45
hmi-frontend/tests/mes-client.mjs
Normal file
45
hmi-frontend/tests/mes-client.mjs
Normal file
@@ -0,0 +1,45 @@
|
||||
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';
|
||||
|
||||
// Native Widgets use the server-verified IMSAPI-HMI session, never sessionStorage.globallogin.
|
||||
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'mes-check-'));
|
||||
const widgetsDir=path.join(dir,'widgets');fs.mkdirSync(widgetsDir);
|
||||
const transpile=(source,fileName)=>ts.transpileModule(source,{fileName,compilerOptions:{target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.ESNext}}).outputText;
|
||||
const root=new URL('../src/',import.meta.url);
|
||||
const apiSource=fs.readFileSync(new URL('api.ts',root),'utf8');
|
||||
const mesSource=fs.readFileSync(new URL('widgets/mesClient.ts',root),'utf8');
|
||||
fs.writeFileSync(path.join(dir,'api.mjs'),transpile(apiSource,'api.ts'));
|
||||
fs.writeFileSync(path.join(widgetsDir,'mesClient.mjs'),transpile(mesSource,'mesClient.ts').replace("from '../api'","from '../api.mjs'"));
|
||||
try{
|
||||
const api=await import(pathToFileURL(path.join(dir,'api.mjs')).href);
|
||||
const lib=await import(pathToFileURL(path.join(widgetsDir,'mesClient.mjs')).href);
|
||||
assert.equal(lib.readMesSession(),null,'No implied login via browser storage');
|
||||
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 action=String(url).split('/').at(-1);
|
||||
const request=opts.body ? JSON.parse(opts.body):{};
|
||||
actions.push({action,request,headers:opts.headers});
|
||||
if(action==='csrf')return {ok:true,status:200,text:async()=>JSON.stringify({user:'worker',station:'ST',csrf:'secret-csrf',designer:false,publisher:false,admin:false})};
|
||||
const result=action==='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,status:200,text:async()=>JSON.stringify({result})};
|
||||
};
|
||||
await api.signInContext();
|
||||
assert.ok(lib.readMesSession(),'server-provided HMI identity recognized');
|
||||
const history=await lib.getHistory('ST','S1');assert.equal(history.sections.booking.length,1);
|
||||
const requests=actions.filter(a=>a.action!=='csrf');assert.equal(requests.length,3);
|
||||
assert.equal(requests[0].request.desolvingSerialNumber,'1');
|
||||
assert.equal(requests[0].request.sessionContext,undefined,'client must not serialize IMSAPI context');
|
||||
assert.equal(requests[0].headers['X-CSRF-Token'],'secret-csrf');
|
||||
globalThis.fetch=async()=>({ok:true,status:200,text:async()=>JSON.stringify({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('PASS: MES client uses server session/CSRF, parses normalized history, handles IMSAPI errors');
|
||||
}finally{fs.rmSync(dir,{recursive:true,force:true});}
|
||||
14
hmi-frontend/tests/navigation.mjs
Normal file
14
hmi-frontend/tests/navigation.mjs
Normal file
@@ -0,0 +1,14 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { navigationRoots,descendantPageIds } from '../src/navigation.ts';
|
||||
const p=(id,order,parentPageId=null,menuGroup='Fertigung')=>({id,key:id,title:id,order,parentPageId,menuGroup,enabled:true});
|
||||
const pages=[p('root',2),p('child',4,'root'),p('nested',1,'child'),p('second',1),p('outside',1,null,'Service')];
|
||||
const roots=navigationRoots(pages);
|
||||
assert.deepEqual(roots.map(r=>r.name),['Fertigung','Service']);
|
||||
assert.deepEqual(roots[0].children.map(n=>n.page.key),['second','root']);
|
||||
assert.deepEqual(roots[0].children[1].children.map(n=>n.page.key),['child']);
|
||||
assert.deepEqual(roots[0].children[1].children[0].children.map(n=>n.page.key),['nested']);
|
||||
assert.deepEqual([...descendantPageIds(pages,'root')].sort(),['child','nested']);
|
||||
assert.deepEqual(navigationRoots([p('cycle-a',1,'cycle-b'),p('cycle-b',2,'cycle-a')])[0].children.map(n=>n.page.key),['cycle-a','cycle-b']);
|
||||
const missing=navigationRoots([p('orphan',1,'not-existing')]);
|
||||
assert.equal(missing[0].children[0].page.key,'orphan');
|
||||
console.log('Navigation: 6 tests passed');
|
||||
21
hmi-frontend/tests/neon-theme.mjs
Normal file
21
hmi-frontend/tests/neon-theme.mjs
Normal file
@@ -0,0 +1,21 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
const dir=path.dirname(fileURLToPath(import.meta.url));
|
||||
const root=path.resolve(dir,'..');
|
||||
const read=p=>fs.readFileSync(path.join(root,p),'utf8');
|
||||
const app=read('src/App.vue'),types=read('src/types.ts'),main=read('src/main.ts'),css=read('src/workbench-neon.css'),server=read('../backend/src/main/java/com/workbenchclassic/hmi/HmiApiResource.java'),presets=read('src/widgets/presets.ts');
|
||||
assert.match(types, /'ios'\|'dark'\|'light'\|'system'\|'neon'/);
|
||||
assert.match(app, /chooseTheme\(/);
|
||||
assert.match(app, /value="neon">Workbench Neon/);
|
||||
assert.match(app, /@click="savePreferences"/);
|
||||
assert.match(app, /document\.body\.dataset\.hmiTheme=value/);
|
||||
assert.match(css, /\.shell\.neon\s*\{/);
|
||||
assert.match(css, /body\[data-hmi-theme='neon'\] \.wb-mes-dialog/);
|
||||
assert.match(css, /prefers-reduced-motion:reduce/);
|
||||
assert.match(main, /workbench-neon\.css/);
|
||||
assert.match(server, /!s\.equals\("neon"\)/);
|
||||
assert.match(presets, /neon-production/);
|
||||
assert.ok(fs.existsSync(path.join(root,'../hmi-examples/Workbench_Neon_Designvorschau.html')));
|
||||
console.log('Workbench Neon: 11 Theme-/Backend-/Preset-Prüfungen erfolgreich');
|
||||
23
hmi-frontend/tests/widget-package.mjs
Normal file
23
hmi-frontend/tests/widget-package.mjs
Normal file
@@ -0,0 +1,23 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import url from 'node:url';
|
||||
import assert from 'node:assert/strict';
|
||||
import ts from 'typescript';
|
||||
const base=path.resolve(path.dirname(url.fileURLToPath(import.meta.url)),'../src');
|
||||
const code=fs.readFileSync(path.join(base,'widgetPackage.ts'),'utf8');
|
||||
const js=ts.transpileModule(code,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022}}).outputText;
|
||||
const defs={'ui.text':{type:'ui.text'},'ui.script':{type:'ui.script'},'ui.image':{type:'ui.image'}};
|
||||
const m={exports:{}}; new Function('module','exports','require',js)(m,m.exports,()=>({catalogByType:defs}));
|
||||
const {parseWidgetPackage,makeExportPackage}=m.exports;
|
||||
const widget={id:'text-1',type:'ui.text',x:0,y:0,w:4,h:2,mandatory:false,personalizable:true,visibleToRoles:[],props:{title:'Test'}};
|
||||
const pkg=makeExportPackage(widget);
|
||||
assert.equal(parseWidgetPackage(JSON.stringify(pkg)).widget.id,'text-1');
|
||||
const invalid=JSON.parse(JSON.stringify(pkg));invalid.widget.type='__proto__';
|
||||
assert.throws(()=>parseWidgetPackage(JSON.stringify(invalid)));
|
||||
const invalidRole=JSON.parse(JSON.stringify(pkg));invalidRole.widget.mandatory=true;invalidRole.widget.visibleToRoles=['hmi-special'];
|
||||
assert.throws(()=>parseWidgetPackage(JSON.stringify(invalidRole)));
|
||||
const invalidScript=JSON.parse(JSON.stringify(pkg));invalidScript.widget.type='ui.script';invalidScript.widget.props={script:'x'.repeat(8001)};
|
||||
assert.throws(()=>parseWidgetPackage(JSON.stringify(invalidScript)));
|
||||
const image=JSON.parse(JSON.stringify(pkg));image.widget.type='ui.image';image.image={name:'logo.png',mime:'text/html',base64:'PGh0bWw+'};
|
||||
assert.throws(()=>parseWidgetPackage(JSON.stringify(image)));
|
||||
console.log('Widget-Format: 5 Prüfungen erfolgreich');
|
||||
Reference in New Issue
Block a user