Add VideoModal tag rendering tests

This commit is contained in:
thePR0M3TH3AN committed 2025-10-23 13:43:05 -04:00
1 parent 6f655d52a3
commit 0fa2617cd4
2 files changed
+42 -1

No files matched your search

+1 -1
View File
@@ -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(
+41
View File
@@ -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",
);
});