Refactor: Replace duplicated extractDTagValue in DeleteModal

Replaced the local `extractDTagValue` function in `js/ui/components/DeleteModal.js` with the shared `getDTagValueFromTags` utility from `js/nostr/nip71.js` (exported via `js/nostr/index.js`).

Added a new unit test `tests/ui/components/DeleteModal.test.mjs` to verify the d-tag extraction logic and ensure the refactor is correct and safe. This test uses `jsdom` to mock the necessary DOM environment.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-26 17:39:07 +00:00
1 parent 9913e484ab
commit 4bdcfbdb2e
2 files changed
+72 -16

No files matched your search

+2 -16
View File
@@ -1,20 +1,6 @@
import { getDTagValueFromTags } from "../../nostr/index.js";
import { createModalAccessibility } from "./modalAccessibility.js";
function extractDTagValue(tags) {
if (!Array.isArray(tags)) {
return "";
}
for (const entry of tags) {
if (!Array.isArray(entry) || entry.length < 2) {
continue;
}
if (entry[0] === "d" && typeof entry[1] === "string") {
return entry[1];
}
}
return "";
}
export class DeleteModal {
constructor({
removeTrackingScripts,
@@ -232,7 +218,7 @@ export class DeleteModal {
video && typeof video.videoRootId === "string" && video.videoRootId.trim().length
? video.videoRootId.trim()
: "";
const dTagValue = extractDTagValue(video?.tags);
const dTagValue = getDTagValueFromTags(video?.tags);
if (this.subtitle) {
const subtitleParts = [];