From 5a1f8d7b6ae34ebc3147b8cc4ea6e39eaaaca7ba Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Mon, 23 Nov 2020 16:13:06 +0100 Subject: [PATCH] add tests for a few core commands --- .../integration/core/clearContent.spec.ts | 36 +++++++++++++++++++ .../integration/core/insertHTML.spec.ts | 36 +++++++++++++++++++ .../integration/core/setContent.spec.ts | 36 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 tests/cypress/integration/core/clearContent.spec.ts create mode 100644 tests/cypress/integration/core/insertHTML.spec.ts create mode 100644 tests/cypress/integration/core/setContent.spec.ts diff --git a/tests/cypress/integration/core/clearContent.spec.ts b/tests/cypress/integration/core/clearContent.spec.ts new file mode 100644 index 00000000..d0edde38 --- /dev/null +++ b/tests/cypress/integration/core/clearContent.spec.ts @@ -0,0 +1,36 @@ +/// + +import { Editor } from '@tiptap/core' +import Document from '@tiptap/extension-document' +import Paragraph from '@tiptap/extension-paragraph' +import Text from '@tiptap/extension-text' + +describe('clearContent', () => { + it('returns true when clearing the content', () => { + const editor = new Editor({ + extensions: [ + Document, + Paragraph, + Text, + ], + }) + + const command = editor.commands.clearContent() + + expect(command).to.be.true + }) + + it('clears the content when using clearContent', () => { + const editor = new Editor({ + extensions: [ + Document, + Paragraph, + Text, + ], + }) + + editor.commands.clearContent() + + expect(editor.getHTML()).to.eq('

') + }) +}) diff --git a/tests/cypress/integration/core/insertHTML.spec.ts b/tests/cypress/integration/core/insertHTML.spec.ts new file mode 100644 index 00000000..2c9cbfac --- /dev/null +++ b/tests/cypress/integration/core/insertHTML.spec.ts @@ -0,0 +1,36 @@ +/// + +import { Editor } from '@tiptap/core' +import Document from '@tiptap/extension-document' +import Paragraph from '@tiptap/extension-paragraph' +import Text from '@tiptap/extension-text' + +describe('insertHTML', () => { + it('returns true when inserting HTML', () => { + const editor = new Editor({ + extensions: [ + Document, + Paragraph, + Text, + ], + }) + + const command = editor.commands.insertHTML('

Cindy Lauper

') + + expect(command).to.be.true + }) + + it('appends the content when using insertHTML', () => { + const editor = new Editor({ + extensions: [ + Document, + Paragraph, + Text, + ], + }) + + editor.commands.insertHTML('

Cindy Lauper

') + + expect(editor.getHTML()).to.eq('

Cindy Lauper

') + }) +}) diff --git a/tests/cypress/integration/core/setContent.spec.ts b/tests/cypress/integration/core/setContent.spec.ts new file mode 100644 index 00000000..b5394269 --- /dev/null +++ b/tests/cypress/integration/core/setContent.spec.ts @@ -0,0 +1,36 @@ +/// + +import { Editor } from '@tiptap/core' +import Document from '@tiptap/extension-document' +import Paragraph from '@tiptap/extension-paragraph' +import Text from '@tiptap/extension-text' + +describe('setContent', () => { + it('returns true when setting the content', () => { + const editor = new Editor({ + extensions: [ + Document, + Paragraph, + Text, + ], + }) + + const command = editor.commands.setContent('

Cindy Lauper

') + + expect(command).to.be.true + }) + + it('replaces the content when using setContent', () => { + const editor = new Editor({ + extensions: [ + Document, + Paragraph, + Text, + ], + }) + + editor.commands.setContent('

Cindy Lauper

') + + expect(editor.getHTML()).to.eq('

Cindy Lauper

') + }) +})