diff --git a/demos/src/Marks/Bold/React/index.html b/demos/src/Marks/Bold/React/index.html new file mode 100644 index 00000000..34469957 --- /dev/null +++ b/demos/src/Marks/Bold/React/index.html @@ -0,0 +1,15 @@ + + +
+ + + + + + + + diff --git a/demos/src/Marks/Bold/React/index.jsx b/demos/src/Marks/Bold/React/index.jsx new file mode 100644 index 00000000..27b180f6 --- /dev/null +++ b/demos/src/Marks/Bold/React/index.jsx @@ -0,0 +1,50 @@ +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 Bold from '@tiptap/extension-bold' + +export default () => { + const editor = useEditor({ + extensions: [Document, Paragraph, Text, Bold], + content: ` +This isn’t bold.
+This is bold.
+And this.
+This as well.
+Oh, and this!
+Cool, isn’t it!?
+Up to font weight 999!!!
+ `, + }) + + if (!editor) { + return null + } + + return ( + <> + + + + +Example Text
') + cy.get('.ProseMirror').type('{selectall}') + }) + }) + + it('should transform b tags to strong tags', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.setContent('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') + }) + }) + + it('sould omit b tags with normal font weight inline style', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.setContent('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') + }) + }) + + it('should transform any tag with bold inline style to strong tags', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.setContent('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') + + editor.commands.setContent('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') + + editor.commands.setContent('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') + + editor.commands.setContent('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') + }) + }) + + it('the button should make the selected text bold', () => { + cy.get('button:first').click() + + cy.get('.ProseMirror').find('strong').should('contain', 'Example Text') + }) + + it('the button should toggle the selected text bold', () => { + cy.get('button:first').click() + cy.get('.ProseMirror').type('{selectall}') + cy.get('button:first').click() + cy.get('.ProseMirror strong').should('not.exist') + }) + + it('should make the selected text bold when the keyboard shortcut is pressed', () => { + cy.get('.ProseMirror') + .trigger('keydown', { modKey: true, key: 'b' }) + .find('strong') + .should('contain', 'Example Text') + }) + + it('should toggle the selected text bold when the keyboard shortcut is pressed', () => { + cy.get('.ProseMirror') + .trigger('keydown', { modKey: true, key: 'b' }) + .find('strong') + .should('contain', 'Example Text') + + cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'b' }) + + cy.get('.ProseMirror strong').should('not.exist') + }) + + it('should make a bold text from the default markdown shortcut', () => { + cy.get('.ProseMirror').type('**Bold**').find('strong').should('contain', 'Bold') + }) + + it('should make a bold text from the alternative markdown shortcut', () => { + cy.get('.ProseMirror').type('__Bold__').find('strong').should('contain', 'Bold') + }) +})