From 4c519faaf748cea25f9d0be87dd0f3e09d7bae4c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 5 Mar 2026 15:05:37 -0800 Subject: android hce nfc --- test/e2e/dm-send.spec.ts | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'test/e2e/dm-send.spec.ts') diff --git a/test/e2e/dm-send.spec.ts b/test/e2e/dm-send.spec.ts index 3930c383..9dfa5174 100644 --- a/test/e2e/dm-send.spec.ts +++ b/test/e2e/dm-send.spec.ts @@ -1,7 +1,7 @@ import { expect, test } from "@playwright/test"; -import { login, bobUsername, bobPassword, aliceUsername } from "./helpers"; +import { login, bobUsername, bobPassword, aliceUsername, apiBaseUrl } from "./helpers"; -test("bob sends a DM to alice via /dm page", async ({ browser }) => { +test("bob sends a DM to alice via /messages page", async ({ browser }) => { const bobContext = await browser.newContext(); const bobPage = await bobContext.newPage(); @@ -25,35 +25,44 @@ test("bob sends a DM to alice via /dm page", async ({ browser }) => { // Login as bob (sets auth cookies + nsec in localStorage) await login(bobPage, bobUsername, bobPassword); - // Navigate to /dm selecting alice - await bobPage.goto(`/dm?username=${aliceUsername}`); + // Resolve Alice's pubkey from username + const aliceRes = await bobPage.request.get(`${apiBaseUrl}/users/${aliceUsername}`); + const alicePubkey = (await aliceRes.json()).pubkey; + expect(alicePubkey, "Alice should have a pubkey").toBeTruthy(); + + // Navigate to /messages selecting alice by pubkey + await bobPage.goto(`/messages/${alicePubkey}`); await bobPage.waitForLoadState("domcontentloaded"); - // Wait for the message textarea (indicates a chat is selected) + // Wait for the message textarea to become enabled (canSend=true after relay query completes) const textarea = bobPage.locator("#message-contents"); - await expect(textarea).toBeVisible({ timeout: 15_000 }); - - // Verify send button is enabled (depends on relay availability) - const sendButton = bobPage.locator("#send-message"); - await expect(sendButton).toBeVisible({ timeout: 5_000 }); - const isDisabled = await sendButton.isDisabled(); - const buttonValue = await sendButton.getAttribute("value"); - console.log(`[e2e] Send button disabled=${isDisabled}, value="${buttonValue}"`); - expect(isDisabled, `Send button is disabled: "${buttonValue}"`).toBeFalsy(); + await expect(textarea).toBeEnabled({ timeout: 15_000 }); // Verify the Nostr sign modal does NOT appear (ensureSigner should use nsec from localStorage) const signerModal = bobPage.locator("text=Nostr sign"); const modalBefore = await signerModal.isVisible({ timeout: 500 }).catch(() => false); expect(modalBefore, "Nostr sign modal should not appear before send").toBeFalsy(); - // Type and send a test message + // Type and send a test message (button is disabled={!canSend || !text.trim()}) const testMessage = `e2e test message ${Date.now()}`; await textarea.fill(testMessage); + const sendButton = bobPage.locator('button[aria-label="Send"]'); + await expect(sendButton).toBeEnabled({ timeout: 5_000 }); await sendButton.click(); - // Wait for the send to complete — textarea clears on success + // Wait for the send to complete — textarea clears immediately, but relay publish is async. + // Wait for relay OK messages to arrive (up to 15s). await expect(textarea).toHaveValue("", { timeout: 15_000 }); + // Wait for relay to accept at least 1 event (the publish is async after textarea clears) + let relayAccepts: string[] = []; + for (let i = 0; i < 30; i++) { + relayAccepts = wsMessages.filter((m) => m.startsWith("recv:") && m.includes('"OK"') && m.includes(",true,")); + if (relayAccepts.length > 0) break; + await bobPage.waitForTimeout(500); + } + console.log(`[e2e] Relay accepted ${relayAccepts.length} event(s)`); + // Verify no error message appeared in the UI const sendError = bobPage.locator(".warning em"); const hasError = await sendError @@ -66,9 +75,6 @@ test("bob sends a DM to alice via /dm page", async ({ browser }) => { } expect(hasError, "No send error should appear").toBeFalsy(); - // Verify the relay accepted both gift-wrapped events (one for recipient, one for sender copy) - const relayAccepts = wsMessages.filter((m) => m.startsWith("recv:") && m.includes('"OK"') && m.includes(",true,")); - console.log(`[e2e] Relay accepted ${relayAccepts.length} event(s)`); expect(relayAccepts.length, "Relay should accept at least 1 gift-wrapped event").toBeGreaterThanOrEqual(1); // Verify no "blocked" or relay rejection -- cgit v1.2.3