mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Fix: Enable video modal share button when source is available
The share button in the video modal was not being enabled correctly because `updateSourceAvailability` returned early if `sourceToggleContainer` was missing, skipping the `setShareEnabled` call. This change ensures `setShareEnabled` is called based on `hasUrl` or `hasMagnet` before checking for `sourceToggleContainer`. Added a regression test `tests/e2e/video-modal-share-bug.spec.ts`.
This commit is contained in:
1 parent
ba69eb6163
commit
afa231da3e
2 files changed
+73
-4
No files matched your search
@@ -2797,10 +2797,6 @@ export class VideoModal {
|
||||
}
|
||||
|
||||
updateSourceAvailability(video) {
|
||||
if (!this.sourceToggleContainer) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hasUrl = Boolean(
|
||||
typeof video?.url === "string" && video.url.trim()
|
||||
);
|
||||
@@ -2809,6 +2805,12 @@ export class VideoModal {
|
||||
video?.torrentSupported
|
||||
);
|
||||
|
||||
this.setShareEnabled(hasUrl || hasMagnet);
|
||||
|
||||
if (!this.sourceToggleContainer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasUrl || hasMagnet) {
|
||||
this.sourceToggleContainer.removeAttribute("hidden");
|
||||
this.sourceToggleContainer.classList.remove("hidden");
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { applyReducedMotion, failOnConsoleErrors } from "./helpers/uiTestUtils";
|
||||
|
||||
test.describe("video modal share button", () => {
|
||||
test("opens the share menu when clicked", async ({ page }) => {
|
||||
await applyReducedMotion(page);
|
||||
await page.goto("/components/video-modal.html", { waitUntil: "networkidle" });
|
||||
|
||||
await page.addScriptTag({
|
||||
type: "module",
|
||||
content: `
|
||||
import { VideoModal } from "/js/ui/components/VideoModal.js";
|
||||
|
||||
// Mock dependencies
|
||||
const mockSetGlobalModalState = (name, isOpen) => {
|
||||
console.log(\`setGlobalModalState: \${name} = \${isOpen}\`);
|
||||
};
|
||||
|
||||
const mockMediaLoader = {
|
||||
observe: () => {},
|
||||
unobserve: () => {},
|
||||
};
|
||||
|
||||
const videoModal = new VideoModal({
|
||||
document: document,
|
||||
setGlobalModalState: mockSetGlobalModalState,
|
||||
mediaLoader: mockMediaLoader,
|
||||
});
|
||||
|
||||
// Force loaded state and hydrate
|
||||
const playerModal = document.getElementById("playerModal");
|
||||
if (playerModal) {
|
||||
videoModal.loaded = true;
|
||||
videoModal.hydrate(playerModal);
|
||||
|
||||
// Mock an active video so the share menu has data
|
||||
videoModal.activeVideo = {
|
||||
id: "test-video-id",
|
||||
title: "Test Video",
|
||||
url: "https://example.com/video.mp4",
|
||||
magnet: "magnet:?xt=urn:btih:test",
|
||||
};
|
||||
|
||||
// Open the modal
|
||||
videoModal.open(videoModal.activeVideo);
|
||||
}
|
||||
|
||||
window.__videoModal = videoModal;
|
||||
`,
|
||||
});
|
||||
|
||||
// Ensure modal is visible
|
||||
const modal = page.locator("#playerModal");
|
||||
await expect(modal).not.toHaveClass(/hidden/);
|
||||
|
||||
// Click share button
|
||||
const shareBtn = page.locator("#shareBtn");
|
||||
await expect(shareBtn).toBeVisible();
|
||||
await shareBtn.click();
|
||||
|
||||
// Expect popover to be open
|
||||
// The popover engine adds data-popover-state="open" to the panel
|
||||
const popoverPanel = page.locator('[data-menu="video-share"]');
|
||||
await expect(popoverPanel).toBeVisible();
|
||||
await expect(popoverPanel).toHaveAttribute("data-popover-state", "open");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user