blowater/app/UI/editor.test.tsx

68 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-06-30 14:05:57 +00:00
/** @jsx h */
import { h, render } from "preact";
2023-06-30 14:05:57 +00:00
import { Editor } from "./editor.tsx";
import { prepareProfileEvent, testEventBus } from "./_setup.test.ts";
import { InMemoryAccountContext, NostrKind } from "@blowater/nostr-sdk";
2024-08-29 08:49:13 +00:00
import { prepareEncryptedNostrEvent, prepareNostrEvent } from "@blowater/nostr-sdk";
2024-04-12 09:04:58 +00:00
import { getTags, Parsed_Event, Profile_Nostr_Event } from "../nostr.ts";
import { NostrEvent } from "@blowater/nostr-sdk";
2024-03-23 08:15:56 +00:00
2024-04-12 09:04:58 +00:00
const author = InMemoryAccountContext.Generate();
const event = await prepareEncryptedNostrEvent(author, {
encryptKey: author.publicKey,
kind: NostrKind.DIRECT_MESSAGE,
tags: [["p", InMemoryAccountContext.Generate().publicKey.hex]],
content: "hi",
}) as NostrEvent<NostrKind.DIRECT_MESSAGE>;
const parsedEvent: Parsed_Event = {
...event,
parsedTags: getTags(event),
publicKey: author.publicKey,
};
const onlyName = await prepareProfileEvent(author, { name: "test_name" });
const onlyDisplayName = await prepareProfileEvent(author, { display_name: "test_display_name" });
const empty = await prepareProfileEvent(author, {});
2024-04-12 09:04:58 +00:00
function TextBook() {
return (
<div class="w-screen h-screen flex-col items-center justify-center gap-2">
<EditorTest />
2024-05-24 09:54:27 +00:00
<EditorTest nip96 />
2024-04-12 09:04:58 +00:00
<EditorTest profileEvent={onlyName} />
<EditorTest profileEvent={onlyDisplayName} />
<EditorTest profileEvent={empty} />
</div>
);
2024-03-23 08:15:56 +00:00
}
2023-06-30 14:05:57 +00:00
2024-04-12 09:04:58 +00:00
testEventBus.emit({
type: "ReplyToMessage",
event: parsedEvent,
});
function EditorTest(props: {
profileEvent?: Profile_Nostr_Event;
2024-05-24 09:54:27 +00:00
nip96?: boolean;
2024-04-12 09:04:58 +00:00
}) {
const { profileEvent } = props;
return (
2023-12-22 06:55:15 +00:00
<Editor
placeholder="Message @xxx"
maxHeight="50vh"
emit={testEventBus.emit}
2024-04-12 09:04:58 +00:00
sub={testEventBus}
2024-03-23 08:15:56 +00:00
getters={{
2024-04-12 09:04:58 +00:00
getProfileByPublicKey: () => profileEvent,
getProfilesByText: () => [onlyName, onlyDisplayName, empty],
2024-03-23 08:15:56 +00:00
}}
2024-05-24 09:54:27 +00:00
nip96={props.nip96}
2023-12-22 06:55:15 +00:00
/>
2024-04-12 09:04:58 +00:00
);
}
render(<TextBook />, document.body);