blowater/app/UI/message-panel.test.tsx
BlowaterNostr e86101ae7f
5.0.0: Redesign & Rearchitecture (#380)
* remove nip-07 extension sign-in temporarily
* bring kind-1 back!
* separated relay views
2024-03-15 21:44:17 +08:00

63 lines
2.1 KiB
TypeScript

/** @jsx h */
import { fail } from "https://deno.land/std@0.176.0/testing/asserts.ts";
import { h, render } from "https://esm.sh/preact@10.17.1";
import { prepareEncryptedNostrEvent } from "../../libs/nostr.ts/event.ts";
import { InMemoryAccountContext, NostrKind } from "../../libs/nostr.ts/nostr.ts";
import { relays } from "../../libs/nostr.ts/relay-list.test.ts";
import { ConnectionPool } from "../../libs/nostr.ts/relay-pool.ts";
import { test_db_view, testEventBus } from "./_setup.test.ts";
import { DirectedMessageController } from "../features/dm.ts";
import { DM_List } from "./conversation-list.ts";
import { MessagePanel } from "./message-panel.tsx";
import { sleep } from "https://raw.githubusercontent.com/BlowaterNostr/csp/master/csp.ts";
const pool = new ConnectionPool();
pool.addRelayURL(relays[2]);
const database = await test_db_view();
const ctx = InMemoryAccountContext.Generate();
const dmController = new DirectedMessageController(ctx);
const event = await prepareEncryptedNostrEvent(ctx, {
content: `test`,
encryptKey: ctx.publicKey,
kind: NostrKind.DIRECT_MESSAGE,
tags: [
["p", ctx.publicKey.hex],
],
});
if (event instanceof Error) fail(event.message);
await dmController.addEvent(event);
const messages = dmController.getChatMessages(ctx.publicKey.hex);
for (let i = 10;; i++) {
messages.push({
author: ctx.publicKey,
content: `${i}`,
created_at: new Date(),
event: messages[0].event,
lamport: i,
type: "text",
});
render(
<div class="w-screen h-screen">
<MessagePanel
getters={{
profileGetter: database,
relayRecordGetter: database,
isUserBlocked: new DM_List(ctx).isUserBlocked,
getEventByID: database.getEventByID,
}}
myPublicKey={ctx.publicKey}
emit={testEventBus.emit}
eventSub={testEventBus}
messages={messages}
/>
</div>,
document.body,
);
await sleep(100);
}