1- import { Editor } from '@tiptap/core' ;
21import { render } from 'react-email' ;
3- import { afterEach , describe , expect , it } from 'vitest' ;
42import { DEFAULT_STYLES } from '../utils/default-styles' ;
53import { Button } from './button' ;
6- import { StarterKit } from './index' ;
74
85const buttonStyle = { ...DEFAULT_STYLES . reset , ...DEFAULT_STYLES . button } ;
96
107describe ( 'EditorButton Node' , ( ) => {
11- let editor : Editor | null = null ;
12-
13- afterEach ( ( ) => {
14- editor ?. destroy ( ) ;
15- editor = null ;
16- } ) ;
17-
188 it ( 'renders React Email properly' , async ( ) => {
199 const Component = Button . config . renderToReactEmail ;
2010 expect ( Component ) . toBeDefined ( ) ;
@@ -38,60 +28,4 @@ describe('EditorButton Node', () => {
3828 ) ,
3929 ) . toMatchSnapshot ( ) ;
4030 } ) ;
41-
42- it ( 'preserves href through HTML round-trip' , ( ) => {
43- editor = new Editor ( {
44- extensions : [ StarterKit ] ,
45- content : {
46- type : 'doc' ,
47- content : [
48- {
49- type : 'container' ,
50- content : [
51- {
52- type : 'button' ,
53- attrs : { href : 'https://example.com' } ,
54- content : [ { type : 'text' , text : 'Click me' } ] ,
55- } ,
56- ] ,
57- } ,
58- ] ,
59- } ,
60- } ) ;
61-
62- const html = editor . getHTML ( ) ;
63- expect ( html ) . toContain ( 'data-href="https://example.com"' ) ;
64- expect ( html ) . toContain ( 'href="https://example.com"' ) ;
65-
66- editor . commands . setContent ( html ) ;
67-
68- const json = editor . getJSON ( ) ;
69- const findButton = ( nodes : typeof json . content ) : typeof json | undefined =>
70- nodes ?. reduce < typeof json | undefined > (
71- ( found , n ) =>
72- found ?? ( n . type === 'button' ? n : findButton ( n . content ?? [ ] ) ) ,
73- undefined ,
74- ) ;
75- const buttonNode = findButton ( json . content ?? [ ] ) ;
76- expect ( buttonNode ?. attrs ?. href ) . toBe ( 'https://example.com' ) ;
77- } ) ;
78-
79- it ( 'parses data-href back to href when href attribute is missing' , ( ) => {
80- editor = new Editor ( { extensions : [ StarterKit ] } ) ;
81-
82- const htmlWithOnlyDataHref =
83- '<div class="align-left"><a class="node-button button" data-id="react-email-button" data-href="https://restored.example.com">Restore me</a></div>' ;
84-
85- editor . commands . setContent ( htmlWithOnlyDataHref ) ;
86-
87- const json = editor . getJSON ( ) ;
88- const findButton = ( nodes : typeof json . content ) : typeof json | undefined =>
89- nodes ?. reduce < typeof json | undefined > (
90- ( found , n ) =>
91- found ?? ( n . type === 'button' ? n : findButton ( n . content ?? [ ] ) ) ,
92- undefined ,
93- ) ;
94- const buttonNode = findButton ( json . content ?? [ ] ) ;
95- expect ( buttonNode ?. attrs ?. href ) . toBe ( 'https://restored.example.com' ) ;
96- } ) ;
9731} ) ;
0 commit comments