From c065edd405489d830853ed3a04deee6e9a17382d Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Fri, 4 Sep 2020 14:42:30 +0200 Subject: [PATCH] add keyboard shortcut tests to the history extension --- docs/src/demos/Extensions/Bold/index.spec.js | 2 +- .../demos/Extensions/History/index.spec.js | 55 ++++++------------- .../src/demos/Extensions/Italic/index.spec.js | 6 +- 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/docs/src/demos/Extensions/Bold/index.spec.js b/docs/src/demos/Extensions/Bold/index.spec.js index e72ca3f4..85a66e41 100644 --- a/docs/src/demos/Extensions/Bold/index.spec.js +++ b/docs/src/demos/Extensions/Bold/index.spec.js @@ -27,7 +27,7 @@ context('/api/extensions/bold', () => { cy.get('.ProseMirror').contains('strong', 'Example Text') }) - it('the button should toggle the selected text bold', () => { + it('the keyboard shortcut should toggle the selected text bold', () => { const shortcut = Cypress.platform === 'darwin' ? '{meta}b' : '{ctrl}b' cy.get('.ProseMirror').type(shortcut, {force: true}).type(shortcut, {force: true}) diff --git a/docs/src/demos/Extensions/History/index.spec.js b/docs/src/demos/Extensions/History/index.spec.js index 09120c2b..13259d94 100644 --- a/docs/src/demos/Extensions/History/index.spec.js +++ b/docs/src/demos/Extensions/History/index.spec.js @@ -11,19 +11,24 @@ context('/api/extensions/history', () => { describe('undo', () => { it('should make the last change undone', () => { cy.get('.ProseMirror').window().then(window => { - const { editor } = window cy.get('.ProseMirror').should('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', () => { + const shortcut = Cypress.platform === 'darwin' ? '{meta}z' : '{ctrl}z' + + cy.get('.ProseMirror').type(shortcut, {force: true}) + cy.get('.ProseMirror').should('not.contain', 'Mistake') + }) }) describe('redo', () => { it('should apply the last undone change again', () => { cy.get('.ProseMirror').window().then(window => { - const { editor } = window cy.get('.ProseMirror').should('contain', 'Mistake') cy.get('.demo__preview button:first').click({ force: true }) @@ -32,40 +37,16 @@ context('/api/extensions/history', () => { cy.get('.ProseMirror').should('contain', 'Mistake') }) }) + + it('the keyboard shortcut should apply the last undone change again', () => { + const undoShortcut = Cypress.platform === 'darwin' ? '{meta}z' : '{ctrl}z' + const redoShortcut = Cypress.platform === 'darwin' ? '{meta}{shift}z' : '{ctrl}{shift}z' + + cy.get('.ProseMirror').type(undoShortcut, {force: true}) + cy.get('.ProseMirror').should('not.contain', 'Mistake') + + cy.get('.ProseMirror').type(redoShortcut, {force: true}) + cy.get('.ProseMirror').should('contain', 'Mistake') + }) }) }) - - -// context('/api/extensions/history', () => { -// beforeEach(() => { -// cy.visit('/api/extensions/history') - -// cy.get('.ProseMirror').window().then(window => { -// const { editor } = window -// editor.setContent('

as

') -// }) -// }) - -// describe('history', () => { -// it('should make the selected text history', () => { -// cy.get('.ProseMirror').window().then(window => { -// const { editor } = window -// const html = editor.html() - -// cy.get('.ProseMirror').type('Mistake', { force: true }) -// // cy.get('.ProseMirror').should('contain', 'Mistake') -// // cy.get('.demo__preview button:first').click({ force: true }) -// // cy.get('.ProseMirror').should('contain', 'Mistake') -// }) -// }) - - -// editor.insertText('Mistake') -// cy.get('.ProseMirror h2:first').should('contain', 'Mistake') - -// // it('should toggle the selected text history', () => { -// // cy.get('.demo__preview button:first').dblclick({ force: true }) -// // cy.get('.ProseMirror em').should('not.exist') -// // }) -// }) -// }) \ No newline at end of file diff --git a/docs/src/demos/Extensions/Italic/index.spec.js b/docs/src/demos/Extensions/Italic/index.spec.js index 60b7206e..8aad2e17 100644 --- a/docs/src/demos/Extensions/Italic/index.spec.js +++ b/docs/src/demos/Extensions/Italic/index.spec.js @@ -10,12 +10,12 @@ context('/api/extensions/italic', () => { }) describe('italic', () => { - it('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('.ProseMirror').contains('em', 'Example Text') }) - it('should toggle the selected text italic', () => { + it('the button should toggle the selected text italic', () => { cy.get('.demo__preview button:first').dblclick({ force: true }) cy.get('.ProseMirror em').should('not.exist') }) @@ -27,7 +27,7 @@ context('/api/extensions/italic', () => { cy.get('.ProseMirror').contains('em', 'Example Text') }) - it('the button should toggle the selected text italic', () => { + it('the keyboard shortcut should toggle the selected text italic', () => { const shortcut = Cypress.platform === 'darwin' ? '{meta}i' : '{ctrl}i' cy.get('.ProseMirror').type(shortcut, {force: true}).type(shortcut, {force: true})