Add HorizontaleRule demo for React

This commit is contained in:
Sven Adlung 2021-11-16 14:56:07 +01:00
parent e8c76a75a0
commit 7d6ecf31d8
4 changed files with 109 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/HorizontalRule", source);
</script>
</body>
</html>

View File

@ -0,0 +1,34 @@
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'
import HorizontalRule from '@tiptap/extension-horizontal-rule'
import './styles.scss'
export default () => {
const editor = useEditor({
extensions: [Document, Paragraph, Text, HorizontalRule],
content: `
<p>This is a paragraph.</p>
<hr>
<p>And this is another paragraph.</p>
<hr>
<p>But between those paragraphs are horizontal rules.</p>
`,
})
if (!editor) {
return null
}
return (
<>
<button onClick={() => editor.chain().focus().setHorizontalRule().run()}>
setHorizontalRule
</button>
<EditorContent editor={editor} />
</>
)
}

View File

@ -0,0 +1,57 @@
context('/src/Nodes/HorizontalRule/React/', () => {
before(() => {
cy.visit('/src/Nodes/HorizontalRule/React/')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p>Example Text</p>')
})
})
it('should parse horizontal rules correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p>Example Text</p><hr>')
expect(editor.getHTML()).to.eq('<p>Example Text</p><hr>')
})
})
it('should parse horizontal rules with self-closing tag correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p>Example Text</p><hr />')
expect(editor.getHTML()).to.eq('<p>Example Text</p><hr>')
})
})
it('the button should add a horizontal rule', () => {
cy.get('.ProseMirror hr').should('not.exist')
cy.get('button:first').click()
cy.get('.ProseMirror hr').should('exist')
})
it('the default markdown shortcut should add a horizontal rule', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.clearContent()
cy.get('.ProseMirror hr').should('not.exist')
cy.get('.ProseMirror').type('---')
cy.get('.ProseMirror hr').should('exist')
})
})
it('the alternative markdown shortcut should add a horizontal rule', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.clearContent()
cy.get('.ProseMirror hr').should('not.exist')
cy.get('.ProseMirror').type('___ ')
cy.get('.ProseMirror hr').should('exist')
})
})
})

View File

@ -0,0 +1,3 @@
hr.ProseMirror-selectednode {
border-top: 1px solid #68cef8;
}