aboutsummaryrefslogtreecommitdiffstats
path: root/test/e2e/dm-send.spec.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-05 15:05:37 -0800
committerAdam Soltys <[email protected]>2026-03-05 15:51:36 -0800
commit4c519faaf748cea25f9d0be87dd0f3e09d7bae4c (patch)
tree1fbda1930d8a8f8d6d03871274105dbfb7e1caa8 /test/e2e/dm-send.spec.ts
parent4a74d51e92365a731a2e5322783b88a39e14f046 (diff)
downloadcoinos-ui-4c519faaf748cea25f9d0be87dd0f3e09d7bae4c.tar.gz
coinos-ui-4c519faaf748cea25f9d0be87dd0f3e09d7bae4c.zip
android hce nfc
Diffstat (limited to 'test/e2e/dm-send.spec.ts')
-rw-r--r--test/e2e/dm-send.spec.ts44
1 files changed, 25 insertions, 19 deletions
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