Files
bpq_gui/sync-state.test.mjs

15 lines
1.6 KiB
JavaScript

import {test} from 'node:test';
import assert from 'node:assert/strict';
import {mergeSyncSnapshot} from './public/sync-state.js';
import {canRecoverIdleScan} from './packet-preparation.mjs';
test('late progress responses cannot revive a failed or cancelled sync',()=>{
for(const state of ['failed','complete','cancelled']){const ended={id:'one',state,active:false,revision:5};assert.equal(mergeSyncSnapshot(ended,{id:'one',state:'calling',active:true,revision:3}),ended);}
const current={id:'new',state:'preparing',active:true,revision:1};assert.equal(mergeSyncSnapshot(current,{id:'old',active:false,revision:5}),current);
const connected={id:'one',state:'connected',active:true,revision:3};assert.equal(mergeSyncSnapshot(connected,{id:'one',state:'calling',active:true,revision:2}),connected);assert.equal(mergeSyncSnapshot(connected,{id:'one',state:'failed',active:false,revision:4}).state,'failed');
});
test('idle HF scan recovery refuses every active session, reservation and TX pause',()=>{
const idle={phase:'hf',scanning:false,txSuspended:false,ptt:false,request:null,manualRequestId:null,radioState:'Free',users:'',radioPorts:[1,3],lastPtt:0,idleSince:10000,now:20000};
assert.equal(canRecoverIdleScan(idle),true);
for(const busy of [{phase:'vhf'},{scanning:true},{txSuspended:true},{ptt:true},{request:{id:'pending'}},{manualRequestId:'reserved'},{radioState:'Connected'},{radioState:'Connecting to gateway'},{radioState:'Interlocked'},{users:'Attached to Port 1/1'},{users:'TNC Uplink Port 3/1'},{lastPtt:19500},{idleSince:19000},{idleSince:0}])assert.equal(canRecoverIdleScan({...idle,...busy}),false,JSON.stringify(busy));
});