71 lines
2.5 KiB
JavaScript
71 lines
2.5 KiB
JavaScript
// SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
|
|
//
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import test from "node:test";
|
|
import vm from "node:vm";
|
|
|
|
test("FT2 entry normalizes audio offsets and registers typed callbacks", async () => {
|
|
let barRenderer;
|
|
const mapMessages = [];
|
|
const window = {
|
|
ft8BaseHz: 14_074_000,
|
|
trxUi: { confirm: async () => true },
|
|
ft8ExtractAllGrids: () => ["JO91"],
|
|
ft8ExtractLikelyCallsign: () => "SP0ABC",
|
|
mapAddLocator: (...args) => { mapMessages.push(args); },
|
|
registerFt8FamilyBarRenderer: (_decoder, renderer) => { barRenderer = renderer; },
|
|
fmtTime: () => "12:00",
|
|
setInterval() { return 1; },
|
|
};
|
|
const context = vm.createContext({
|
|
window,
|
|
document: { getElementById: () => null, createElement: () => ({ dataset: {} }), createDocumentFragment: () => ({ appendChild() {} }) },
|
|
Date,
|
|
Number,
|
|
String,
|
|
Array,
|
|
console,
|
|
});
|
|
const source = await readFile(new URL("../../assets/web/generated/ft2.js", import.meta.url), "utf8");
|
|
new vm.Script(source).runInContext(context);
|
|
|
|
window.onServerFt2({ message: "CQ SP0ABC JO91", freq_hz: 1_250, ts_ms: Date.now(), snr_db: -8 });
|
|
assert.equal(mapMessages.length, 1);
|
|
assert.equal(mapMessages[0][4].freq_hz, 14_075_250);
|
|
const bar = barRenderer();
|
|
assert.equal(bar.count, 1);
|
|
assert.match(bar.html, /CQ SP0ABC/);
|
|
assert.match(bar.html, /JO91/);
|
|
});
|
|
|
|
test("FT8 entry installs shared parsing without relying on script globals", async () => {
|
|
const forwarded = [];
|
|
const window = {
|
|
ft8BaseHz: 7_074_000,
|
|
trxUi: { confirm: async () => true },
|
|
mapAddLocator: (...args) => { forwarded.push(args); },
|
|
setInterval() { return 1; },
|
|
};
|
|
const context = vm.createContext({
|
|
window,
|
|
document: { getElementById: () => null, createElement: () => ({ dataset: {} }), createDocumentFragment: () => ({ appendChild() {} }) },
|
|
Date,
|
|
Number,
|
|
String,
|
|
Array,
|
|
Set,
|
|
console,
|
|
});
|
|
const source = await readFile(new URL("../../assets/web/generated/ft8.js", import.meta.url), "utf8");
|
|
new vm.Script(source).runInContext(context);
|
|
|
|
const details = window.ft8ExtractLocatorDetails("K1ABC SP0ABC JO91");
|
|
assert.equal(details[0].source, "SP0ABC");
|
|
assert.equal(details[0].target, "K1ABC");
|
|
window.onServerFt8({ message: "K1ABC SP0ABC JO91", freq_hz: 500, ts_ms: Date.now() });
|
|
assert.equal(forwarded[0][4].freq_hz, 7_074_500);
|
|
});
|