refactoring

This commit is contained in:
Philipp Kühn
2020-09-15 00:07:00 +02:00
parent 61ca7d4377
commit 71cc626b0a
12 changed files with 307 additions and 123 deletions

View File

@@ -11,34 +11,60 @@ context('/api/extensions/blockquote', () => {
}) })
it('the button should make the selected line a blockquote', () => { it('the button should make the selected line a blockquote', () => {
cy.get('.ProseMirror blockquote').should('not.exist') cy.get('.ProseMirror blockquote')
cy.get('.demo__preview button:first').click({ force: true }) .should('not.exist')
cy.get('.ProseMirror').find('blockquote').should('contain', 'Example Text')
cy.get('.demo__preview button:first')
.click({ force: true })
cy.get('.ProseMirror')
.find('blockquote')
.should('contain', 'Example Text')
}) })
it('the button should toggle the blockquote', () => { it('the button should toggle the blockquote', () => {
cy.get('.ProseMirror blockquote').should('not.exist') cy.get('.ProseMirror blockquote')
cy.get('.demo__preview button:first').click({ force: true }) .should('not.exist')
cy.get('.ProseMirror').find('blockquote').should('contain', 'Example Text')
cy.get('.ProseMirror').type('{selectall}', { force: true }) cy.get('.demo__preview button:first')
cy.get('.demo__preview button:first').click({ force: true }) .click({ force: true })
cy.get('.ProseMirror blockquote').should('not.exist')
cy.get('.ProseMirror')
.find('blockquote')
.should('contain', 'Example Text')
cy.get('.ProseMirror')
.type('{selectall}', { force: true })
cy.get('.demo__preview button:first')
.click({ force: true })
cy.get('.ProseMirror blockquote')
.should('not.exist')
}) })
it('the keyboard shortcut should make the selected line a blockquote', () => { it('the keyboard shortcut should make the selected line a blockquote', () => {
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, modKey: true, key: '9' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').find('blockquote').should('contain', 'Example Text') .trigger('keydown', { shiftKey: true, modKey: true, key: '9' })
.find('blockquote')
.should('contain', 'Example Text')
}) })
it('the keyboard shortcut should toggle the blockquote', () => { it('the keyboard shortcut should toggle the blockquote', () => {
cy.get('.ProseMirror blockquote').should('not.exist') cy.get('.ProseMirror blockquote')
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, modKey: true, key: '9' }) .should('not.exist')
cy.get('.ProseMirror').find('blockquote').should('contain', 'Example Text')
cy.get('.ProseMirror').type('{selectall}', { force: true }) cy.get('.ProseMirror')
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, modKey: true, key: '9' }) .trigger('keydown', { shiftKey: true, modKey: true, key: '9' })
cy.get('.ProseMirror blockquote').should('not.exist') .find('blockquote')
.should('contain', 'Example Text')
cy.get('.ProseMirror')
.type('{selectall}', { force: true })
.trigger('keydown', { shiftKey: true, modKey: true, key: '9' })
cy.get('.ProseMirror blockquote')
.should('not.exist')
}) })
it('should make a blockquote from markdown shortcuts', () => { it('should make a blockquote from markdown shortcuts', () => {

View File

@@ -12,7 +12,9 @@ context('/api/extensions/bold', () => {
it('the button should make the selected text bold', () => { it('the button should make the selected text bold', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first').click({ force: true })
cy.get('.ProseMirror').find('strong').should('contain', 'Example Text') cy.get('.ProseMirror')
.find('strong')
.should('contain', 'Example Text')
}) })
it('the button should toggle the selected text bold', () => { it('the button should toggle the selected text bold', () => {

View File

@@ -11,14 +11,25 @@ context('/api/extensions/code', () => {
}) })
it('should mark the selected text as inline code', () => { it('should mark the selected text as inline code', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').find('code').should('contain', 'Example Text') .click({ force: true })
cy.get('.ProseMirror')
.find('code')
.should('contain', 'Example Text')
}) })
it('should toggle the selected text as inline code', () => { it('should toggle the selected text as inline code', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').type('{selectall}', { force: true }) .click({ force: true })
cy.get('.demo__preview button:first').click({ force: true })
cy.get('.ProseMirror code').should('not.exist') cy.get('.ProseMirror')
.type('{selectall}', { force: true })
cy.get('.demo__preview button:first')
.click({ force: true })
cy.get('.ProseMirror code')
.should('not.exist')
}) })
}) })

View File

@@ -11,31 +11,51 @@ context('/api/extensions/code-block', () => {
}) })
it('the button should make the selected line a code block', () => { it('the button should make the selected line a code block', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').find('pre').should('contain', 'Example Text') .click({ force: true })
cy.get('.ProseMirror')
.find('pre')
.should('contain', 'Example Text')
}) })
it('the button should toggle the code block', () => { it('the button should toggle the code block', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').find('pre').should('contain', 'Example Text') .click({ force: true })
cy.get('.ProseMirror').type('{selectall}', { force: true }) cy.get('.ProseMirror')
cy.get('.demo__preview button:first').click({ force: true }) .find('pre')
cy.get('.ProseMirror pre').should('not.exist') .should('contain', 'Example Text')
cy.get('.ProseMirror')
.type('{selectall}', { force: true })
cy.get('.demo__preview button:first')
.click({ force: true })
cy.get('.ProseMirror pre')
.should('not.exist')
}) })
it('the keyboard shortcut should make the selected line a code block', () => { it('the keyboard shortcut should make the selected line a code block', () => {
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').find('pre').should('contain', 'Example Text') .trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' })
.find('pre')
.should('contain', 'Example Text')
}) })
it('the keyboard shortcut should toggle the code block', () => { it('the keyboard shortcut should toggle the code block', () => {
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').find('pre').should('contain', 'Example Text') .trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' })
.find('pre')
.should('contain', 'Example Text')
cy.get('.ProseMirror').type('{selectall}', { force: true }) cy.get('.ProseMirror')
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' }) .type('{selectall}', { force: true })
cy.get('.ProseMirror pre').should('not.exist') .trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' })
cy.get('.ProseMirror pre')
.should('not.exist')
}) })
it('should make a code block from markdown shortcuts', () => { it('should make a code block from markdown shortcuts', () => {

View File

@@ -10,20 +10,35 @@ context('/api/extensions/hard-break', () => {
}) })
it('the button should add a line break', () => { it('the button should add a line break', () => {
cy.get('.ProseMirror br').should('not.exist') cy.get('.ProseMirror br')
cy.get('.demo__preview button:first').click({ force: true }) .should('not.exist')
cy.get('.ProseMirror br').should('exist')
cy.get('.demo__preview button:first')
.click({ force: true })
cy.get('.ProseMirror br')
.should('exist')
}) })
it('the default keyboard shortcut should add a line break', () => { it('the default keyboard shortcut should add a line break', () => {
cy.get('.ProseMirror br').should('not.exist') cy.get('.ProseMirror br')
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, key: 'Enter' }) .should('not.exist')
cy.get('.ProseMirror br').should('exist')
cy.get('.ProseMirror')
.trigger('keydown', { shiftKey: true, key: 'Enter' })
cy.get('.ProseMirror br')
.should('exist')
}) })
it('the alternative keyboard shortcut should add a line break', () => { it('the alternative keyboard shortcut should add a line break', () => {
cy.get('.ProseMirror br').should('not.exist') cy.get('.ProseMirror br')
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'Enter' }) .should('not.exist')
cy.get('.ProseMirror br').should('exist')
cy.get('.ProseMirror')
.trigger('keydown', { modKey: true, key: 'Enter' })
cy.get('.ProseMirror br')
.should('exist')
}) })
}) })

View File

@@ -11,20 +11,38 @@ context('/api/extensions/heading', () => {
}) })
it('the button should make the selected line a h1', () => { it('the button should make the selected line a h1', () => {
cy.get('.ProseMirror h1').should('not.exist') cy.get('.ProseMirror h1')
cy.get('.demo__preview button:nth-child(1)').click({ force: true }) .should('not.exist')
cy.get('.ProseMirror').find('h1').should('contain', 'Example Text')
cy.get('.demo__preview button:nth-child(1)')
.click({ force: true })
cy.get('.ProseMirror')
.find('h1')
.should('contain', 'Example Text')
}) })
it('the button should make the selected line a h2', () => { it('the button should make the selected line a h2', () => {
cy.get('.ProseMirror h2').should('not.exist') cy.get('.ProseMirror h2')
cy.get('.demo__preview button:nth-child(2)').click({ force: true }) .should('not.exist')
cy.get('.ProseMirror').find('h2').should('contain', 'Example Text')
cy.get('.demo__preview button:nth-child(2)')
.click({ force: true })
cy.get('.ProseMirror')
.find('h2')
.should('contain', 'Example Text')
}) })
it('the button should make the selected line a h3', () => { it('the button should make the selected line a h3', () => {
cy.get('.ProseMirror h3').should('not.exist') cy.get('.ProseMirror h3')
cy.get('.demo__preview button:nth-child(3)').click({ force: true }) .should('not.exist')
cy.get('.ProseMirror').find('h3').should('contain', 'Example Text')
cy.get('.demo__preview button:nth-child(3)')
.click({ force: true })
cy.get('.ProseMirror')
.find('h3')
.should('contain', 'Example Text')
}) })
}) })

View File

@@ -10,29 +10,44 @@ context('/api/extensions/history', () => {
}) })
it('should make the last change undone', () => { it('should make the last change undone', () => {
cy.get('.ProseMirror').should('contain', 'Mistake') cy.get('.ProseMirror')
cy.get('.demo__preview button:first').click({ force: true }) .should('contain', 'Mistake')
cy.get('.ProseMirror').should('not.contain', 'Mistake')
cy.get('.demo__preview button:first')
.click({ force: true })
cy.get('.ProseMirror')
.should('not.contain', 'Mistake')
}) })
it('the keyboard shortcut should make the last change undone', () => { it('the keyboard shortcut should make the last change undone', () => {
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'z' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').should('not.contain', 'Mistake') .trigger('keydown', { modKey: true, key: 'z' })
.should('not.contain', 'Mistake')
}) })
it('should apply the last undone change again', () => { it('should apply the last undone change again', () => {
cy.get('.ProseMirror').should('contain', 'Mistake') cy.get('.ProseMirror')
cy.get('.demo__preview button:first').click({ force: true }) .should('contain', 'Mistake')
cy.get('.ProseMirror').should('not.contain', 'Mistake')
cy.get('.demo__preview button:nth-child(2)').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').should('contain', 'Mistake') .click({ force: true })
cy.get('.ProseMirror')
.should('not.contain', 'Mistake')
cy.get('.demo__preview button:nth-child(2)')
.click({ force: true })
cy.get('.ProseMirror')
.should('contain', 'Mistake')
}) })
it.skip('the keyboard shortcut should apply the last undone change again', () => { it.skip('the keyboard shortcut should apply the last undone change again', () => {
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'z' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').should('not.contain', 'Mistake') .trigger('keydown', { modKey: true, key: 'z' })
.should('not.contain', 'Mistake')
cy.get('.ProseMirror').trigger('keydown', { modKey: true, shiftKey: true, key: 'z' }) .trigger('keydown', { modKey: true, shiftKey: true, key: 'z' })
cy.get('.ProseMirror').should('contain', 'Mistake') .should('contain', 'Mistake')
}) })
}) })

View File

@@ -10,18 +10,28 @@ context('/api/extensions/horizontal-rule', () => {
}) })
it('the button should add a horizontal rule', () => { it('the button should add a horizontal rule', () => {
cy.get('.ProseMirror hr').should('not.exist') cy.get('.ProseMirror hr')
cy.get('.demo__preview button:first').click({ force: true }) .should('not.exist')
cy.get('.ProseMirror hr').should('exist')
cy.get('.demo__preview button:first')
.click({ force: true })
cy.get('.ProseMirror hr')
.should('exist')
}) })
it('the default markdown shortcut should add a horizontal rule', () => { it('the default markdown shortcut should add a horizontal rule', () => {
cy.get('.ProseMirror').then(([{ editor }]) => { cy.get('.ProseMirror').then(([{ editor }]) => {
editor.clearContent() editor.clearContent()
cy.get('.ProseMirror hr').should('not.exist') cy.get('.ProseMirror hr')
cy.get('.ProseMirror').type('---', { force: true }) .should('not.exist')
cy.get('.ProseMirror hr').should('exist')
cy.get('.ProseMirror')
.type('---', { force: true })
cy.get('.ProseMirror hr')
.should('exist')
}) })
}) })
@@ -29,9 +39,14 @@ context('/api/extensions/horizontal-rule', () => {
cy.get('.ProseMirror').then(([{ editor }]) => { cy.get('.ProseMirror').then(([{ editor }]) => {
editor.clearContent() editor.clearContent()
cy.get('.ProseMirror hr').should('not.exist') cy.get('.ProseMirror hr')
cy.get('.ProseMirror').type('___ ', { force: true }) .should('not.exist')
cy.get('.ProseMirror hr').should('exist')
cy.get('.ProseMirror')
.type('___ ', { force: true })
cy.get('.ProseMirror hr')
.should('exist')
}) })
}) })
}) })

View File

@@ -11,25 +11,40 @@ context('/api/extensions/italic', () => {
}) })
it('the button should make the selected text italic', () => { it('the button should make the selected text italic', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').find('em').should('contain', 'Example Text') .click({ force: true })
cy.get('.ProseMirror')
.find('em')
.should('contain', 'Example Text')
}) })
it('the button should toggle the selected text italic', () => { it('the button should toggle the selected text italic', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').type('{selectall}', { force: true }) .click({ force: true })
cy.get('.demo__preview button:first').click({ force: true })
cy.get('.ProseMirror em').should('not.exist') cy.get('.ProseMirror')
.type('{selectall}', { force: true })
cy.get('.demo__preview button:first')
.click({ force: true })
cy.get('.ProseMirror em')
.should('not.exist')
}) })
it('the keyboard shortcut should make the selected text italic', () => { it('the keyboard shortcut should make the selected text italic', () => {
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'i' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').find('em').should('contain', 'Example Text') .trigger('keydown', { modKey: true, key: 'i' })
.find('em')
.should('contain', 'Example Text')
}) })
it('the keyboard shortcut should toggle the selected text italic', () => { it('the keyboard shortcut should toggle the selected text italic', () => {
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'i' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'i' }) .trigger('keydown', { modKey: true, key: 'i' })
cy.get('.ProseMirror em').should('not.exist') .trigger('keydown', { modKey: true, key: 'i' })
.find('em')
.should('not.exist')
}) })
}) })

View File

@@ -10,21 +10,36 @@ context('/api/extensions/paragraph', () => {
}) })
it('text should be wrapped in a paragraph by default', () => { it('text should be wrapped in a paragraph by default', () => {
cy.get('.ProseMirror').type('Example Text', { force: true }) cy.get('.ProseMirror')
cy.get('.ProseMirror').find('p').should('contain', 'Example Text') .type('Example Text', { force: true })
.find('p')
.should('contain', 'Example Text')
}) })
it('enter should make a new paragraph', () => { it('enter should make a new paragraph', () => {
cy.get('.ProseMirror').type('First Paragraph{enter}Second Paragraph', { force: true }) cy.get('.ProseMirror')
cy.get('.ProseMirror').find('p').should('have.length', 2) .type('First Paragraph{enter}Second Paragraph', { force: true })
cy.get('.ProseMirror').find('p:first').should('contain', 'First Paragraph') .find('p')
cy.get('.ProseMirror').find('p:nth-child(2)').should('contain', 'Second Paragraph') .should('have.length', 2)
cy.get('.ProseMirror')
.find('p:first')
.should('contain', 'First Paragraph')
cy.get('.ProseMirror')
.find('p:nth-child(2)')
.should('contain', 'Second Paragraph')
}) })
it('backspace should remove the second paragraph', () => { it('backspace should remove the second paragraph', () => {
cy.get('.ProseMirror').type('{enter}', { force: true }) cy.get('.ProseMirror')
cy.get('.ProseMirror').find('p').should('have.length', 2) .type('{enter}', { force: true })
cy.get('.ProseMirror').type('{backspace}', { force: true }) .find('p')
cy.get('.ProseMirror').find('p').should('have.length', 1) .should('have.length', 2)
cy.get('.ProseMirror')
.type('{backspace}', { force: true })
.find('p')
.should('have.length', 1)
}) })
}) })

View File

@@ -11,26 +11,42 @@ context('/api/extensions/strike', () => {
}) })
it('the button should strike the selected text', () => { it('the button should strike the selected text', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').find('s').should('contain', 'Example Text') .click({ force: true })
cy.get('.ProseMirror')
.find('s')
.should('contain', 'Example Text')
}) })
it('the button should toggle the selected text striked', () => { it('the button should toggle the selected text striked', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').type('{selectall}', { force: true }) .click({ force: true })
cy.get('.demo__preview button:first').click({ force: true })
cy.get('.ProseMirror s').should('not.exist') cy.get('.ProseMirror')
.type('{selectall}', { force: true })
cy.get('.demo__preview button:first')
.click({ force: true })
cy.get('.ProseMirror')
.find('s')
.should('not.exist')
}) })
it('the keyboard shortcut should strike the selected text', () => { it('the keyboard shortcut should strike the selected text', () => {
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'd' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').find('s').should('contain', 'Example Text') .trigger('keydown', { modKey: true, key: 'd' })
.find('s')
.should('contain', 'Example Text')
}) })
it('the keyboard shortcut should toggle the selected text striked', () => { it('the keyboard shortcut should toggle the selected text striked', () => {
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'd' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'd' }) .trigger('keydown', { modKey: true, key: 'd' })
cy.get('.ProseMirror s').should('not.exist') .trigger('keydown', { modKey: true, key: 'd' })
.find('s')
.should('not.exist')
}) })
it('should make a striked text from the markdown shortcut', () => { it('should make a striked text from the markdown shortcut', () => {

View File

@@ -11,25 +11,41 @@ context('/api/extensions/underline', () => {
}) })
it('the button should underline the selected text', () => { it('the button should underline the selected text', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').find('u').should('contain', 'Example Text') .click({ force: true })
cy.get('.ProseMirror')
.find('u')
.should('contain', 'Example Text')
}) })
it('the button should toggle the selected text underline', () => { it('the button should toggle the selected text underline', () => {
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first')
cy.get('.ProseMirror').type('{selectall}', { force: true }) .click({ force: true })
cy.get('.demo__preview button:first').click({ force: true })
cy.get('.ProseMirror u').should('not.exist') cy.get('.ProseMirror')
.type('{selectall}', { force: true })
cy.get('.demo__preview button:first')
.click({ force: true })
cy.get('.ProseMirror')
.find('u')
.should('not.exist')
}) })
it('the keyboard shortcut should underline the selected text', () => { it('the keyboard shortcut should underline the selected text', () => {
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'u' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').find('u').should('contain', 'Example Text') .trigger('keydown', { modKey: true, key: 'u' })
.find('u')
.should('contain', 'Example Text')
}) })
it('the keyboard shortcut should toggle the selected text underline', () => { it('the keyboard shortcut should toggle the selected text underline', () => {
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'u' }) cy.get('.ProseMirror')
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'u' }) .trigger('keydown', { modKey: true, key: 'u' })
cy.get('.ProseMirror u').should('not.exist') .trigger('keydown', { modKey: true, key: 'u' })
.find('u')
.should('not.exist')
}) })
}) })