|
| 1 | +/** |
| 2 | + * @copyright Copyright (c) 2020 Julius Härtl <[email protected]> |
| 3 | + * |
| 4 | + * @author Julius Härtl <[email protected]> |
| 5 | + * |
| 6 | + * @license AGPL-3.0-or-later |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License as |
| 10 | + * published by the Free Software Foundation, either version 3 of the |
| 11 | + * License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License |
| 19 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +import { randUser } from '../utils/index.js' |
| 24 | + |
| 25 | +const user = randUser() |
| 26 | + |
| 27 | +describe('Test state loading of documents', function() { |
| 28 | + before(function() { |
| 29 | + // Init user |
| 30 | + cy.createUser(user) |
| 31 | + cy.login(user) |
| 32 | + cy.uploadFile('test.md', 'text/markdown') |
| 33 | + cy.uploadFile('test.md', 'text/markdown', 'test2.md') |
| 34 | + cy.uploadFile('test.md', 'text/markdown', 'test3.md') |
| 35 | + }) |
| 36 | + beforeEach(function() { |
| 37 | + cy.login(user) |
| 38 | + }) |
| 39 | + |
| 40 | + it('Initial content can not be undone', function() { |
| 41 | + cy.shareFile('/test.md', { edit: true }) |
| 42 | + .then((token) => { |
| 43 | + cy.visit(`/s/${token}`) |
| 44 | + }) |
| 45 | + .then(() => { |
| 46 | + cy.getEditor().should('be.visible') |
| 47 | + cy.getContent() |
| 48 | + .should('contain', 'Hello world') |
| 49 | + .find('h2').should('contain', 'Hello world') |
| 50 | + |
| 51 | + cy.getMenu().should('be.visible') |
| 52 | + cy.getActionEntry('undo').should('be.visible').click() |
| 53 | + cy.getContent() |
| 54 | + .should('contain', 'Hello world') |
| 55 | + .find('h2').should('contain', 'Hello world') |
| 56 | + }) |
| 57 | + }) |
| 58 | + |
| 59 | + it('Consecutive sessions work properly', function() { |
| 60 | + let readToken = null |
| 61 | + let writeToken = null |
| 62 | + cy.interceptCreate() |
| 63 | + cy.shareFile('/test2.md') |
| 64 | + .then((token) => { |
| 65 | + readToken = token |
| 66 | + cy.logout() |
| 67 | + cy.visit(`/s/${readToken}`) |
| 68 | + cy.wait('@create') |
| 69 | + }) |
| 70 | + .then(() => { |
| 71 | + // Open read only for the first time |
| 72 | + cy.getEditor().should('be.visible') |
| 73 | + cy.getContent() |
| 74 | + .should('contain', 'Hello world') |
| 75 | + .find('h2').should('contain', 'Hello world') |
| 76 | + cy.closeInterceptedSession(readToken) |
| 77 | + |
| 78 | + // Open read only for the second time |
| 79 | + cy.reload() |
| 80 | + cy.getEditor().should('be.visible') |
| 81 | + cy.getContent() |
| 82 | + .should('contain', 'Hello world') |
| 83 | + .find('h2').should('contain', 'Hello world') |
| 84 | + cy.closeInterceptedSession(readToken) |
| 85 | + |
| 86 | + cy.login(user) |
| 87 | + cy.shareFile('/test2.md', { edit: true }) |
| 88 | + .then((token) => { |
| 89 | + writeToken = token |
| 90 | + // Open write link and edit something |
| 91 | + cy.visit(`/s/${writeToken}`) |
| 92 | + cy.getEditor().should('be.visible') |
| 93 | + cy.getContent() |
| 94 | + .should('contain', 'Hello world') |
| 95 | + .find('h2').should('contain', 'Hello world') |
| 96 | + cy.getContent() |
| 97 | + .type('Something new {end}') |
| 98 | + cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push') |
| 99 | + cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync') |
| 100 | + cy.wait('@push') |
| 101 | + cy.wait('@sync') |
| 102 | + cy.closeInterceptedSession(writeToken) |
| 103 | + |
| 104 | + // Reopen read only link and check if changes are there |
| 105 | + cy.visit(`/s/${readToken}`) |
| 106 | + cy.getEditor().should('be.visible') |
| 107 | + cy.getContent() |
| 108 | + .find('h2').should('contain', 'Something new Hello world') |
| 109 | + }) |
| 110 | + }) |
| 111 | + }) |
| 112 | + |
| 113 | + it('Load after state has been saved', function() { |
| 114 | + let readToken = null |
| 115 | + let writeToken = null |
| 116 | + cy.interceptCreate() |
| 117 | + cy.shareFile('/test3.md', { edit: true }) |
| 118 | + .then((token) => { |
| 119 | + writeToken = token |
| 120 | + cy.logout() |
| 121 | + cy.visit(`/s/${writeToken}`) |
| 122 | + }) |
| 123 | + .then(() => { |
| 124 | + // Open a file, write and save |
| 125 | + cy.getEditor().should('be.visible') |
| 126 | + cy.getContent() |
| 127 | + .should('contain', 'Hello world') |
| 128 | + .find('h2').should('contain', 'Hello world') |
| 129 | + cy.getContent() |
| 130 | + .type('Something new {end}') |
| 131 | + cy.intercept({ method: 'POST', url: '**/session/*/save' }).as('save') |
| 132 | + cy.get('.save-status button').click() |
| 133 | + cy.wait('@save', { timeout: 10000 }) |
| 134 | + cy.closeInterceptedSession(writeToken) |
| 135 | + |
| 136 | + // Open writable file again and assert the content |
| 137 | + cy.reload() |
| 138 | + cy.getEditor().should('be.visible') |
| 139 | + cy.getContent() |
| 140 | + .should('contain', 'Hello world') |
| 141 | + .find('h2').should('contain', 'Something new Hello world') |
| 142 | + |
| 143 | + cy.login(user) |
| 144 | + cy.shareFile('/test3.md') |
| 145 | + .then((token) => { |
| 146 | + readToken = token |
| 147 | + cy.logout() |
| 148 | + cy.visit(`/s/${readToken}`) |
| 149 | + }) |
| 150 | + .then(() => { |
| 151 | + // Open read only file again and assert the content |
| 152 | + cy.getEditor().should('be.visible') |
| 153 | + cy.getContent() |
| 154 | + .should('contain', 'Hello world') |
| 155 | + .find('h2').should('contain', 'Something new Hello world') |
| 156 | + }) |
| 157 | + }) |
| 158 | + }) |
| 159 | + |
| 160 | +}) |
0 commit comments