Files
DCCONSTRUCTIONS f32c7b400b feat(vesc): extend motor diagnostics, configuration and transport recovery
Add firmware and extension catalogues, configuration transactions, sample review and QML diagnostics. Preserve explicit authority, bounded retries and stop recovery in motor transport.
2026-10-29 09:09:59 +03:00

46 lines
3.0 KiB
JavaScript

import assert from 'node:assert/strict';
import {before,after,test} from 'node:test';
import {createServer} from './support/vite-server.mjs';
let server,config,editor;
before(async()=>{
server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});
config=await server.ssrLoadModule('../../plugins/vesc/frontend/src/configuration.ts');
editor=await server.ssrLoadModule('../../plugins/vesc/frontend/src/VescParameterEditor.tsx');
});
after(async()=>{await server?.close();});
const parameter={name:'current_max',title:'Motor current',type:'number',value:0.35,editor_scale:100,decimals:1,suffix:'%',transmittable:true};
test('native editor scale and units display without changing stored values',()=>{
assert.equal(config.parameterValue(parameter),'35 %');assert.equal(parameter.value,0.35);
assert.equal(config.parameterValue({...parameter,type:'enum',value:1,options:['Disabled','FOC']}),'FOC');
assert.equal(config.parameterValue({...parameter,type:'boolean',value:false}),'Выключено');
});
test('search reaches native names across groups and ignores separator pseudo parameters',()=>{
const other={...parameter,name:'app_mode',title:'Application mode'};
const schema={parameters:[parameter,other],groups:[{name:'general',subgroups:[{name:'limits',parameters:['::sep::Motor','current_max']}]}]};
assert.deepEqual(config.groupedParameters(schema,'general',''),[parameter]);
assert.deepEqual(config.groupedParameters(schema,'general','app_mode'),[other]);
assert.deepEqual(config.groupedParameters(schema,'all','missing'),[]);
});
test('unknown upstream groups remain accessible after an engine update',()=>{
assert.equal(config.groupLabel('foc'),'FOC');assert.equal(config.groupLabel('future_device'),'future_device');
});
test('subgroups preserve upstream order and hide unrelated fields by default',()=>{
const first={...parameter,name:'first'},second={...parameter,name:'second'};
const schema={parameters:[first,second],groups:[{name:'general',subgroups:[{name:'current',parameters:['::sep::Current','second','first']},{name:'voltage',parameters:['first']}]}]};
assert.deepEqual(config.groupedParameters(schema,'general','','current'),[second,first]);
assert.deepEqual(config.groupedParameters(schema,'general','','voltage'),[first]);
});
test('typed editor converts display units back to firmware values and rejects invalid input',()=>{
const p={...parameter,min:0,max:1};
assert.equal(editor.initialDraft(p),'35');
assert.deepEqual(editor.parseDraft(p,'42,5'),{value:0.425,error:null});
for(const value of ['', 'Infinity', 'NaN', '101', '-1'])assert.ok(editor.parseDraft(p,value).error);
assert.ok(editor.parseDraft({...p,type:'integer',min:0,max:100},'1.2').error);
assert.ok(editor.parseDraft({...p,type:'enum',options:['a','b']},'2').error);
assert.ok(editor.parseDraft({...p,type:'bitfield'},'256').error);
assert.equal(editor.parseDraft({...p,type:'boolean'},false).value,false);
assert.ok(editor.parseDraft({...p,type:'string',max_length:4},'longer').error);
});