Open-source, local-first social media research agent for Instagram, TikTok, and LinkedIn. Jev routes read-only steps; socai CLI captures cited browser evidence.
JavaScript agent-skillsai-agentsbrowser-agentbrowser-automationdecision-modeldeep-researchinstagramjevlinkedinlocal-firstopen-sourceosintresearch-agentsocaisocial-listeningsocial-mediasocial-media-researchsocmintsystem-onetiktok
fix(a11y): name video evidence previews (#102)
Asklv733f0c3c7d23
diff --git a/public/app.js b/public/app.jsindex 695e129..609ccfd 100644--- a/public/app.js+++ b/public/app.js@@ -502,12 +502,12 @@ function evidenceKey(item, index) {function renderCard(item, index) {const card = element("article", "card");+ const title = firstString(item, ["title", "caption", "description", "text", "name"]) || `Result ${index + 1}`;const frame = element("div", "media-frame");- renderMediaPreview(frame, item);+ renderMediaPreview(frame, item, { title });card.append(frame);const body = element("div", "card-body");- const title = firstString(item, ["title", "caption", "description", "text", "name"]) || `Result ${index + 1}`;const author = authorName(item);body.append(element("h4", "", title));if (author) body.append(element("p", "author", author.startsWith("@") ? author : `@${author}`));@@ -531,7 +531,7 @@ function renderCard(item, index) {return card;}-function renderMediaPreview(frame, item, { showBadge = true } = {}) {+function renderMediaPreview(frame, item, { showBadge = true, title = "captured evidence" } = {}) {const failed = new Set();const poster = posterSource(item);const tryNext = () => {@@ -548,6 +548,7 @@ function renderMediaPreview(frame, item, { showBadge = true } = {}) {video.controls = true;video.preload = "metadata";video.playsInline = true;+ video.setAttribute("aria-label", `Video preview for ${String(title).trim() || "captured evidence"}`);video.addEventListener("error", () => {failed.add(candidate.src);tryNext();@@ -646,7 +647,7 @@ function renderTable(items) {function showDetail(item, title) {const media = element("div", "detail-media");- renderMediaPreview(media, item, { showBadge: false });+ renderMediaPreview(media, item, { showBadge: false, title });const copy = element("div", "detail-copy");copy.append(element("h3", "", title));const description = firstString(item, ["description", "caption", "text", "title"]);diff --git a/test/media-preview-name.test.js b/test/media-preview-name.test.jsnew file mode 100644index 0000000..6eb59fa--- /dev/null+++ b/test/media-preview-name.test.js@@ -0,0 +1,126 @@+import assert from "node:assert/strict";+import { readFile } from "node:fs/promises";+import vm from "node:vm";+import test from "node:test";++const appSource = await readFile(new URL("../public/app.js", 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 renderPreview(title, { candidates = [{ kind: "remote-video", src: "https://media.example/video.mp4" }], ...options } = {}) {+ const created = [];+ const frameClasses = new Set();+ const frame = {+ children: [],+ classList: {+ toggle(name, enabled) {+ if (enabled) frameClasses.add(name);+ else frameClasses.delete(name);+ },+ },+ replaceChildren(...children) {+ this.children = children;+ },+ };+ const renderer = vm.runInNewContext(+ `(() => {+ ${productionFunction("renderMediaPreview", "renderMediaFallback")}+ ${productionFunction("renderMediaFallback", "posterSources")}+ return renderMediaPreview;+ })()`,+ {+ document: {+ createElement(tagName) {+ const node = {+ tagName,+ attributes: {},+ listeners: {},+ addEventListener(name, listener) {+ this.listeners[name] = listener;+ },+ dispatch(name) {+ this.listeners[name]?.();+ },+ setAttribute(name, value) {+ this.attributes[name] = String(value);+ },+ };+ created.push(node);+ return node;+ },+ },+ element: (tagName, className, text) => ({+ tagName,+ className,+ text,+ children: [],+ append(...children) {+ this.children.push(...children);+ },+ }),+ nextPreviewCandidate: (_item, failed) => candidates.find((candidate) => (+ candidate.kind === "fallback" || !failed.has(candidate.src)+ )) ?? { kind: "fallback" },+ posterSource: () => "https://media.example/poster.jpg",+ capitalize: (value) => value.charAt(0).toUpperCase() + value.slice(1),+ },+ );++ renderer(frame, {}, { title, ...options });+ return { created, frame, frameClasses };+}++test("card and detail video previews keep equivalent record-specific accessible names", () => {+ assert.match(+ appSource,+ /const title = firstString\([\s\S]{0,240}renderMediaPreview\(frame, item, \{ title \}\)/,+ "renderCard must pass its visible evidence title into the production media renderer",+ );+ assert.match(+ appSource,+ /renderMediaPreview\(media, item, \{ showBadge: false, title \}\)/,+ "showDetail must pass the same evidence title into the production media renderer",+ );++ const card = renderPreview("Ceramic studio tour");+ const detail = renderPreview("Ceramic studio tour", { showBadge: false });+ const other = renderPreview("City market interview");+ const cardVideo = card.created.find((node) => node.tagName === "video");+ const detailVideo = detail.created.find((node) => node.tagName === "video");+ const otherVideo = other.created.find((node) => node.tagName === "video");++ assert.equal(cardVideo.attributes["aria-label"], "Video preview for Ceramic studio tour");+ assert.equal(detailVideo.attributes["aria-label"], cardVideo.attributes["aria-label"]);+ assert.equal(otherVideo.attributes["aria-label"], "Video preview for City market interview");+ assert.notEqual(otherVideo.attributes["aria-label"], cardVideo.attributes["aria-label"]);+});++test("video errors preserve decorative images and the existing fallback copy", () => {+ const preview = renderPreview("Ceramic studio tour", {+ candidates: [+ { kind: "remote-video", src: "https://media.example/video.mp4" },+ { kind: "image", src: "https://media.example/poster.jpg" },+ { kind: "fallback" },+ ],+ });+ const video = preview.created.find((node) => node.tagName === "video");++ video.dispatch("error");+ const image = preview.created.find((node) => node.tagName === "img");+ assert.equal(image.alt, "", "image previews must remain decorative");+ assert.equal(preview.frame.children[0], image);++ image.dispatch("error");+ assert.ok(preview.frameClasses.has("media-frame-fallback"));+ assert.equal(preview.frame.children[0].className, "media-fallback");+ assert.equal(+ preview.frame.children[0].children[2].text,+ "Preview unavailable — post details are still preserved.",+ );+});