diff --git a/demos/src/Nodes/Heading/React/index.html b/demos/src/Nodes/Heading/React/index.html new file mode 100644 index 00000000..b8d54fbb --- /dev/null +++ b/demos/src/Nodes/Heading/React/index.html @@ -0,0 +1,15 @@ + + +
+ + + + + + + + diff --git a/demos/src/Nodes/Heading/React/index.jsx b/demos/src/Nodes/Heading/React/index.jsx new file mode 100644 index 00000000..81baf9e4 --- /dev/null +++ b/demos/src/Nodes/Heading/React/index.jsx @@ -0,0 +1,54 @@ +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 Heading from '@tiptap/extension-heading' + +export default () => { + const editor = useEditor({ + extensions: [ + Document, + Paragraph, + Text, + Heading.configure({ + levels: [1, 2, 3], + }), + ], + content: ` +Example Text
') + cy.get('.ProseMirror').type('{selectall}') + }) + }) + + const headings = ['Example Text
') + }) + }) + + it('the button should make the selected line a h1', () => { + cy.get('.ProseMirror h1').should('not.exist') + + cy.get('button:nth-child(1)').click() + + cy.get('.ProseMirror').find('h1').should('contain', 'Example Text') + }) + + it('the button should make the selected line a h2', () => { + cy.get('.ProseMirror h2').should('not.exist') + + cy.get('button:nth-child(2)').click() + + cy.get('.ProseMirror').find('h2').should('contain', 'Example Text') + }) + + it('the button should make the selected line a h3', () => { + cy.get('.ProseMirror h3').should('not.exist') + + cy.get('button:nth-child(3)').click() + + cy.get('.ProseMirror').find('h3').should('contain', 'Example Text') + }) + + it('the button should toggle the heading', () => { + cy.get('.ProseMirror h1').should('not.exist') + + cy.get('button:nth-child(1)').click() + + cy.get('.ProseMirror').find('h1').should('contain', 'Example Text') + + cy.get('button:nth-child(1)').click() + + cy.get('.ProseMirror h1').should('not.exist') + }) + + it('should make the paragraph a h1 keyboard shortcut is pressed', () => { + cy.get('.ProseMirror') + .trigger('keydown', { modKey: true, altKey: true, key: '1' }) + .find('h1') + .should('contain', 'Example Text') + }) + + it('should make the paragraph a h2 keyboard shortcut is pressed', () => { + cy.get('.ProseMirror') + .trigger('keydown', { modKey: true, altKey: true, key: '2' }) + .find('h2') + .should('contain', 'Example Text') + }) + + it('should make the paragraph a h3 keyboard shortcut is pressed', () => { + cy.get('.ProseMirror') + .trigger('keydown', { modKey: true, altKey: true, key: '3' }) + .find('h3') + .should('contain', 'Example Text') + }) + + it('should make a h1 from the default markdown shortcut', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.clearContent() + }) + + cy.get('.ProseMirror').type('# Headline').find('h1').should('contain', 'Headline') + }) + + it('should make a h2 from the default markdown shortcut', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.clearContent() + }) + + cy.get('.ProseMirror').type('## Headline').find('h2').should('contain', 'Headline') + }) + + it('should make a h3 from the default markdown shortcut', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.clearContent() + }) + + cy.get('.ProseMirror').type('### Headline').find('h3').should('contain', 'Headline') + }) +})