Skip to content

Commit ed8683d

Browse files
committed
fix(api-test): resolve remaining SonarQube issues in api-test.html
1 parent b387dfa commit ed8683d

1 file changed

Lines changed: 40 additions & 25 deletions

File tree

public/api-test.html

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,32 @@
2222
.log-entry.recv { background: #14532d22; border-left: 3px solid #22c55e; }
2323
.log-entry.error { background: #7f1d1d22; border-left: 3px solid #ef4444; }
2424
.log-entry.event { background: #4a1d9122; border-left: 3px solid #a855f7; }
25-
.log-entry .ts { color: #94a3b8; font-size: 10px; }
25+
.log-entry .ts { color: #cbd5e1; font-size: 10px; }
2626
.log-entry .type { font-weight: 600; }
2727
button { background: #334155; color: #e2e8f0; border: 1px solid #475569; border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 12px; transition: background 0.15s; }
2828
button:hover { background: #475569; }
29-
button.primary { background: #0ea5e9; border-color: #0ea5e9; color: #fff; }
30-
button.primary:hover { background: #0284c7; }
29+
button.primary { background: #0c86c7; border-color: #0c86c7; color: #fff; }
30+
button.primary:hover { background: #04649e; }
3131
button.danger { background: #dc2626; border-color: #dc2626; color: #fff; }
3232
button.danger:hover { background: #b91c1c; }
33-
button.success { background: #16a34a; border-color: #16a34a; color: #fff; }
34-
button.success:hover { background: #15803d; }
33+
button.success { background: #15803d; border-color: #15803d; color: #fff; }
34+
button.success:hover { background: #166d3f; }
3535
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
3636
input, select, textarea { background: #0f172a; color: #e2e8f0; border: 1px solid #475569; border-radius: 6px; padding: 6px 8px; font-size: 12px; width: 100%; }
3737
textarea { font-family: 'SF Mono', monospace; resize: vertical; }
38-
label { font-size: 11px; color: #94a3b8; display: block; margin-bottom: 2px; }
38+
label { font-size: 11px; color: #cbd5e1; display: block; margin-bottom: 2px; }
3939
.field { margin-bottom: 8px; }
4040
.inline { display: flex; gap: 6px; align-items: end; }
4141
.inline .field { flex: 1; }
4242
hr { border: none; border-top: 1px solid #334155; margin: 10px 0; }
4343
.status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
44-
.status.connected { background: #16a34a33; color: #4ade80; }
45-
.status.disconnected { background: #dc262633; color: #f87171; }
44+
.status.connected { background: #16a34a33; color: #e2e8f0; }
45+
.status.disconnected { background: #dc262633; color: #e2e8f0; }
4646
#test-results { margin-top: 8px; font-size: 12px; }
4747
.test-pass { color: #4ade80; }
4848
.test-fail { color: #f87171; }
4949
.test-skip { color: #fbbf24; }
50-
.counter { font-size: 11px; color: #94a3b8; }
50+
.counter { font-size: 11px; color: #cbd5e1; }
5151
</style>
5252
</head>
5353
<body>
@@ -57,7 +57,7 @@ <h1>UnoSim External API Test Console</h1>
5757
<!-- Left panel: Controls -->
5858
<div class="panel">
5959
<div class="field">
60-
<label for="sim-url">Simulator URL <span style="color:#94a3b8">(same origin as this page)</span></label>
60+
<label for="sim-url">Simulator URL <span style="color:#cbd5e1">(same origin as this page)</span></label>
6161
<input id="sim-url" type="text" />
6262
</div>
6363
<div class="btn-row">
@@ -206,12 +206,14 @@ <h2 style="margin:0">Message Log</h2>
206206
// ── Connect ────────────────────────────────────────────────────────────
207207
function connectSimulator() {
208208
var url = document.getElementById("sim-url").value.trim();
209-
if (!url) return;
210-
211-
try {
212-
simOrigin = new URL(url).origin;
213-
} catch (e) {
214-
log("error", "Invalid URL: " + url, { name: e.name, message: e.message }, "error");
209+
if (url) {
210+
try {
211+
simOrigin = new URL(url).origin;
212+
} catch (e) {
213+
log("error", "Invalid URL: " + url, { name: e.name, message: e.message }, "error");
214+
return;
215+
}
216+
} else {
215217
return;
216218
}
217219

@@ -244,13 +246,14 @@ <h2 style="margin:0">Message Log</h2>
244246

245247
// ── Send Action ────────────────────────────────────────────────────────
246248
function sendAction(type, payload) {
247-
if (!simWindow) {
249+
if (simWindow) {
250+
var msg = { type: type, payload: payload };
251+
log("sent", type, payload);
252+
simWindow.postMessage(msg, simOrigin);
253+
} else {
248254
log("error", "Not connected — click Connect first", undefined, "error");
249255
return;
250256
}
251-
var msg = { type: type, payload: payload };
252-
log("sent", type, payload);
253-
simWindow.postMessage(msg, simOrigin);
254257
}
255258

256259
function sendAndWait(type, payload, timeoutMs = 5000) {
@@ -312,8 +315,18 @@ <h2 style="margin:0">Message Log</h2>
312315
var passed = 0, failed = 0, skipped = 0;
313316

314317
function report(name, ok, detail) {
315-
var statusClass = ok === true ? "test-pass" : ok === false ? "test-fail" : "test-skip";
316-
var symbol = ok === true ? "✓" : ok === false ? "✗" : "⊘";
318+
var statusClass;
319+
var symbol;
320+
if (ok === true) {
321+
statusClass = "test-pass";
322+
symbol = "✓";
323+
} else if (ok === false) {
324+
statusClass = "test-fail";
325+
symbol = "✗";
326+
} else {
327+
statusClass = "test-skip";
328+
symbol = "⊘";
329+
}
317330
var message = symbol + " " + name;
318331
var fullLine = detail ? message + " — " + detail : message;
319332
results.innerHTML += '<span class="' + statusClass + '">' + fullLine + "</span><br>";
@@ -326,7 +339,9 @@ <h2 style="margin:0">Message Log</h2>
326339
}
327340
}
328341

329-
if (!simWindow) {
342+
if (simWindow) {
343+
await sleep(1000);
344+
} else {
330345
report("Connection", null, "Connect to simulator first");
331346
results.innerHTML += "<br><b>Skipped — connect first.</b>";
332347
return;
@@ -398,7 +413,7 @@ <h2 style="margin:0">Message Log</h2>
398413

399414
// ── Wire up all event listeners (CSP script-src-attr blocks inline onclick) ──
400415
document.addEventListener("DOMContentLoaded", function () {
401-
document.getElementById("sim-url").value = window.location.origin;
416+
document.getElementById("sim-url").value = globalThis.location.origin;
402417

403418
document.getElementById("btn-connect").addEventListener("click", connectSimulator);
404419
document.getElementById("btn-clear-log").addEventListener("click", clearLog);
@@ -442,7 +457,7 @@ <h2 style="margin:0">Message Log</h2>
442457
});
443458

444459
document.getElementById("btn-serial-send").addEventListener("click", function () {
445-
sendAction("SERIAL_INPUT", { data: document.getElementById("serial-data").value.replaceAll("\\n", "\n") });
460+
sendAction("SERIAL_INPUT", { data: document.getElementById("serial-data").value.replaceAll(String.raw`\n`, "\n") });
446461
});
447462

448463
document.querySelectorAll("[data-tab]").forEach(function (btn) {

0 commit comments

Comments
 (0)