add an interactive demo and tests to the underline extension
This commit is contained in:
33
docs/src/demos/Extensions/Underline/index.spec.js
Normal file
33
docs/src/demos/Extensions/Underline/index.spec.js
Normal file
@@ -0,0 +1,33 @@
|
||||
context('/api/extensions/underline', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('/api/extensions/underline')
|
||||
|
||||
cy.get('.ProseMirror').window().then(window => {
|
||||
const { editor } = window
|
||||
editor.setContent('<p>Example Text</p>')
|
||||
editor.focus().selectAll()
|
||||
})
|
||||
})
|
||||
|
||||
describe('bold', () => {
|
||||
it('the button should underline the selected text', () => {
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.ProseMirror').contains('u', 'Example Text')
|
||||
})
|
||||
|
||||
it('the button should toggle the selected text underline', () => {
|
||||
cy.get('.demo__preview button:first').dblclick({ force: true })
|
||||
cy.get('.ProseMirror u').should('not.exist')
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should underline the selected text', () => {
|
||||
cy.get('.ProseMirror').type('{meta}u', {force: true})
|
||||
cy.get('.ProseMirror').contains('u', 'Example Text')
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should toggle the selected text underline', () => {
|
||||
cy.get('.ProseMirror').type('{meta}u', {force: true}).type('{meta}u', {force: true})
|
||||
cy.get('.ProseMirror u').should('not.exist')
|
||||
})
|
||||
})
|
||||
})
|
||||
52
docs/src/demos/Extensions/Underline/index.vue
Normal file
52
docs/src/demos/Extensions/Underline/index.vue
Normal file
@@ -0,0 +1,52 @@
|
||||
<template>
|
||||
<div v-if="editor">
|
||||
<button @click="editor.focus().underline()" :class="{ 'is-active': editor.isActive('underline') }">
|
||||
underline
|
||||
</button>
|
||||
|
||||
<editor-content :editor="editor" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Editor } from '@tiptap/core'
|
||||
import { EditorContent } from '@tiptap/vue'
|
||||
import Document from '@tiptap/extension-document'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import Underline from '@tiptap/extension-underline'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorContent,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
extensions: [
|
||||
Document(),
|
||||
Paragraph(),
|
||||
Text(),
|
||||
Underline(),
|
||||
],
|
||||
content: `
|
||||
<p>There is no underline here.</p>
|
||||
<p><u>This is underlined though.</u></p>
|
||||
<p style="text-decoration: underline">And this as well.</p>
|
||||
`,
|
||||
})
|
||||
|
||||
window.editor = this.editor
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user