-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add additional unit tests for hastags before a breakline
- Loading branch information
1 parent
9fa7224
commit 7af4b1a
Showing
3 changed files
with
135 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable no-empty-pattern, */ | ||
import { Editor } from '@tiptap/core' | ||
import StarterKit from '@tiptap/starter-kit' | ||
import { Markdown as MarkdownExtension } from 'tiptap-markdown' | ||
import { test as base } from 'vitest' | ||
import { NostrExtension } from '../extensions/NostrExtension' | ||
|
||
const extensions = [StarterKit.configure({ history: false }), NostrExtension] | ||
|
||
const editor = new Editor({ extensions }) | ||
|
||
type Fixtures = { | ||
editor: typeof editor | ||
editorMarkdown: Editor | ||
editorUserAbout: Editor | ||
} | ||
|
||
// We ideally want to have a single editor instance to parse markdown and user abouts, | ||
// But currently no ideal way to dynamically load extensions | ||
export const test = base.extend<Fixtures>({ | ||
editor: ({}, use) => { | ||
return use(editor) | ||
}, | ||
editorMarkdown: ({}, use) => { | ||
return use( | ||
new Editor({ | ||
extensions: [ | ||
StarterKit.configure({ history: false }), | ||
NostrExtension, | ||
MarkdownExtension.configure({ breaks: true }), | ||
], | ||
}), | ||
) | ||
}, | ||
editorUserAbout: ({}, use) => { | ||
return use( | ||
new Editor({ | ||
extensions: [ | ||
StarterKit.configure({ history: false }), | ||
NostrExtension.configure({ image: false, video: false }), | ||
], | ||
}), | ||
) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { nip19 } from 'nostr-tools' | ||
import type { NostrStorage } from '../extensions/NostrExtension' | ||
import { test } from './fixtures' | ||
import { fakeEvent } from './testUtils' | ||
|
||
describe('Storage', () => { | ||
test('assert getTags()', ({ editor }) => { | ||
const event = fakeEvent({ content: `text #123 #456 text #123 text #abc` }) | ||
editor.commands.setEventContent(event) | ||
const storage = editor.storage.nostr as NostrStorage | ||
expect(storage.getTags()).toEqual([{ tag: '#123' }, { tag: '#456' }, { tag: '#123' }, { tag: '#abc' }]) | ||
}) | ||
|
||
test('assert getNprofiles()', ({ editor }) => { | ||
const ref = fakeEvent() | ||
const decoded = { relays: [], pubkey: ref.pubkey } | ||
const nprofile = nip19.nprofileEncode(decoded) | ||
const event = fakeEvent({ content: `${nprofile}` }) | ||
editor.commands.setEventContent(event) | ||
const storage = editor.storage.nostr as NostrStorage | ||
expect(storage.getNprofiles()).toEqual([{ ...decoded, nprofile }]) | ||
}) | ||
|
||
test('assert getNevents()', ({ editor }) => { | ||
const ref = fakeEvent() | ||
const decoded = { kind: 1, id: ref.id, relays: [], author: ref.pubkey } | ||
const nevent = nip19.neventEncode(decoded) | ||
const event = fakeEvent({ content: `${nevent}` }) | ||
editor.commands.setEventContent(event) | ||
const storage = editor.storage.nostr as NostrStorage | ||
expect(storage.getNevents()).toEqual([{ ...decoded, nevent }]) | ||
}) | ||
|
||
test('assert getNAddress()', ({ editor }) => { | ||
const ref = fakeEvent() | ||
const decoded = { kind: 1, identifier: ref.id, relays: [], pubkey: ref.pubkey } | ||
const naddr = nip19.naddrEncode(decoded) | ||
const event = fakeEvent({ content: `${naddr}` }) | ||
editor.commands.setEventContent(event) | ||
const storage = editor.storage.nostr as NostrStorage | ||
expect(storage.getNaddress()).toEqual([{ ...decoded, naddr }]) | ||
}) | ||
}) |