From ab794e4e0abcef97b09bb8c2b91029612e7d27ce Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 2 May 2024 06:45:02 +0200 Subject: [PATCH] test(cy): simplify direct editing spec Extract function `enterContentAndClose()`. Signed-off-by: Max --- cypress/e2e/directediting.spec.js | 88 +++++++++---------------------- 1 file changed, 26 insertions(+), 62 deletions(-) diff --git a/cypress/e2e/directediting.spec.js b/cypress/e2e/directediting.spec.js index 82c0f9d364..9915ad8064 100644 --- a/cypress/e2e/directediting.spec.js +++ b/cypress/e2e/directediting.spec.js @@ -2,6 +2,21 @@ import { initUserAndFiles, randUser } from '../utils/index.js' const user = randUser() +function enterContentAndClose() { + cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest') + cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push') + cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync') + cy.getContent().type('# This is a headline') + cy.getContent().type('{enter}') + cy.getContent().type('Some text') + cy.getContent().type('{enter}') + cy.getContent().type('{ctrl+s}') + cy.wait('@push') + cy.wait('@sync') + cy.get('button.icon-close').click() + cy.wait('@closeRequest') +} + describe('direct editing', function() { before(function() { @@ -9,92 +24,41 @@ describe('direct editing', function() { }) it('Open an existing file, edit it', () => { - cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest') - cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push') - cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync') - cy.login(user) cy.createDirectEditingLink('empty.md') .then((token) => { cy.session('direct-editing', () => { }) cy.openDirectEditingToken(token) }) - cy.getContent().type('# This is a headline') - cy.getContent().type('{enter}') - cy.getContent().type('Some text') - cy.getContent().type('{enter}') - cy.getContent().type('{ctrl+s}') - - cy.wait('@push') - cy.wait('@sync') - - cy.get('button.icon-close').click() - cy.wait('@closeRequest') + enterContentAndClose() cy.login(user) - cy.getFileContent('empty.md').then((content) => { - expect(content).to.equal('# This is a headline\n\nSome text') - }) + cy.getFileContent('empty.md') + .should('equal', '# This is a headline\n\nSome text') }) it('Create a file, edit it', () => { - cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest') - cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push') - cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync') - cy.login(user) cy.createDirectEditingLinkForNewFile('newfile.md') .then((token) => { cy.session('direct-editing', () => { }) cy.openDirectEditingToken(token) }) - - cy.getContent().type('# This is a headline') - cy.getContent().type('{enter}') - cy.getContent().type('Some text') - cy.getContent().type('{enter}') - cy.getContent().type('{ctrl+s}') - - cy.wait('@push') - cy.wait('@sync') - - cy.get('button.icon-close').click() - cy.wait('@closeRequest') - .then(() => { - cy.login(user) - cy.getFileContent('newfile.md').then((content) => { - expect(content).to.equal('# This is a headline\n\nSome text') - }) - }) + enterContentAndClose() + cy.login(user) + cy.getFileContent('newfile.md') + .should('equal', '# This is a headline\n\nSome text') }) it('Open an existing plain text file, edit it', () => { - cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest') - cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push') - cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync') - cy.login(user) cy.createDirectEditingLink('empty.txt') .then((token) => { cy.session('direct-editing', () => { }) cy.openDirectEditingToken(token) }) - - cy.getContent().type('# This is a headline') - cy.getContent().type('{enter}') - cy.getContent().type('Some text') - cy.getContent().type('{enter}') - cy.getContent().type('{ctrl+s}') - - cy.wait('@push') - cy.wait('@sync') - - cy.get('button.icon-close').click() - cy.wait('@closeRequest') - .then(() => { - cy.login(user) - cy.getFileContent('empty.txt').then((content) => { - expect(content).to.equal('# This is a headline\nSome text\n') - }) - }) + enterContentAndClose() + cy.login(user) + cy.getFileContent('empty.txt') + .should('equal', '# This is a headline\nSome text\n') }) })