46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
import test from 'brittle'
|
|
import { buildFleetRoster, summarizeFleet } from '../ui/fleet.js'
|
|
|
|
const hex = (n) => n.repeat(64)
|
|
|
|
test('buildFleetRoster merges saved + live and sorts active first', (t) => {
|
|
const a = hex('a')
|
|
const b = hex('b')
|
|
const c = hex('c')
|
|
const roster = buildFleetRoster({
|
|
saved: [
|
|
{ publicKeyHex: a, alias: 'alpha' },
|
|
{ publicKeyHex: b, alias: 'bravo' },
|
|
{ publicKeyHex: c, alias: 'charlie' },
|
|
],
|
|
live: [
|
|
{ publicKeyHex: a, connected: true },
|
|
{ publicKeyHex: b, connected: false },
|
|
],
|
|
activeId: a,
|
|
getReconnectInfo: (id) =>
|
|
id === b
|
|
? { attempts: 3, maxAttempts: 20, reconnecting: true, failed: false }
|
|
: { attempts: 0, maxAttempts: 20, reconnecting: false, failed: false },
|
|
})
|
|
t.is(roster[0].id, a)
|
|
t.ok(roster[0].active && roster[0].connected)
|
|
t.ok(roster.find((p) => p.id === b)?.reconnecting)
|
|
t.is(roster[roster.length - 1].id, c)
|
|
})
|
|
|
|
test('summarizeFleet counts states', (t) => {
|
|
const s = summarizeFleet([
|
|
{ connected: true, reconnecting: false, failed: false },
|
|
{ connected: true, reconnecting: false, failed: false },
|
|
{ connected: false, reconnecting: true, failed: false },
|
|
{ connected: false, reconnecting: false, failed: true },
|
|
{ connected: false, reconnecting: false, failed: false },
|
|
])
|
|
t.is(s.live, 2)
|
|
t.is(s.reconnecting, 1)
|
|
t.is(s.failed, 1)
|
|
t.is(s.offline, 1)
|
|
t.is(s.total, 5)
|
|
})
|