Files
NODEDC_MISSION_CORE/apps/control-station/test/k1ManualControl.test.mjs
T

136 lines
9.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert/strict';
import {before,after,test} from 'node:test';
import {createElement} from 'react';
import {renderToStaticMarkup} from 'react-dom/server';
import {createServer} from './support/vite-server.mjs';
let server,Detail,presentation,enrolledDevice,ObservationAction;
before(async()=>{
server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});
({K1Detail:Detail}=await server.ssrLoadModule('@xgrids-k1/frontend/sensors/K1Detail.tsx'));
({K1ObservationAction:ObservationAction}=await server.ssrLoadModule('@xgrids-k1/frontend/sensors/K1ObservationAction.tsx'));
presentation=await server.ssrLoadModule('@xgrids-k1/frontend/sensors/presentation.ts');
({enrolledDevice}=await server.ssrLoadModule('../../packages/sensor-ui/src/contracts.ts'));
});
after(async()=>{await server?.close();});
const device={id:'synthetic',kind:'k1',name:'K1 test',online:true,verified:true,prepared:true,
control:{can_start:true,can_stop:false,can_verify:true,generation:1,revision:1,acquisition_id:null},
snapshot:{context:{session_id:'exact-session',execution:{node_id:'test'}},acquisition:'idle'}};
const render=(value,enabled=true)=>renderToStaticMarkup(createElement(Detail,{device:value,enabled,
transport:{},back:()=>{},refresh:async()=>{},failure:()=>{},createRerunHost:()=>assert.fail('SSR must not start a viewer or hardware')}));
test('manual K1 surface admits one START only after current control proof',()=>{
const markup=render(device);
assert.match(markup,/Инициировать запуск/);
const start=(markup.match(/<button\b[\s\S]*?<\/button>/g)??[]).filter(button=>button.replace(/<[^>]+>/g,'')==='Инициировать запуск');
assert.equal(start.length,1);
assert.match(start[0],/<button[^>]*disabled=""/);
for(const label of ['Тип установки / носитель','Режим GNSS','Название проекта'])assert.ok(markup.includes(label));
assert.match(markup,/Настройки устройства/);
assert.doesNotMatch(markup,/Остановить устройство|Обновить просмотр|sensor-live-layout/);
const waiting={...device,online:false,verified:false,control:{...device.control,can_start:false,network_applied:true,reason_code:'application_authority_unavailable'}};
const pending=render(waiting);
assert.doesNotMatch(pending,/Инициировать запуск|Настройки устройства|sensor-live-layout/);
assert.match(pending,/Проверить состояние K1/);
assert.match(pending,/авторизовать/);
assert.equal(presentation.k1Status(waiting,true).label,'Нет связи с K1');
assert.equal(presentation.k1ManualState(device,false).canStart,false);
});
test('active acquisition exposes STOP and Rerun without another START',()=>{
const active={...device,control:{...device.control,can_start:false,can_stop:true},snapshot:{...device.snapshot,acquisition:'streaming'}};
const markup=render(active);
assert.match(markup,/Остановить устройство/);
assert.match(markup,/rerun-viewport__canvas/);
assert.doesNotMatch(markup,/>Статус</);
assert.match(markup,/>Пространственная сцена</);
for(const label of ['Движок','Слои','Отображение','Камера K1','Окно накопления облака точек'])assert.ok(markup.includes(label));
assert.ok(markup.includes('data-presented="false"'));
assert.ok(!markup.includes('Loading Rerun'));
assert.ok(!markup.includes('The data layer'));
assert.ok(!markup.includes('data-align="center"'));
assert.doesNotMatch(markup,/Восстановить просмотр|nodedc-activity-indicator/);
assert.doesNotMatch(markup,/Инициировать запуск|Обновить просмотр/);
assert.equal(presentation.k1ManualState(active,false).canStart,false);
assert.equal(presentation.k1ManualState(active,false).showStop,true);
});
test('calibration loader stays inside the primary action',()=>{
const starting={...device,control:{...device.control,can_start:false},snapshot:{...device.snapshot,acquisition:'starting'}};
const markup=render(starting);
const start=(markup.match(/<button\b[\s\S]*?<\/button>/g)??[]).filter(button=>button.replace(/<[^>]+>/g,'')==='Запускаем устройство');
assert.equal(start.length,1);
assert.match(start[0],/<button[^>]*aria-busy="true"/);
assert.equal((start[0].match(/class="nodedc-activity-indicator"/g)??[]).length,1);
assert.match(markup,/K1 калибруется и готовит облако точек/);
assert.doesNotMatch(markup,/Обновить просмотр/);
});
test('connection loss is visible independently of completed STOP',()=>{
const stopped={...device,online:false,verified:false,control:{...device.control,phase:'completed',can_start:false,network_applied:true}};
const markup=render(stopped);
assert.match(markup,/Нет связи с K1/);
assert.match(markup,/Проверить состояние K1/);
assert.doesNotMatch(markup,/Инициировать запуск|нет управления/);
});
test('enrollment handoff opens only the verified current session',()=>{
const inventory={fresh:true,items:[device],operations:[]};
assert.equal(enrolledDevice(inventory,'exact-session'),device);
assert.equal(enrolledDevice(inventory,'other-session'),null);
assert.equal(enrolledDevice({...inventory,fresh:false},'exact-session'),null);
assert.equal(enrolledDevice({...inventory,items:[{...device,verified:false}]},'exact-session'),null);
assert.equal(enrolledDevice({...inventory,items:[device,device]},'exact-session'),null);
});
test('completed scan with healthy control remains connected and permits a named next scan',()=>{
const stopped={...device,control:{...device.control,phase:'completed'}};
const markup=render(stopped);
assert.equal(presentation.k1Status(stopped,true).label,'Подключён');
assert.equal(presentation.k1ManualState(stopped,true).canStart,true);
assert.match(markup,/Инициировать запуск/);
assert.doesNotMatch(markup,/Проверить состояние K1|Подключить устройство|Устройство остановлено/);
assert.equal(presentation.k1Status(stopped,false).tone,'neutral');
});
test('observation Play only opens configuration; active acquisition offers its existing controls',()=>{
let opened=0;
const action=ObservationAction({device,fresh:true,configure:()=>opened++});
assert.equal(action.props.label,'Начать сканирование K1');assert.equal(action.props.children.props.name,'play');
action.props.onClick();assert.equal(opened,1);
assert.equal(ObservationAction({device,fresh:false,configure:()=>opened++}),null);
const active={...device,snapshot:{...device.snapshot,acquisition:'streaming'}};
let stopped=0;const stop=ObservationAction({device:{...active,control:{...active.control,can_stop:true}},fresh:true,stop:()=>stopped++});
assert.equal(stop.props.label,'Остановить сканирование K1');stop.props.onClick();assert.equal(stopped,1);assert.equal(opened,1);
});
test('observation configuration preserves START fields and STOP without a duplicate media viewer',()=>{
for(const acquisition of ['idle','starting','streaming','stopping']){
const value={...device,snapshot:{...device.snapshot,acquisition}};
const markup=renderToStaticMarkup(createElement(Detail,{device:value,enabled:true,previewEnabled:false,backLabel:'Вернуться к наблюдению',transport:{},back:()=>{},refresh:async()=>{},failure:()=>{},createRerunHost:()=>assert.fail('must not allocate another viewer')}));
assert.match(markup,/Вернуться к наблюдению/);assert.doesNotMatch(markup,/rerun-viewport__canvas|Открыть пространственную сцену/);
if(acquisition==='idle')assert.match(markup,/Название проекта/);
if(acquisition==='streaming')assert.match(markup,/Остановить устройство/);
}
});
test('observation gear contains only acquisition controls, including before START',()=>{
for(const acquisition of ['idle','streaming']){
const value={...device,snapshot:{...device.snapshot,acquisition}};
const markup=renderToStaticMarkup(createElement(Detail,{device:value,enabled:true,previewEnabled:false,sceneProfile:{view:'plan',save:()=>{}},transport:{},back:()=>{},refresh:async()=>{},failure:()=>{}}));
assert.doesNotMatch(markup,/Размер точки|Атрибут цвета|Палитра|rerun-viewport__canvas/);
if(acquisition==='idle')assert.match(markup,/Название проекта/);
else assert.match(markup,/Остановить устройство/);
}
});
test('K1 storage shows used percentage and expires independently of a fresh inventory',()=>{
const now=Date.now(),observed_at=new Date(now-1000).toISOString();
const almostFull={...device,storage_status:{used_percent:98.99,observed_at}};
assert.equal(presentation.k1StorageStatus(almostFull,true,now+18000).tone,'warning');
const status=presentation.k1StorageStatus(almostFull,true,now);
assert.equal(status.tone,'warning');assert.match(status.label,/занято 99 %.*мало свободного места/);
assert.match(render(almostFull),/Хранилище K1: занято 99 %/);
for(const [value,fresh,at] of [[almostFull,false,now],[{...almostFull,online:false},true,now],[almostFull,true,now+20000],[{...device,storage_status:null},true,now]]){
const unavailable=presentation.k1StorageStatus(value,fresh,at);
assert.equal(unavailable.tone,'neutral');assert.match(unavailable.label,/нет свежих данных/);assert.doesNotMatch(unavailable.label,/99/);
}
assert.equal(presentation.k1StorageStatus({...device,storage_status:{used_percent:0,observed_at}},true,now).tone,'neutral');
});