diff --git a/demos/src/Marks/Italic/React/index.html b/demos/src/Marks/Italic/React/index.html new file mode 100644 index 00000000..7b9dc42f --- /dev/null +++ b/demos/src/Marks/Italic/React/index.html @@ -0,0 +1,15 @@ + + + + + + + +
+ + + diff --git a/demos/src/Marks/Italic/React/index.jsx b/demos/src/Marks/Italic/React/index.jsx new file mode 100644 index 00000000..c1ecfe0b --- /dev/null +++ b/demos/src/Marks/Italic/React/index.jsx @@ -0,0 +1,47 @@ +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 Italic from '@tiptap/extension-italic' + +export default () => { + const editor = useEditor({ + extensions: [Document, Paragraph, Text, Italic], + content: ` +

This isn’t italic.

+

This is italic.

+

And this.

+

This as well.

+ `, + }) + + if (!editor) { + return null + } + + return ( + <> + + + + + + + ) +} diff --git a/demos/src/Marks/Italic/React/index.spec.js b/demos/src/Marks/Italic/React/index.spec.js new file mode 100644 index 00000000..1ff47583 --- /dev/null +++ b/demos/src/Marks/Italic/React/index.spec.js @@ -0,0 +1,64 @@ +context('/src/Marks/Italic/React/', () => { + before(() => { + cy.visit('/src/Marks/Italic/React/') + }) + + beforeEach(() => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.setContent('

Example Text

') + cy.get('.ProseMirror').type('{selectall}') + }) + }) + + it('i tags should be transformed to em tags', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.setContent('

Example Text

') + expect(editor.getHTML()).to.eq('

Example Text

') + }) + }) + + it('i tags with normal font style should be omitted', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.setContent('

Example Text

') + expect(editor.getHTML()).to.eq('

Example Text

') + }) + }) + + it('generic tags with italic style should be transformed to strong tags', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.commands.setContent('

Example Text

') + expect(editor.getHTML()).to.eq('

Example Text

') + }) + }) + + it('the button should make the selected text italic', () => { + cy.get('button:first').click() + + cy.get('.ProseMirror').find('em').should('contain', 'Example Text') + }) + + it('the button should toggle the selected text italic', () => { + cy.get('button:first').click() + + cy.get('.ProseMirror').type('{selectall}') + + cy.get('button:first').click() + + cy.get('.ProseMirror em').should('not.exist') + }) + + it('the keyboard shortcut should make the selected text italic', () => { + cy.get('.ProseMirror') + .trigger('keydown', { modKey: true, key: 'i' }) + .find('em') + .should('contain', 'Example Text') + }) + + it('the keyboard shortcut should toggle the selected text italic', () => { + cy.get('.ProseMirror') + .trigger('keydown', { modKey: true, key: 'i' }) + .trigger('keydown', { modKey: true, key: 'i' }) + .find('em') + .should('not.exist') + }) +})