diff --git a/packages/tiptap/test/Editor.spec.js b/packages/tiptap/test/Editor.spec.js index f6528046..e7a58819 100644 --- a/packages/tiptap/test/Editor.spec.js +++ b/packages/tiptap/test/Editor.spec.js @@ -1,7 +1,157 @@ import Editor from '../src/Utils/Editor' +import { + Blockquote, + CodeBlock, + HardBreak, + Heading, + OrderedList, + BulletList, + ListItem, + TodoItem, + TodoList, + Bold, + Code, + Italic, + Link, + Strike, + Underline, + History, +} from '../../tiptap-extensions' + test('can create editor', () => { const editor = new Editor() expect(editor).toBeDefined() }) + +test('set HTML, get HTML', () => { + const result = '

Lorem ipsum dolor sit amet.

' + + const editor = new Editor({ + content: result, + extensions: [ + new Bold(), + ], + }) + + expect(editor.getHTML()).toEqual(result) +}) + +test('set HTML, get JSON', () => { + const editor = new Editor({ + content: '

Lorem ipsum dolor sit amet.

', + extensions: [ + new Bold(), + ], + }) + + const result = { + type: 'doc', + content: [ + { + type: 'paragraph', + content: [ + { + type: 'text', + text: 'Lorem ', + }, + { + type: 'text', + marks: [ + { + type: 'bold', + }, + ], + text: 'ipsum', + }, + { + type: 'text', + text: ' dolor sit amet.', + }, + ], + }, + ], + } + + expect(editor.getJSON()).toEqual(result) +}) + +test('set JSON, get JSON', () => { + const result = { + type: 'doc', + content: [ + { + type: 'paragraph', + content: [ + { + type: 'text', + text: 'Lorem ', + }, + { + type: 'text', + marks: [ + { + type: 'bold', + }, + ], + text: 'ipsum', + }, + { + type: 'text', + text: ' dolor sit amet.', + }, + ], + }, + ], + } + + const editor = new Editor({ + content: result, + extensions: [ + new Bold(), + ], + }) + + expect(editor.getJSON()).toEqual(result) +}) + +test('set JSON, get HTML', () => { + const content = { + type: 'doc', + content: [ + { + type: 'paragraph', + content: [ + { + type: 'text', + text: 'Lorem ', + }, + { + type: 'text', + marks: [ + { + type: 'bold', + }, + ], + text: 'ipsum', + }, + { + type: 'text', + text: ' dolor sit amet.', + }, + ], + }, + ], + } + const result = '

Lorem ipsum dolor sit amet.

' + + const editor = new Editor({ + content, + extensions: [ + new Bold(), + ], + }) + + expect(editor.getHTML()).toEqual(result) +})