47 lines
2.4 KiB
JavaScript
47 lines
2.4 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 './support/vite-server.mjs';
|
|
|
|
let server,Observation;
|
|
before(async()=>{
|
|
server=await createServer({appType:'custom',logLevel:'silent',plugins:[{
|
|
name:'inline-observation-portals-for-ssr',enforce:'pre',
|
|
transform(code,id){
|
|
if(id.endsWith('/K1Observation.tsx')||id.endsWith('/ObservationHeader.tsx'))
|
|
return code.replace("import {createPortal} from 'react-dom';","import {cloneElement as portalChild} from 'react'; const createPortal=(child: any,_target: unknown,key?: string)=>child&&key?portalChild(child,{key}):child;");
|
|
},
|
|
}]});
|
|
({K1Observation:Observation}=await server.ssrLoadModule('@xgrids-k1/frontend/sensors/K1Observation.tsx'));
|
|
});
|
|
after(async()=>{await server?.close();});
|
|
|
|
const render=(acquisition,enabled)=>renderToStaticMarkup(createElement(Observation,{
|
|
device:{id:'synthetic-k1',name:'K1',online:enabled,verified:enabled,
|
|
control:{can_stop:true,acquisition_id:'same-acquisition'},
|
|
snapshot:{acquisition,context:{session_id:'same-session'}}},
|
|
transport:{},enabled,fresh:enabled,views:[{id:'points',target:{},statusTarget:{},actionsTarget:{}}],
|
|
createRerunHost:()=>assert.fail('server rendering must not allocate a viewer'),
|
|
}));
|
|
test('an ongoing acquisition retains the spatial surface during a link gap while STOP is disabled',()=>{
|
|
const online=render('streaming',true),offline=render('streaming',false);
|
|
for(const markup of [online,offline]){
|
|
assert.match(markup,/rerun-viewport__canvas/);
|
|
assert.match(markup,/Окно накопления облака точек/);
|
|
assert.match(markup,/Позиция воспроизведения/);
|
|
assert.match(markup,/ЭФИР/);
|
|
assert.doesNotMatch(markup,/буфер не включён/);
|
|
assert.match(markup,/Следовать за K1/);
|
|
assert.doesNotMatch(markup,/data-viewer-controls/);
|
|
assert.match(markup,/data-pulse="true"/);
|
|
}
|
|
const stop=offline.match(/<button\b[^>]*aria-label="Остановить сканирование K1"[^>]*>/)?.[0];
|
|
assert.ok(stop);assert.match(stop,/disabled=""/);
|
|
assert.doesNotMatch(offline,/Инициировать запуск/);
|
|
});
|
|
test('completed or never-started acquisitions do not retain an active spatial surface',()=>{
|
|
for(const acquisition of ['idle','failed'])
|
|
assert.doesNotMatch(render(acquisition,false),/rerun-viewport__canvas/);
|
|
});
|