Files
bitvid/tests/e2e/dm-scenarios.spec.ts
T
google-labs-jules[bot]andPR0M3TH3AN a10899dacc Fix: E2E test robustness (feed visibility, login state)
- Add `s` tag to seeded video events in `bitvidTestFixture.ts` to pass schema validation and appear in feeds.
- Update `js/testHarness.js` `loginWithNsec` to call `app.authService.login()`, ensuring UI state reflects login.
- Update `js/testHarness.js` `logout` to be async and use `app.requestLogout()`.
- Fix TypeScript error in `tests/e2e/dm-scenarios.spec.ts`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-22 04:08:13 +00:00

61 lines
2.2 KiB
TypeScript

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: any = {};
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');
}
});
});