move everything around, add more content and a first test for images

This commit is contained in:
Hans Pagel
2020-11-03 16:43:35 +01:00
parent 9bcdb57f14
commit 34a3a7fe26
64 changed files with 177 additions and 70 deletions

View File

@@ -0,0 +1,91 @@
context('/api/marks/bold', () => {
before(() => {
cy.visit('/api/marks/bold')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example Text</p>')
editor.selectAll()
})
})
it('should transform b tags to strong tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><b>Example Text</b></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
})
})
it('sould omit b tags with normal font weight inline style', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><b style="font-weight: normal">Example Text</b></p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
})
})
it('should transform any tag with bold inline style to strong tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><span style="font-weight: bold">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
editor.setContent('<p><span style="font-weight: bolder">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
editor.setContent('<p><span style="font-weight: 500">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
editor.setContent('<p><span style="font-weight: 900">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><strong>Example Text</strong></p>')
})
})
it('the button should make the selected text bold', () => {
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.find('strong')
.should('contain', 'Example Text')
})
it('the button should toggle the selected text bold', () => {
cy.get('.demo__preview button:first').click()
cy.get('.ProseMirror').type('{selectall}')
cy.get('.demo__preview button:first').click()
cy.get('.ProseMirror strong').should('not.exist')
})
it('the keyboard shortcut should make the selected text bold', () => {
cy.get('.ProseMirror')
.trigger('keydown', { modKey: true, key: 'b' })
.find('strong')
.should('contain', 'Example Text')
})
it('the keyboard shortcut should toggle the selected text bold', () => {
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')
})
})

View File

@@ -0,0 +1,54 @@
<template>
<div v-if="editor">
<button @click="editor.chain().focus().bold().run()" :class="{ 'is-active': editor.isActive('bold') }">
bold
</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 Bold from '@tiptap/extension-bold'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document(),
Paragraph(),
Text(),
Bold(),
],
content: `
<p>This isnt bold.</p>
<p><strong>This is bold.</strong></p>
<p><b>And this.</b></p>
<p style="font-weight: bold">This as well.</p>
<p style="font-weight: bolder">Oh, and this!</p>
<p style="font-weight: 500">Cool, isnt it!?</p>
<p style="font-weight: 999">Up to font weight 999!!!</p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>

View File

@@ -0,0 +1,52 @@
context('/api/marks/code', () => {
before(() => {
cy.visit('/api/marks/code')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example Text</p>')
editor.selectAll()
})
})
it('should parse code tags correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><code>Example Text</code></p>')
expect(editor.getHTML()).to.eq('<p><code>Example Text</code></p>')
editor.setContent('<code>Example Text</code>')
expect(editor.getHTML()).to.eq('<p><code>Example Text</code></p>')
})
})
it('should mark the selected text as inline code', () => {
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.find('code')
.should('contain', 'Example Text')
})
it('should toggle the selected text as inline code', () => {
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.type('{selectall}')
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror code')
.should('not.exist')
})
it('should make inline code from the markdown shortcut', () => {
cy.get('.ProseMirror')
.type('`Example`')
.find('code')
.should('contain', 'Example')
})
})

View File

@@ -0,0 +1,49 @@
<template>
<div v-if="editor">
<button @click="editor.chain().focus().code().run()" :class="{ 'is-active': editor.isActive('code') }">
code
</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 Code from '@tiptap/extension-code'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document(),
Paragraph(),
Text(),
Code(),
],
content: `
<p>This isnt code.</p>
<p><code>This is code.</code></p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>

View File

@@ -0,0 +1,71 @@
context('/api/marks/italic', () => {
before(() => {
cy.visit('/api/marks/italic')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example Text</p>')
editor.selectAll()
})
})
it('i tags should be transformed to em tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><i>Example Text</i></p>')
expect(editor.getHTML()).to.eq('<p><em>Example Text</em></p>')
})
})
it('i tags with normal font style should be omitted', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><i style="font-style: normal">Example Text</i></p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
})
})
it('generic tags with italic style should be transformed to strong tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><span style="font-style: italic">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><em>Example Text</em></p>')
})
})
it('the button should make the selected text italic', () => {
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.find('em')
.should('contain', 'Example Text')
})
it('the button should toggle the selected text italic', () => {
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.type('{selectall}')
cy.get('.demo__preview 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')
})
})

View File

@@ -0,0 +1,51 @@
<template>
<div v-if="editor">
<button @click="editor.chain().focus().italic().run()" :class="{ 'is-active': editor.isActive('italic') }">
italic
</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 Italic from '@tiptap/extension-italic'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document(),
Paragraph(),
Text(),
Italic(),
],
content: `
<p>This isnt italic.</p>
<p><em>This is italic.</em></p>
<p><i>And this.</i></p>
<p style="font-style: italic">This as well.</p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>

View File

@@ -0,0 +1,73 @@
context('/api/marks/link', () => {
before(() => {
cy.visit('/api/marks/link')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example Text</p>')
editor.selectAll()
})
})
it('should parse a tags correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><a href="#">Example Text</a></p>')
expect(editor.getHTML()).to.eq('<p><a href="#" target="_blank" rel="noopener noreferrer nofollow">Example Text</a></p>')
})
})
it('should parse a tags with target attribute correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><a href="#" target="_self">Example Text</a></p>')
expect(editor.getHTML()).to.eq('<p><a href="#" target="_self" rel="noopener noreferrer nofollow">Example Text</a></p>')
})
})
it('should parse a tags with rel attribute correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><a href="#" rel="follow">Example Text</a></p>')
expect(editor.getHTML()).to.eq('<p><a href="#" target="_blank" rel="noopener noreferrer nofollow">Example Text</a></p>')
})
})
it('the button should add a link to the selected text', () => {
cy.window().then(win => {
cy.stub(win, 'prompt').returns('https://tiptap.dev')
cy.get('.demo__preview button:first')
.click()
cy.window().its('prompt').should('be.called')
cy.get('.ProseMirror')
.find('a')
.should('contain', 'Example Text')
.should('have.attr', 'href', 'https://tiptap.dev')
})
})
const validUrls = [
'https://example.com',
'https://example.com/with-path',
'http://example.com/with-http',
'https://www.example.com/with-www',
'https://www.example.com/with-numbers-123',
'https://www.example.com/with-parameters?var=true',
'https://www.example.com/with-multiple-parameters?var=true&foo=bar',
'https://www.example.com/with-spaces?var=true&foo=bar+3',
// TODO: 'https://www.example.com/with,comma',
'http://thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com/',
'https://example.longtopleveldomain',
'https://example-with-dashes.com',
]
validUrls.forEach(url => {
it(`url should be detected: ${url}`, () => {
cy.get('.ProseMirror').paste({ pastePayload: url, pasteType: 'text/plain' })
.find('a')
.should('contain', url)
.should('have.attr', 'href', url)
})
})
})

View File

@@ -0,0 +1,63 @@
<template>
<div v-if="editor">
<button @click="addLink" :class="{ 'is-active': editor.isActive('link') }">
link
</button>
<button @click="editor.chain().focus().removeMark('link').run()" v-if="editor.isActive('link')">
remove
</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 Link from '@tiptap/extension-link'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document(),
Paragraph(),
Text(),
Link(),
],
content: `
<p>
Wow, this editor has support for links to the whole <a href="https://en.wikipedia.org/wiki/World_Wide_Web">world wide web</a>. We tested a lot of URLs and I think you can add *every URL* you want. Isnt that cool? Lets try <a href="https://statamic.com/">another one!</a> Yep, seems to work.
</p>
<p>
By default every link will get a \`rel="noopener noreferrer nofollow"\` attribute. Its configurable though.
</p>
`,
})
},
methods: {
addLink() {
const url = window.prompt('URL')
this.editor.chain().focus().link({ href: url }).run()
},
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>

View File

@@ -0,0 +1,86 @@
context('/api/marks/strike', () => {
before(() => {
cy.visit('/api/marks/strike')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example Text</p>')
editor.selectAll()
})
})
it('should parse s tags correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><s>Example Text</s></p>')
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
})
})
it('should transform del tags to s tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><del>Example Text</del></p>')
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
})
})
it('should transform strike tags to s tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><strike>Example Text</strike></p>')
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
})
})
it('should transform any tag with text decoration line through to s tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><span style="text-decoration: line-through">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
})
})
it('the button should strike the selected text', () => {
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.find('s')
.should('contain', 'Example Text')
})
it('the button should toggle the selected text striked', () => {
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.type('{selectall}')
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.find('s')
.should('not.exist')
})
it('the keyboard shortcut should strike the selected text', () => {
cy.get('.ProseMirror')
.trigger('keydown', { modKey: true, key: 'd' })
.find('s')
.should('contain', 'Example Text')
})
it('the keyboard shortcut should toggle the selected text striked', () => {
cy.get('.ProseMirror')
.trigger('keydown', { modKey: true, key: 'd' })
.trigger('keydown', { modKey: true, key: 'd' })
.find('s')
.should('not.exist')
})
it('should make a striked text from the markdown shortcut', () => {
cy.get('.ProseMirror')
.type('~~Strike~~')
.find('s')
.should('contain', 'Strike')
})
})

View File

@@ -0,0 +1,52 @@
<template>
<div v-if="editor">
<button @click="editor.chain().focus().strike().run()" :class="{ 'is-active': editor.isActive('strike') }">
strike
</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 Strike from '@tiptap/extension-strike'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document(),
Paragraph(),
Text(),
Strike(),
],
content: `
<p>This isnt striked through.</s></p>
<p><s>But thats striked through.</s></p>
<p><del>And this.</del></p>
<p><strike>This too.</strike></p>
<p style="text-decoration: line-through">This as well.</p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>

View File

@@ -0,0 +1,65 @@
context('/api/marks/underline', () => {
before(() => {
cy.visit('/api/marks/underline')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p>Example Text</p>')
editor.selectAll()
})
})
it('should parse u tags correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><u>Example Text</u></p>')
expect(editor.getHTML()).to.eq('<p><u>Example Text</u></p>')
})
})
it('should transform any tag with text decoration underline to u tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('<p><span style="text-decoration: underline">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><u>Example Text</u></p>')
})
})
it('the button should underline the selected text', () => {
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.find('u')
.should('contain', 'Example Text')
})
it('the button should toggle the selected text underline', () => {
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.type('{selectall}')
cy.get('.demo__preview button:first')
.click()
cy.get('.ProseMirror')
.find('u')
.should('not.exist')
})
it('the keyboard shortcut should underline the selected text', () => {
cy.get('.ProseMirror')
.trigger('keydown', { modKey: true, key: 'u' })
.find('u')
.should('contain', 'Example Text')
})
it('the keyboard shortcut should toggle the selected text underline', () => {
cy.get('.ProseMirror')
.trigger('keydown', { modKey: true, key: 'u' })
.trigger('keydown', { modKey: true, key: 'u' })
.find('u')
.should('not.exist')
})
})

View File

@@ -0,0 +1,50 @@
<template>
<div v-if="editor">
<button @click="editor.chain().focus().underline().run()" :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>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>