diff --git a/cypress/e2e/initial.spec.js b/cypress/e2e/initial.spec.js new file mode 100644 index 00000000000..d4e10ef8cd4 --- /dev/null +++ b/cypress/e2e/initial.spec.js @@ -0,0 +1,157 @@ +/** + * @copyright Copyright (c) 2020 Julius Härtl + * + * @author Julius Härtl + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import { randUser } from '../utils/index.js' + +const user = randUser() + +describe('Test state loading of documents', function() { + before(function() { + // Init user + cy.createUser(user) + cy.login(user) + cy.uploadFile('test.md', 'text/markdown') + }) + beforeEach(function() { + cy.login(user) + }) + + 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.visible').click() + cy.getContent() + .should('contain', 'Hello world') + .find('h2').should('contain', 'Hello world') + }) + }) + + it('Consecutive sessions work properly', function() { + cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push') + cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync') + + let readToken = null + let writeToken = null + cy.shareFile('/test.md') + .then((token) => { + readToken = token + cy.logout() + cy.visit(`/s/${readToken}`) + }) + .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') + + // 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.login(user) + cy.shareFile('/test.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.wait('@push') + cy.wait('@sync') + + // 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') + + }) + }) + }) + + it('Load after state has been saved', function() { + cy.uploadFile('test.md', 'text/markdown') + cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push') + cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync') + cy.intercept({ method: 'POST', url: '**/session/*/save' }).as('save') + + let readToken = null + let writeToken = null + cy.shareFile('/test.md', { edit: true }) + .then((token) => { + writeToken = token + cy.logout() + cy.visit(`/s/${writeToken}`) + }) + .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.getContent() + .type('Something new {end}') + cy.get('.save-status button').click() + cy.wait('@save') + + // Open read only for the second time + 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('/test.md') + .then((token) => { + readToken = token + cy.logout() + cy.visit(`/s/${readToken}`) + }) + .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') + }) + }) + }) + +})