blowater/UI/conversation-list.test.tsx

47 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-09-13 11:31:44 +00:00
/** @jsx h */
import { h, render } from "https://esm.sh/preact@10.17.1";
2023-09-23 21:54:13 +00:00
import { ConversationList } from "./conversation-list.tsx";
2023-09-13 11:31:44 +00:00
import { fail } from "https://deno.land/std@0.176.0/testing/asserts.ts";
import { Datebase_View } from "../database.ts";
2023-09-13 11:31:44 +00:00
import { PrivateKey } from "../lib/nostr-ts/key.ts";
2023-09-23 21:33:30 +00:00
import { InMemoryAccountContext } from "../lib/nostr-ts/nostr.ts";
import { testEventBus } from "./_setup.test.ts";
2023-09-13 11:31:44 +00:00
import { initialModel } from "./app_model.ts";
2023-10-15 22:39:21 +00:00
import { DM_List } from "./conversation-list.ts";
2023-09-23 21:33:30 +00:00
import { NewIndexedDB } from "./dexie-db.ts";
import { ProfileSyncer } from "../features/profile.ts";
2023-11-03 13:09:13 +00:00
import { ConnectionPool } from "../lib/nostr-ts/relay-pool.ts";
import { OtherConfig } from "./config-other.ts";
import { GroupChatSyncer, GroupMessageController } from "../features/gm.ts";
2023-09-13 11:31:44 +00:00
const ctx = InMemoryAccountContext.New(PrivateKey.Generate());
2023-09-23 21:33:30 +00:00
const db = NewIndexedDB();
if (db instanceof Error) {
fail(db.message);
}
2023-11-17 07:06:11 +00:00
const database = await Datebase_View.New(db, db, db);
const pool = new ConnectionPool();
const profileSyncer = new ProfileSyncer(database, pool);
const convoLists = new DM_List(ctx, profileSyncer);
const gmc = new GroupMessageController(ctx, new GroupChatSyncer(database, pool), profileSyncer);
2023-11-17 07:06:11 +00:00
convoLists.addEvents(Array.from(database.events.values()));
2023-09-13 11:31:44 +00:00
const model = initialModel();
2023-09-23 21:33:30 +00:00
const view = () =>
render(
<ConversationList
convoListRetriever={convoLists}
hasNewMessages={new Set()}
pinListGetter={OtherConfig.Empty()}
2023-10-07 20:40:18 +00:00
eventBus={testEventBus}
2023-09-23 21:33:30 +00:00
emit={testEventBus.emit}
profileGetter={database}
groupChatListGetter={gmc}
2023-09-23 21:33:30 +00:00
/>,
document.body,
);
2023-09-13 11:31:44 +00:00
2023-09-23 21:33:30 +00:00
view();