Add Paragraph demo for React

This commit is contained in:
Sven Adlung 2021-11-16 15:15:03 +01:00
parent cbc717334d
commit ddd5545e9a
3 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="app"></div>
<script type="module">
import setup from "../../../../setup/react.ts";
import source from "@source";
setup("Nodes/Paragraph", source);
</script>
</body>
</html>

View File

@ -0,0 +1,20 @@
import React from 'react'
import { useEditor, EditorContent } from '@tiptap/react'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
export default () => {
const editor = useEditor({
extensions: [Document, Paragraph, Text],
content: `
<p>The Paragraph extension is not required, but its very likely you want to use it. Its needed to write paragraphs of text. 🤓</p>
`,
})
if (!editor) {
return null
}
return <EditorContent editor={editor} />
}

View File

@ -0,0 +1,45 @@
context('/src/Nodes/Paragraph/React/', () => {
before(() => {
cy.visit('/src/Nodes/Paragraph/React/')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.clearContent()
})
})
it('should parse paragraphs correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p>Example Text</p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
editor.commands.setContent('<p><x-unknown>Example Text</x-unknown></p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
editor.commands.setContent('<p style="display: block;">Example Text</p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
})
})
it('text should be wrapped in a paragraph by default', () => {
cy.get('.ProseMirror').type('Example Text').find('p').should('contain', 'Example Text')
})
it('enter should make a new paragraph', () => {
cy.get('.ProseMirror')
.type('First Paragraph{enter}Second Paragraph')
.find('p')
.should('have.length', 2)
cy.get('.ProseMirror').find('p:first').should('contain', 'First Paragraph')
cy.get('.ProseMirror').find('p:nth-child(2)').should('contain', 'Second Paragraph')
})
it('backspace should remove the second paragraph', () => {
cy.get('.ProseMirror').type('{enter}').find('p').should('have.length', 2)
cy.get('.ProseMirror').type('{backspace}').find('p').should('have.length', 1)
})
})