From 0fa2617cd49d71055be9f4f17c780747be047d2a Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Thu, 23 Oct 2025 13:43:05 -0400 Subject: [PATCH] Add VideoModal tag rendering tests --- tests/video-modal-accessibility.test.mjs | 2 +- tests/video-modal-tags.test.mjs | 41 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/video-modal-tags.test.mjs diff --git a/tests/video-modal-accessibility.test.mjs b/tests/video-modal-accessibility.test.mjs index 96bcdad5..a0f04e3e 100644 --- a/tests/video-modal-accessibility.test.mjs +++ b/tests/video-modal-accessibility.test.mjs @@ -12,7 +12,7 @@ const modalMarkupPromise = readFile( "utf8" ); -async function setupModal({ lazyLoad = false } = {}) { +export async function setupModal({ lazyLoad = false } = {}) { const markup = await modalMarkupPromise; const modalMarkup = lazyLoad ? "" : markup; const dom = new JSDOM( diff --git a/tests/video-modal-tags.test.mjs b/tests/video-modal-tags.test.mjs new file mode 100644 index 00000000..fac10932 --- /dev/null +++ b/tests/video-modal-tags.test.mjs @@ -0,0 +1,41 @@ +import test from "node:test"; +import assert from "node:assert/strict"; + +import { setupModal } from "./video-modal-accessibility.test.mjs"; + +test("VideoModal renders tag metadata and toggles visibility", async (t) => { + const { document, modal, cleanup } = await setupModal(); + t.after(() => { + cleanup(); + }); + + const tagsRoot = document.getElementById("videoTags"); + assert.ok(tagsRoot, "#videoTags element should exist"); + assert.strictEqual(tagsRoot.getAttribute("aria-hidden"), "true"); + assert.ok(tagsRoot.hasAttribute("hidden")); + + modal.updateMetadata({ tags: ["nostr", "Bitvid", "alpha"] }); + + assert.strictEqual(tagsRoot.getAttribute("aria-hidden"), "false"); + assert.ok(!tagsRoot.hasAttribute("hidden")); + assert.ok(!tagsRoot.classList.contains("hidden")); + + const tagButtons = Array.from(tagsRoot.querySelectorAll("button")); + assert.strictEqual(tagButtons.length, 3, "tag strip should render all tags"); + assert.deepStrictEqual( + tagButtons.map((button) => button.textContent), + ["#alpha", "#Bitvid", "#nostr"], + "tag labels should be normalized and sorted alphabetically", + ); + + modal.updateMetadata({ tags: [] }); + + assert.strictEqual(tagsRoot.getAttribute("aria-hidden"), "true"); + assert.ok(tagsRoot.hasAttribute("hidden")); + assert.ok(tagsRoot.classList.contains("hidden")); + assert.strictEqual( + tagsRoot.querySelectorAll("button").length, + 0, + "tag strip should be cleared when metadata tags are empty", + ); +});