Skip to content

Open-source, local-first social media research agent for Instagram, TikTok, and LinkedIn. Jev routes read-only steps; socai CLI captures cited browser evidence.

fix: give the evidence detail dialog an accessible name (#71)

chenzeyan54-commitsb3d2e012275e
diff --git a/public/app.js b/public/app.js
index eb7d5c7..d56f5e2 100644
--- a/public/app.js
+++ b/public/app.js
@@ -650,7 +650,9 @@ function showDetail(item, title) {
const media = element("div", "detail-media");
renderMediaPreview(media, item, { showBadge: false, title });
const copy = element("div", "detail-copy");
- copy.append(element("h3", "", title));
+ const heading = element("h3", "", title);
+ heading.id = "detail-title";
+ copy.append(heading);
const description = firstString(item, ["description", "caption", "text", "title"]);
if (description) copy.append(element("p", "", description));
const comments = item.top_comments || item.comments || item.socai_detail?.entity?.top_comments;
diff --git a/public/index.html b/public/index.html
index 208b4e9..b1f50a4 100644
--- a/public/index.html
+++ b/public/index.html
@@ -136,10 +136,10 @@
</main>
</div>
- <dialog id="detail-dialog" class="detail-dialog">
+ <dialog id="detail-dialog" class="detail-dialog" aria-labelledby="detail-title">
<button id="close-detail" class="dialog-close" type="button" aria-label="Close">×</button>
<div id="detail-content"></div>
</dialog>
<script type="module" src="/app.js"></script>
</body>
-</html>
+</html>
\ No newline at end of file
diff --git a/test/detail-dialog-name.test.js b/test/detail-dialog-name.test.js
new file mode 100644
index 0000000..0035b2d
--- /dev/null
+++ b/test/detail-dialog-name.test.js
@@ -0,0 +1,70 @@
+import assert from "node:assert/strict";
+import { readFile } from "node:fs/promises";
+import test from "node:test";
+import vm from "node:vm";
+
+const appSource = await readFile(new URL("../public/app.js", import.meta.url), "utf8");
+const html = await readFile(new URL("../public/index.html", import.meta.url), "utf8");
+
+function productionFunction(name, nextName) {
+ const start = appSource.indexOf(`function ${name}(`);
+ const end = appSource.indexOf(`\nfunction ${nextName}(`, start);
+ assert.notEqual(start, -1, `expected production function ${name}`);
+ assert.notEqual(end, -1, `expected production function ${nextName} after ${name}`);
+ return appSource.slice(start, end).trim();
+}
+
+function element(tagName, className, text = "") {
+ return {
+ tagName,
+ className,
+ text,
+ id: "",
+ children: [],
+ append(...children) {
+ this.children.push(...children);
+ },
+ replaceChildren(...children) {
+ this.children = children;
+ },
+ };
+}
+
+function descendants(node) {
+ return [node, ...(node.children || []).flatMap(descendants)];
+}
+
+test("the evidence detail dialog is labelled by its current visible title", () => {
+ const dialogTag = html.match(/<dialog\b[^>]*id="detail-dialog"[^>]*>/u)?.[0] || "";
+ assert.match(dialogTag, /aria-labelledby="detail-title"/u);
+ assert.match(html, /id="close-detail"[^>]*aria-label="Close"/u);
+
+ const detail = element("div", "");
+ const dialog = { showModalCalls: 0, showModal() { this.showModalCalls += 1; } };
+ const showDetail = vm.runInNewContext(
+ `(() => { ${productionFunction("showDetail", "localVideoSource")} return showDetail; })()`,
+ {
+ elements: { detail, dialog },
+ element,
+ renderMediaPreview() {},
+ firstString(item, keys) {
+ return keys.map((key) => item[key]).find((value) => typeof value === "string" && value);
+ },
+ authorName: () => "",
+ isHttpUrl: () => false,
+ Array,
+ },
+ );
+
+ showDetail({ description: "First description" }, "First result");
+ let headings = descendants(detail).filter((node) => node.id === "detail-title");
+ assert.equal(headings.length, 1);
+ assert.equal(headings[0].tagName, "h3");
+ assert.equal(headings[0].text, "First result");
+
+ showDetail({ description: "Second description" }, "Second result");
+ headings = descendants(detail).filter((node) => node.id === "detail-title");
+ assert.equal(headings.length, 1, "replacing a record must not leave duplicate title IDs");
+ assert.equal(headings[0].text, "Second result");
+ assert.equal(dialog.showModalCalls, 2);
+});