Add Paragraph demo for React
This commit is contained in:
15
demos/src/Nodes/Paragraph/React/index.html
Normal file
15
demos/src/Nodes/Paragraph/React/index.html
Normal 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>
|
||||||
20
demos/src/Nodes/Paragraph/React/index.jsx
Normal file
20
demos/src/Nodes/Paragraph/React/index.jsx
Normal 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 it’s very likely you want to use it. It’s needed to write paragraphs of text. 🤓</p>
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!editor) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return <EditorContent editor={editor} />
|
||||||
|
}
|
||||||
45
demos/src/Nodes/Paragraph/React/index.spec.js
Normal file
45
demos/src/Nodes/Paragraph/React/index.spec.js
Normal 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)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user