A calm place to write long-form, and publish it to the open social web.
skypress.blog/
1import { describe, expect, it, beforeAll } from 'vitest';
2import { create, toHTMLString, applyFormat } from '@wordpress/rich-text';
3import { registerMentionFormat, MENTION_FORMAT } from './mention-format';
4
5beforeAll( () => {
6 registerMentionFormat();
7} );
8
9describe( 'skypress/mention format', () => {
10 it( 'round-trips an anchor carrying href + data-did, keeping the text', () => {
11 // Build a value "@alice.bsky.social" and apply the mention format across it.
12 const value = create( { text: '@alice.bsky.social' } );
13 const formatted = applyFormat(
14 value,
15 // The bundled `RichTextFormat` type only models `{ type }`; the runtime
16 // `attributes` map is real, so cast to satisfy the incomplete type.
17 {
18 type: MENTION_FORMAT,
19 attributes: {
20 url: 'https://bsky.app/profile/alice.bsky.social',
21 did: 'did:plc:alice',
22 },
23 } as unknown as Parameters< typeof applyFormat >[ 1 ],
24 0,
25 value.text.length
26 );
27 const html = toHTMLString( { value: formatted } );
28 expect( html ).toContain( 'href="https://bsky.app/profile/alice.bsky.social"' );
29 expect( html ).toContain( 'data-did="did:plc:alice"' );
30 expect( html ).toContain( '@alice.bsky.social' );
31 expect( html ).toContain( 'class="skypress-mention"' );
32 } );
33
34 it( 'is idempotent — calling register twice does not throw', () => {
35 expect( () => registerMentionFormat() ).not.toThrow();
36 } );
37} );