From 301341dfe6be0542975f6cf21c1ec9f9345b13d5 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 18 Jun 2024 09:51:09 +0200 Subject: [PATCH] test(cy): do not wait for push after initialization The toc does not trigger a transaction anymore and therefore there is no push to wait for either. Also use cypress aliases and avoid deep nesting of cypress calls when possible. Signed-off-by: Max [skip ci] --- cypress/e2e/initial.spec.js | 201 +++++++++++++++++------------------- 1 file changed, 94 insertions(+), 107 deletions(-) diff --git a/cypress/e2e/initial.spec.js b/cypress/e2e/initial.spec.js index aac7fd98c69..c8bb0038688 100644 --- a/cypress/e2e/initial.spec.js +++ b/cypress/e2e/initial.spec.js @@ -39,123 +39,110 @@ describe('Test state loading of documents', function() { it('Initial content can not be undone', function() { cy.shareFile('/test.md', { edit: true }) - .then((token) => { - cy.visit(`/s/${token}`) - }) - .then(() => { - cy.getEditor().should('be.visible') - cy.getContent() - .should('contain', 'Hello world') - .find('h2').should('contain', 'Hello world') - - cy.getMenu().should('be.visible') - cy.getActionEntry('undo').should('be.disabled') - - cy.getContent() - .type('New content') - cy.getActionEntry('undo').should('not.be.disabled') - }) + .then(token => cy.visit(`/s/${token}`)) + cy.getEditor().should('be.visible') + cy.getContent() + .should('contain', 'Hello world') + .find('h2').should('contain', 'Hello world') + + cy.getMenu().should('be.visible') + cy.getActionEntry('undo').should('be.disabled') + + cy.getContent() + .type('New content') + cy.getActionEntry('undo').should('not.be.disabled') }) it('Consecutive sessions work properly', function() { - let readToken = null - let writeToken = null cy.interceptCreate() cy.shareFile('/test2.md') - .then((token) => { - readToken = token - cy.logout() - cy.visit(`/s/${readToken}`) - cy.wait('@create') - }) - .then(() => { - // Open read only for the first time - cy.getEditor().should('be.visible') - cy.getContent() - .should('contain', 'Hello world') - .find('h2').should('contain', 'Hello world') - cy.closeInterceptedSession(readToken) - - // Open read only for the second time - cy.reload() - cy.getEditor().should('be.visible') - cy.getContent() - .should('contain', 'Hello world') - .find('h2').should('contain', 'Hello world') - cy.closeInterceptedSession(readToken) - - cy.login(user) - cy.shareFile('/test2.md', { edit: true }) - .then((token) => { - writeToken = token - // Open write link and edit something - cy.visit(`/s/${writeToken}`) - cy.getEditor().should('be.visible') - cy.getContent() - .should('contain', 'Hello world') - .find('h2').should('contain', 'Hello world') - cy.getContent() - .type('Something new {end}') - cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push') - cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync') - cy.wait('@push') - cy.wait('@sync') - cy.closeInterceptedSession(writeToken) - - // Reopen read only link and check if changes are there - cy.visit(`/s/${readToken}`) - cy.getEditor().should('be.visible') - cy.getContent() - .find('h2').should('contain', 'Something new Hello world') - }) - }) + .as('readToken') + cy.logout() + cy.get('@readToken') + .then(token => cy.visit(`/s/${token}`)) + cy.wait('@create') + // Open read only for the first time + cy.getEditor().should('be.visible') + cy.getContent() + .should('contain', 'Hello world') + .find('h2').should('contain', 'Hello world') + cy.get('@readToken') + .then(cy.closeInterceptedSession) + + // Open read only for the second time + cy.reload() + cy.getEditor().should('be.visible') + cy.getContent() + .should('contain', 'Hello world') + .find('h2').should('contain', 'Hello world') + cy.get('@readToken') + .then(cy.closeInterceptedSession) + + cy.login(user) + cy.shareFile('/test2.md', { edit: true }) + .as('writeToken') + // Open write link and edit something + cy.get('@writeToken') + .then(token => cy.visit(`/s/${token}`)) + cy.getEditor().should('be.visible') + cy.getContent() + .should('contain', 'Hello world') + .find('h2').should('contain', 'Hello world') + cy.getContent() + .type('Something new {end}') + cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync') + cy.wait('@sync') + cy.get('@writeToken') + .then(cy.closeInterceptedSession) + + // Reopen read only link and check if changes are there + cy.get('@readToken') + .then(token => cy.visit(`/s/${token}`)) + cy.getEditor().should('be.visible') + cy.getContent() + .find('h2').should('contain', 'Something new Hello world') }) it('Load after state has been saved', function() { - let readToken = null - let writeToken = null cy.interceptCreate() cy.shareFile('/test3.md', { edit: true }) - .then((token) => { - writeToken = token - cy.logout() - cy.visit(`/s/${writeToken}`) - }) - .then(() => { - // Open a file, write and save - cy.getEditor().should('be.visible') - cy.getContent() - .should('contain', 'Hello world') - .find('h2').should('contain', 'Hello world') - cy.getContent() - .type('Something new {end}') - cy.intercept({ method: 'POST', url: '**/session/*/save' }).as('save') - cy.get('.save-status button').click() - cy.wait('@save', { timeout: 10000 }) - cy.closeInterceptedSession(writeToken) - - // Open writable file again and assert the content - cy.reload() - cy.getEditor().should('be.visible') - cy.getContent() - .should('contain', 'Hello world') - .find('h2').should('contain', 'Something new Hello world') - - cy.login(user) - cy.shareFile('/test3.md') - .then((token) => { - readToken = token - cy.logout() - cy.visit(`/s/${readToken}`) - }) - .then(() => { - // Open read only file again and assert the content - cy.getEditor().should('be.visible') - cy.getContent() - .should('contain', 'Hello world') - .find('h2').should('contain', 'Something new Hello world') - }) - }) + .as('writeToken') + cy.logout() + cy.get('@writeToken') + .then(token => cy.visit(`/s/${token}`)) + + // Open a file, write and save + cy.getEditor().should('be.visible') + cy.getContent() + .should('contain', 'Hello world') + .find('h2').should('contain', 'Hello world') + cy.getContent() + .type('Something new {end}') + cy.intercept({ method: 'POST', url: '**/session/*/save' }).as('save') + cy.get('.save-status button').click() + cy.wait('@save', { timeout: 10000 }) + cy.get('@writeToken') + .then(cy.closeInterceptedSession) + + // Open writable file again and assert the content + cy.reload() + cy.getEditor().should('be.visible') + cy.getContent() + .should('contain', 'Hello world') + .find('h2').should('contain', 'Something new Hello world') + + cy.login(user) + cy.shareFile('/test3.md') + .as('readToken') + cy.logout() + cy.get('@readToken') + .then(token => cy.visit(`/s/${token}`)) + + // Open read only file again and assert the content + cy.getEditor().should('be.visible') + cy.getContent() + .should('contain', 'Hello world') + .find('h2').should('contain', 'Something new Hello world') }) })