blowater/UI/conversation-list.test.tsx

45 lines
1.5 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 { Database_Contextual_View } from "../database.ts";
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";
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);
}
const database = await Database_Contextual_View.New(db, ctx);
2023-09-13 11:31:44 +00:00
if (database instanceof Error) {
fail(database.message);
}
2023-10-15 22:39:21 +00:00
const convoLists = new DM_List(ctx, new ProfileSyncer(database, new ConnectionPool()));
2023-09-23 21:33:30 +00:00
convoLists.addEvents(database.events);
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}
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();