mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
test(infra): mock web APIs for JSDOM and fix comments test assertions
- Mock HTMLMediaElement.prototype.pause/load and window.scrollTo in test setup to prevent JSDOM "Not implemented" errors. - Fix VideoModal mock in comments tests to preserve prototype chain (using Object.create instead of spread). - Add missing childrenByParent map to comments test payloads to fix rendering assertions. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
8e6257881d
commit
8f440c0acb
2 files changed
+30
-6
No files matched your search
@@ -33,6 +33,16 @@ export async function setupModal({ lazyLoad = false } = {}) {
|
||||
globalThis.Event = window.Event;
|
||||
globalThis.Node = window.Node;
|
||||
globalThis.EventTarget = window.EventTarget;
|
||||
|
||||
if (typeof window.HTMLMediaElement !== "undefined") {
|
||||
window.HTMLMediaElement.prototype.pause = function () {};
|
||||
window.HTMLMediaElement.prototype.load = function () {};
|
||||
}
|
||||
if (typeof window.HTMLVideoElement !== "undefined") {
|
||||
window.HTMLVideoElement.prototype.pause = function () {};
|
||||
window.HTMLVideoElement.prototype.load = function () {};
|
||||
}
|
||||
|
||||
try {
|
||||
Object.defineProperty(globalThis, "navigator", {
|
||||
value: window.navigator,
|
||||
@@ -142,6 +152,8 @@ export async function setupModal({ lazyLoad = false } = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
window.scrollTo = () => {};
|
||||
|
||||
applyDesignSystemAttributes(document);
|
||||
|
||||
if (!window.ResizeObserver) {
|
||||
@@ -432,6 +444,16 @@ async function setupPlaybackHarness() {
|
||||
globalThis.Event = window.Event;
|
||||
globalThis.Node = window.Node;
|
||||
globalThis.EventTarget = window.EventTarget;
|
||||
|
||||
if (typeof window.HTMLMediaElement !== "undefined") {
|
||||
if (!window.HTMLMediaElement.prototype.pause) {
|
||||
window.HTMLMediaElement.prototype.pause = function () {};
|
||||
}
|
||||
if (!window.HTMLMediaElement.prototype.load) {
|
||||
window.HTMLMediaElement.prototype.load = function () {};
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Object.defineProperty(globalThis, "navigator", {
|
||||
value: window.navigator,
|
||||
@@ -531,6 +553,8 @@ async function setupPlaybackHarness() {
|
||||
};
|
||||
}
|
||||
|
||||
window.scrollTo = () => {};
|
||||
|
||||
window.NostrTools = {
|
||||
nip19: {
|
||||
neventEncode: () => "nevent1example",
|
||||
|
||||
@@ -247,12 +247,10 @@ test(
|
||||
t.after(cleanup);
|
||||
|
||||
const visibilityCalls = [];
|
||||
const instrumentedModal = {
|
||||
...modal,
|
||||
setCommentsVisibility: (isVisible) => {
|
||||
visibilityCalls.push(isVisible);
|
||||
modal.setCommentsVisibility(isVisible);
|
||||
},
|
||||
const instrumentedModal = Object.create(modal);
|
||||
instrumentedModal.setCommentsVisibility = (isVisible) => {
|
||||
visibilityCalls.push(isVisible);
|
||||
modal.setCommentsVisibility(isVisible);
|
||||
};
|
||||
|
||||
const snapshot = {
|
||||
@@ -398,6 +396,7 @@ test(
|
||||
},
|
||||
],
|
||||
]),
|
||||
childrenByParent: new Map([[null, ["c1"]]]),
|
||||
commentIds: ["c1"],
|
||||
profiles: new Map([["ABCD", { name: "Mixed Case" }]]),
|
||||
});
|
||||
@@ -477,6 +476,7 @@ test(
|
||||
},
|
||||
],
|
||||
]),
|
||||
childrenByParent: new Map([[null, ["comment-2"]]]),
|
||||
commentIds: ["comment-2"],
|
||||
profiles: new Map(),
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user