refactor: consolidate FT2 and FT4 plugins in TypeScript
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// 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 JO91/);
|
||||
});
|
||||
Reference in New Issue
Block a user