68 lines
4.5 KiB
JavaScript
68 lines
4.5 KiB
JavaScript
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 'vite';
|
|
|
|
let server,Detail,presentation,enrolledDevice;
|
|
before(async()=>{
|
|
server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});
|
|
({K1Detail:Detail}=await server.ssrLoadModule('@xgrids-k1/frontend/sensors/K1Detail.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,/Инициировать запуск/);
|
|
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,'Wi-Fi настроен · нет управления');
|
|
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,/k1-preview-spatial/);
|
|
assert.match(markup,/>Статус</);
|
|
assert.match(markup,/>Rerun</);
|
|
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);
|
|
assert.match(markup,/<button[^>]*aria-busy="true"[\s\S]*?nodedc-activity-indicator[\s\S]*?Запускаем устройство<\/button>/);
|
|
assert.equal((markup.match(/nodedc-activity-indicator"/g)||[]).length,1);
|
|
assert.doesNotMatch(markup,/Остановить устройство|k1-preview-spatial/);
|
|
});
|
|
test('completed STOP remains visible while the control connection is checked again',()=>{
|
|
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,/Устройство остановлено/);
|
|
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);
|
|
});
|