Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress tests for examples #2777

Merged
merged 19 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
76283fe
test: added first tests for examples
bdbch May 10, 2022
2a23f4f
test: increase default command timeout to 50s
bdbch May 10, 2022
27ce938
test: add new tests for multiple examples
bdbch May 11, 2022
a6f51b7
style(examples): fix linting issues in custom document test
bdbch May 11, 2022
020c4a9
test(examples): add tests for more example pages
bdbch May 11, 2022
bfb950d
test(examples): adds more tests for tables, tasks and commands
bdbch May 12, 2022
f9ab39e
refactor(tests): added todo note for tasks test
bdbch May 12, 2022
2c9437d
Merge branch 'main' of github.com:ueberdosis/tiptap into maintainment…
bdbch May 12, 2022
debd0d0
Merge branch 'maintainment/example-tests' of github.com:ueberdosis/ti…
bdbch May 12, 2022
bda3c88
test(experiments): adds test for collaboration annotation examples
bdbch May 12, 2022
cb6950e
style: fix linting issues in collaboration annotation test
bdbch May 12, 2022
92fb9b1
test(examples): add missing test for tasks example
bdbch May 12, 2022
ce85da0
test(examples): add test for tasks vue example
bdbch May 12, 2022
bb008e4
Merge branch 'main' of github.com:ueberdosis/tiptap into maintainment…
bdbch May 13, 2022
4e07578
Merge branch 'main' of github.com:ueberdosis/tiptap into maintainment…
bdbch May 13, 2022
af8e46d
test: fix broken tests & change inactive time for cypress
bdbch May 13, 2022
7578cd9
test(examples): try to fix broken test for images react demo
bdbch May 13, 2022
6b005c5
test: fix images test in react and collaboration annotation test
bdbch May 13, 2022
b354f79
style: remove stray console.log
bdbch May 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions demos/src/Examples/Book/React/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
context('/src/Examples/Book/React/', () => {
before(() => {
cy.visit('/src/Examples/Book/React/')
})

it('should have a working tiptap instance', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
// eslint-disable-next-line
expect(editor).to.not.be.null
})
})
})
7 changes: 6 additions & 1 deletion demos/src/Examples/Book/Vue/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ context('/src/Examples/Book/Vue/', () => {
cy.visit('/src/Examples/Book/Vue/')
})

// TODO: Write tests
it('should have a working tiptap instance', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
// eslint-disable-next-line
expect(editor).to.not.be.null
})
})
})
Empty file.
172 changes: 172 additions & 0 deletions demos/src/Examples/CSSModules/React/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import './styles.scss'

import React from 'react'

import { EditorContent, useEditor } from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'

import styles from './index.module.css'

const MenuBar = ({ editor }) => {
if (!editor) {
return null
}

return (
<div className={`toolbar ${styles.toolbar}`}>
<button
onClick={() => editor.chain().focus().toggleBold().run()}
className={editor.isActive('bold') ? 'is-active' : ''}
>
bold
</button>
<button
onClick={() => editor.chain().focus().toggleItalic().run()}
className={editor.isActive('italic') ? 'is-active' : ''}
>
italic
</button>
<button
onClick={() => editor.chain().focus().toggleStrike().run()}
className={editor.isActive('strike') ? 'is-active' : ''}
>
strike
</button>
<button
onClick={() => editor.chain().focus().toggleCode().run()}
className={editor.isActive('code') ? 'is-active' : ''}
>
code
</button>
<button onClick={() => editor.chain().focus().unsetAllMarks().run()}>
clear marks
</button>
<button onClick={() => editor.chain().focus().clearNodes().run()}>
clear nodes
</button>
<button
onClick={() => editor.chain().focus().setParagraph().run()}
className={editor.isActive('paragraph') ? 'is-active' : ''}
>
paragraph
</button>
<button
onClick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()}
className={editor.isActive('heading', { level: 1 }) ? 'is-active' : ''}
>
h1
</button>
<button
onClick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
className={editor.isActive('heading', { level: 2 }) ? 'is-active' : ''}
>
h2
</button>
<button
onClick={() => editor.chain().focus().toggleHeading({ level: 3 }).run()}
className={editor.isActive('heading', { level: 3 }) ? 'is-active' : ''}
>
h3
</button>
<button
onClick={() => editor.chain().focus().toggleHeading({ level: 4 }).run()}
className={editor.isActive('heading', { level: 4 }) ? 'is-active' : ''}
>
h4
</button>
<button
onClick={() => editor.chain().focus().toggleHeading({ level: 5 }).run()}
className={editor.isActive('heading', { level: 5 }) ? 'is-active' : ''}
>
h5
</button>
<button
onClick={() => editor.chain().focus().toggleHeading({ level: 6 }).run()}
className={editor.isActive('heading', { level: 6 }) ? 'is-active' : ''}
>
h6
</button>
<button
onClick={() => editor.chain().focus().toggleBulletList().run()}
className={editor.isActive('bulletList') ? 'is-active' : ''}
>
bullet list
</button>
<button
onClick={() => editor.chain().focus().toggleOrderedList().run()}
className={editor.isActive('orderedList') ? 'is-active' : ''}
>
ordered list
</button>
<button
onClick={() => editor.chain().focus().toggleCodeBlock().run()}
className={editor.isActive('codeBlock') ? 'is-active' : ''}
>
code block
</button>
<button
onClick={() => editor.chain().focus().toggleBlockquote().run()}
className={editor.isActive('blockquote') ? 'is-active' : ''}
>
blockquote
</button>
<button onClick={() => editor.chain().focus().setHorizontalRule().run()}>
horizontal rule
</button>
<button onClick={() => editor.chain().focus().setHardBreak().run()}>
hard break
</button>
<button onClick={() => editor.chain().focus().undo().run()}>
undo
</button>
<button onClick={() => editor.chain().focus().redo().run()}>
redo
</button>
</div>
)
}

export default () => {
const editor = useEditor({
extensions: [
StarterKit,
],
content: `
<h2>
Hi there,
</h2>
<p>
this is a <em>basic</em> example of <strong>tiptap</strong>. Sure, there are all kind of basic text styles you’d probably expect from a text editor. But wait until you see the lists:
</p>
<ul>
<li>
That’s a bullet list with one …
</li>
<li>
… or two list items.
</li>
</ul>
<p>
Isn’t that great? And all of that is editable. But wait, there’s more. Let’s try a code block:
</p>
<pre><code class="language-css">body {
display: none;
}</code></pre>
<p>
I know, I know, this is impressive. It’s only the tip of the iceberg though. Give it a try and click a little bit around. Don’t forget to check the other examples too.
</p>
<blockquote>
Wow, that’s amazing. Good work, boy! 👏
<br />
— Mom
</blockquote>
`,
})

return (
<div>
<MenuBar editor={editor} />
<EditorContent editor={editor} />
</div>
)
}
4 changes: 4 additions & 0 deletions demos/src/Examples/CSSModules/React/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.toolbar {
background-color: red;
padding: 16px;
}
11 changes: 11 additions & 0 deletions demos/src/Examples/CSSModules/React/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
context('/src/Examples/CSSModules/React/', () => {
before(() => {
cy.visit('/src/Examples/CSSModules/React/')
})

it('should apply a randomly generated class that adds padding and background color to the toolbar', () => {
cy.get('.toolbar').should('exist')
cy.get('.toolbar').should('have.css', 'background-color', 'rgb(255, 0, 0)')
cy.get('.toolbar').should('have.css', 'padding', '16px')
})
})
56 changes: 56 additions & 0 deletions demos/src/Examples/CSSModules/React/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}

ul,
ol {
padding: 0 1rem;
}

h1,
h2,
h3,
h4,
h5,
h6 {
line-height: 1.1;
}

code {
background-color: rgba(#616161, 0.1);
color: #616161;
}

pre {
background: #0D0D0D;
color: #FFF;
font-family: 'JetBrainsMono', monospace;
padding: 0.75rem 1rem;
border-radius: 0.5rem;

code {
color: inherit;
padding: 0;
background: none;
font-size: 0.8rem;
}
}

img {
max-width: 100%;
height: auto;
}

blockquote {
padding-left: 1rem;
border-left: 2px solid rgba(#0D0D0D, 0.1);
}

hr {
border: none;
border-top: 2px solid rgba(#0D0D0D, 0.1);
margin: 2rem 0;
}
}
3 changes: 0 additions & 3 deletions demos/src/Examples/CSSModules/Vue/index.css

This file was deleted.

4 changes: 4 additions & 0 deletions demos/src/Examples/CSSModules/Vue/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.toolbar {
background-color: red;
padding: 16px;
}
14 changes: 4 additions & 10 deletions demos/src/Examples/CSSModules/Vue/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ context('/src/Examples/CSSModules/Vue/', () => {
cy.visit('/src/Examples/CSSModules/Vue/')
})

beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<h1>Example Text</h1>')
cy.get('.ProseMirror').type('{selectall}')
})
})

it('should apply a red headline style to h1', () => {
cy.get('.ProseMirror h1').should('exist')
cy.get('.ProseMirror h1').should('have.css', 'color', 'rgb(255, 0, 0)')
it('should apply a randomly generated class that adds padding and background color to the toolbar', () => {
cy.get('.toolbar').should('exist')
cy.get('.toolbar').should('have.css', 'background-color', 'rgb(255, 0, 0)')
cy.get('.toolbar').should('have.css', 'padding', '16px')
})
})
7 changes: 4 additions & 3 deletions demos/src/Examples/CSSModules/Vue/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="editor">
<div v-if="editor" class="toolbar" :class="styles.toolbar">
<button @click="editor.chain().focus().toggleBold().run()" :class="{ 'is-active': editor.isActive('bold') }">
bold
</button>
Expand Down Expand Up @@ -70,7 +70,7 @@
<script>
import { Editor, EditorContent } from '@tiptap/vue-3'
import StarterKit from '@tiptap/starter-kit'
import './index.css'
import styles from './index.module.css'

export default {
components: {
Expand All @@ -80,6 +80,7 @@ export default {
data() {
return {
editor: null,
styles,
}
},

Expand All @@ -89,7 +90,7 @@ export default {
StarterKit,
],
content: `
<h1>
<h1 class="test">
This is a red headline
</h1>
<p>
Expand Down
28 changes: 28 additions & 0 deletions demos/src/Examples/CodeBlockLanguage/React/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
context('/src/Examples/CodeBlockLanguage/React/', () => {
before(() => {
cy.visit('/src/Examples/CodeBlockLanguage/React/')
})

it('should have hljs classes for syntax highlighting', () => {
cy.get('[class^=hljs]').then(elements => {
expect(elements.length).to.be.greaterThan(0)
})
})

it('should have different count of hljs classes after switching language', () => {
cy.get('[class^=hljs]').then(elements => {
const initialCount = elements.length

expect(initialCount).to.be.greaterThan(0)

cy.get('.ProseMirror select').select('java')
cy.wait(500)

cy.get('[class^=hljs]').then(newElements => {
const newCount = newElements.length

expect(newCount).to.not.equal(initialCount)
})
})
})
})
28 changes: 28 additions & 0 deletions demos/src/Examples/CodeBlockLanguage/Vue/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
context('/src/Examples/CodeBlockLanguage/Vue/', () => {
before(() => {
cy.visit('/src/Examples/CodeBlockLanguage/Vue/')
})

it('should have hljs classes for syntax highlighting', () => {
cy.get('[class^=hljs]').then(elements => {
expect(elements.length).to.be.greaterThan(0)
})
})

it('should have different count of hljs classes after switching language', () => {
cy.get('[class^=hljs]').then(elements => {
const initialCount = elements.length

expect(initialCount).to.be.greaterThan(0)

cy.get('.ProseMirror select').select('java')
cy.wait(500)

cy.get('[class^=hljs]').then(newElements => {
const newCount = newElements.length

expect(newCount).to.not.equal(initialCount)
})
})
})
})
Loading