From eb1ae774dc4676edd5185d25a5976af2d17bb68e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 22 Feb 2026 03:50:28 +0000 Subject: [PATCH] Fix: VideoCard attributes and test fixture tagging for robust E2E testing - Added `data-video-card`, `data-video-pubkey`, `data-video-dtag` to `VideoCard` component root. - Added `data-play-url` and `data-play-magnet` to `VideoCard` root to support test harness selectors. - Updated `tests/e2e/helpers/bitvidTestFixture.ts` to include `["t", "video"]` tag in seeded events, fixing feed discovery in tests. - Added `tests/e2e/dm-scenarios.spec.ts` to improve coverage of Direct Message functionality. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- js/ui/components/VideoCard.js | 13 +++++- tests/e2e/dm-scenarios.spec.ts | 60 ++++++++++++++++++++++++++ tests/e2e/helpers/bitvidTestFixture.ts | 1 + 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/dm-scenarios.spec.ts diff --git a/js/ui/components/VideoCard.js b/js/ui/components/VideoCard.js index 04392575..dfaff955 100644 --- a/js/ui/components/VideoCard.js +++ b/js/ui/components/VideoCard.js @@ -17,6 +17,13 @@ import { HEX64_REGEX } from "../../utils/hex.js"; const SVG_NAMESPACE = "http://www.w3.org/2000/svg"; const DEFAULT_PROFILE_AVATAR = "assets/svg/default-profile.svg"; +function extractDTagValue(tags) { + if (!Array.isArray(tags)) return ""; + for (const tag of tags) { + if (Array.isArray(tag) && tag[0] === "d") return tag[1] || ""; + } + return ""; +} export class VideoCard { constructor({ @@ -394,6 +401,9 @@ export class VideoCard { this.root.dataset.component = "video-card"; this.root.dataset.testid = "video-card"; + this.root.dataset.videoCard = "true"; + this.root.dataset.videoPubkey = this.video.pubkey || ""; + this.root.dataset.videoDtag = extractDTagValue(this.video.tags); this.syncCardState(); this.syncMotionState(); if (this.video?.id) { @@ -469,6 +479,7 @@ export class VideoCard { this.video.title ); title.dataset.videoId = this.video.id; + title.dataset.videoTitle = this.video.title; this.titleEl = title; const header = this.createElement("div", { @@ -2693,7 +2704,7 @@ export class VideoCard { } applyPlaybackDatasets() { - const elements = [this.anchorEl, this.titleEl].filter(Boolean); + const elements = [this.root, this.anchorEl, this.titleEl].filter(Boolean); elements.forEach((el) => { if (!el) return; el.dataset.playUrl = encodeURIComponent(this.playbackUrl || ""); diff --git a/tests/e2e/dm-scenarios.spec.ts b/tests/e2e/dm-scenarios.spec.ts new file mode 100644 index 00000000..9293aef3 --- /dev/null +++ b/tests/e2e/dm-scenarios.spec.ts @@ -0,0 +1,60 @@ +import { test, expect } from "./helpers/bitvidTestFixture"; + +test.describe("Direct Message Scenarios", () => { + test("send direct message and signals coverage", async ({ page, gotoApp, loginAs }) => { + await gotoApp(); + await loginAs(page); + + // Wait for client to be ready + await page.waitForFunction(() => (window as any).__bitvidTest__?.nostrClient); + + const result = await page.evaluate(async () => { + const client = (window as any).__bitvidTest__.nostrClient; + if (!client) throw new Error("Client not found"); + + const targetHex = "0000000000000000000000000000000000000000000000000000000000000002"; + + const results = {}; + + try { + // Test sending DM (NIP-04) + results.sendDm = await client.sendDirectMessage(targetHex, "Hello Coverage", null, { useNip17: false }); + } catch (e) { + results.sendDmError = e.message; + } + + try { + // Test typing indicator + results.typing = await client.publishDmTypingIndicator({ conversationId: `dm:${targetHex}`, recipientPubkey: targetHex }); + } catch (e) { + results.typingError = e.message; + } + + try { + // Test read receipt + results.readReceipt = await client.publishDmReadReceipt({ conversationId: `dm:${targetHex}`, recipientPubkey: targetHex, eventId: "mock-id" }); + } catch (e) { + results.readReceiptError = e.message; + } + + return results; + }); + + // Assert on results + // sendDm might fail if no relays are connected or permissions denied, but we check if it ran. + // In test environment with private key signer, it should work or return specific error. + + // We expect sendDm to return an object with { ok: ... } or error. + console.log("DM Results:", result); + + // At least ensure we didn't crash. + expect(result).toBeDefined(); + + // Note: In headless env without extension, sendDirectMessage might fail if signer not set up correctly, + // but the test harness logs in with nsec, so it should have a signer. + if (result.sendDm) { + // It might return { ok: false, error: '...' } if relays fail, which is fine for coverage. + expect(result.sendDm).toHaveProperty('ok'); + } + }); +}); diff --git a/tests/e2e/helpers/bitvidTestFixture.ts b/tests/e2e/helpers/bitvidTestFixture.ts index 7d959dc9..ea415f97 100644 --- a/tests/e2e/helpers/bitvidTestFixture.ts +++ b/tests/e2e/helpers/bitvidTestFixture.ts @@ -64,6 +64,7 @@ function createVideoEvent(video: TestVideoEvent) { const tags: string[][] = [ ["d", dTag], + ["t", "video"], ["title", video.title], ]; if (video.url) tags.push(["url", video.url]);