fix(settings): connect to the decoder URL shown in the field

Connect now used the saved URL even after a new one was typed; typed
decoder URLs are now saved first. Adds a browser test for saving a new
decoder port and connecting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
larssandandClaude Opus 5.5 committed 2026-10-17 17:23:48 +02:00
1 parent abed53fb32
commit cdde070c1c
7 files changed
+76 -4

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import assert from "node:assert/strict";
import { startFakeDecoder } from "./browser_fake_decoder.js";
// A user running AMMC themselves on another port: type the new WebSocket URL in Settings ->
// Connection, press Save, then Connect now - the decoder must come online on that port.
export async function runDecoderUrlSmoke({ evaluate, navigate, savedState, waitFor, base }) {
const decoder = await startFakeDecoder();
const before = await savedState();
try {
await navigate("settings", "settingsForm");
await evaluate(`document.querySelector('[data-settings-tab="connection"]').click()`);
const url = `ws://127.0.0.1:${decoder.port}`;
await evaluate(`(() => {
const input = document.querySelector('#settingsForm [name="wsUrl"]');
input.value = ${JSON.stringify(url)};
input.dispatchEvent(new Event("input", { bubbles: true }));
input.dispatchEvent(new Event("change", { bubbles: true }));
document.querySelector('#settingsForm button[type="submit"]').click();
})()`);
await waitFor(async () => (await savedState()).settings.wsUrl === url, "the new WebSocket URL is saved");
await evaluate(`document.getElementById("settingsConnect").click()`);
await waitFor(async () => evaluate('document.getElementById("connectionBadge")?.classList.contains("badge-online")'), "decoder online on the new port");
assert.equal(await evaluate(`document.querySelector('#settingsForm [name="wsUrl"]').value`), url, "the field still shows the new URL after the re-render");
console.log("PASS typing a new decoder WebSocket URL, Save and Connect now connects on that port");
// Typing a URL and pressing Connect now without Save: the typed URL is saved and used.
const second = await startFakeDecoder();
try {
const secondUrl = `ws://127.0.0.1:${second.port}`;
await evaluate(`(() => { const input = document.querySelector('#settingsForm [name="wsUrl"]'); input.value = ${JSON.stringify(secondUrl)}; document.getElementById("settingsConnect").click(); })()`);
await waitFor(async () => (await savedState()).settings.wsUrl === secondUrl, "the typed URL is saved by Connect now");
await waitFor(async () => second.totalConnections() > 0, "connected to the typed port");
console.log("PASS Connect now uses the URL in the field even without pressing Save");
} finally {
await second.close();
}
} finally {
const current = await savedState();
await fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ...current, settings: { ...current.settings, wsUrl: before.settings.wsUrl, autoReconnect: false } }) });
await decoder.close();
}
}