refactor: convert background decode controls to TypeScript
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
// 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("background decode loads configuration for the explicitly selected rig", async () => {
|
||||
const requested = [];
|
||||
const window = {
|
||||
decoderRegistry: [],
|
||||
trxUi: { confirm: async () => true },
|
||||
};
|
||||
const context = vm.createContext({
|
||||
window,
|
||||
document: { getElementById: () => null },
|
||||
fetch: async (url) => {
|
||||
requested.push(url);
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => url === "/bookmarks"
|
||||
? []
|
||||
: url.endsWith("/status")
|
||||
? { entries: [] }
|
||||
: { remote: "rig/a", enabled: false, bookmark_ids: [] },
|
||||
};
|
||||
},
|
||||
setInterval: () => 1,
|
||||
clearInterval() {},
|
||||
setTimeout,
|
||||
URL,
|
||||
Set,
|
||||
Error,
|
||||
console,
|
||||
});
|
||||
const source = await readFile(new URL("../../assets/web/generated/background-decode.js", import.meta.url), "utf8");
|
||||
new vm.Script(source).runInContext(context);
|
||||
|
||||
window.initBackgroundDecode("rig/a", "control");
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.ok(requested.includes("/background-decode/rig%2Fa"));
|
||||
assert.ok(requested.includes("/bookmarks"));
|
||||
assert.ok(requested.includes("/background-decode/rig%2Fa/status"));
|
||||
});
|
||||
Reference in New Issue
Block a user