From 247c8cb96622cb0bbcccb82faaea3ac7898d6065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 23 Mar 2023 13:14:02 +0100 Subject: [PATCH 1/2] tests(cypress): Add basic test for direct editing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- cypress/e2e/direct.spec.js | 67 +++++++++++++++++++++++++++++++++++++ cypress/support/commands.js | 30 ++++++++++++----- 2 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 cypress/e2e/direct.spec.js diff --git a/cypress/e2e/direct.spec.js b/cypress/e2e/direct.spec.js new file mode 100644 index 0000000000..0467ec7e84 --- /dev/null +++ b/cypress/e2e/direct.spec.js @@ -0,0 +1,67 @@ +/** + * SPDX-FileLicenseText: 2023 Julius Härtl + * SPDX-License-Identifier: 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 . + * + */ + +const createDirectEditingLink = (user, fileId) => { + cy.login(user) + return cy.request({ + method: 'POST', + url: `${Cypress.env('baseUrl')}/ocs/v2.php/apps/richdocuments/api/v1/document?format=json`, + form: true, + body: { + fileId, + }, + auth: { user: user.userId, pass: user.password }, + headers: { + 'OCS-ApiRequest': 'true', + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }).then(response => { + cy.log(response) + const token = response.body?.ocs?.data?.url + cy.log(`Created direct editing token for ${user.userId}`, token) + cy.wrap(token) + }) +} +describe('Direct editing (legacy)', function() { + let randUser + let fileId + + before(function() { + cy.createRandomUser().then(user => { + randUser = user + cy.login(user) + cy.uploadFile(user, 'document.odt', 'application/vnd.oasis.opendocument.text', '/document.odt') + .then((id) => { + fileId = id + }) + }) + }) + + it('Open an existing file', function() { + createDirectEditingLink(randUser, fileId) + .then((token) => { + cy.nextcloudTestingAppConfigSet('richdocuments', 'uiDefaults-UIMode', 'classic') + cy.logout() + cy.visit(token) + cy.waitForCollabora(false) + cy.screenshot('direct') + }) + }) + +}) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index fd8b7798d3..ab7944b7c6 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -71,7 +71,7 @@ Cypress.Commands.add('uploadFile', (user, fixture, mimeType, target = `/${fixtur const filePath = target.split('/').map(encodeURIComponent).join('/') try { const file = new File([blob], fileName, { type: mimeType }) - return cy.request('/csrftoken') + cy.request('/csrftoken') .then(({ body }) => body.token) .then(requesttoken => { return axios.put(`${rootPath}/${filePath}`, file, { @@ -80,7 +80,12 @@ Cypress.Commands.add('uploadFile', (user, fixture, mimeType, target = `/${fixtur 'Content-Type': mimeType, }, }).then(response => { - cy.log(`Uploaded ${fileName}`, response.status) + const fileId = Number( response.headers['oc-fileid']?.split('oc')?.[0]) + cy.log(`Uploaded ${fileName}`, + response.status, + { fileId } + ) + cy.wrap(fileId) }) }) } catch (error) { @@ -199,13 +204,20 @@ Cypress.Commands.add('waitForViewer', () => { .and('have.class', 'modal-mask') .and('not.have.class', 'icon-loading') }) -Cypress.Commands.add('waitForCollabora', () => { - cy.get('[data-cy="documentframe"]', { timeout: 30000 }) - .its('0.contentDocument') - .its('body').should('not.be.empty') - .should('be.visible').should('not.be.empty') - .as('collaboraframe') - cy.get('@collaboraframe').find('[data-cy="coolframe"]', { timeout: 30000 }) +Cypress.Commands.add('waitForCollabora', (wrapped = true) => { + if (wrapped) { + cy.get('[data-cy="documentframe"]', { timeout: 30000 }) + .its('0.contentDocument') + .its('body').should('not.be.empty') + .should('be.visible').should('not.be.empty') + .as('collaboraframe') + } + + const coolFrame = wrapped + ? cy.get('@collaboraframe').find('[data-cy="coolframe"]', { timeout: 30000 }) + : cy.get('[data-cy="coolframe"]') + + coolFrame .its('0.contentDocument') .its('body').should('not.be.empty') .as('loleafletframe') From fc9d675a9feb163be3b11b5887781a52bc0dcbd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 23 Mar 2023 13:14:53 +0100 Subject: [PATCH 2/2] fix: Fix initial document state value name for direct editing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/helpers/mobile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/mobile.js b/src/helpers/mobile.js index 0a026e23b5..be8fd81a27 100644 --- a/src/helpers/mobile.js +++ b/src/helpers/mobile.js @@ -22,7 +22,7 @@ import Config from './../services/config.tsx' -const isDirectEditing = () => Config.get('directEdit') +const isDirectEditing = () => Config.get('direct') const isMobileInterfaceAvailable = () => window.RichDocumentsMobileInterface || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.RichDocumentsMobileInterface)