From f0dce125bb56e09d149a24ea62c8245698c7c197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 20 Aug 2024 11:43:53 +0200 Subject: [PATCH] test(cypress): Add simple federated editing tests 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 | 17 +++++++++++- cypress/e2e/share-federated.spec.js | 43 +++++++++++++++++++++++++++++ cypress/support/commands.js | 38 +++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 cypress/e2e/share-federated.spec.js diff --git a/cypress/e2e/direct.spec.js b/cypress/e2e/direct.spec.js index 7247454102..c93b070a8c 100644 --- a/cypress/e2e/direct.spec.js +++ b/cypress/e2e/direct.spec.js @@ -11,7 +11,7 @@ const createDirectEditingLink = (user, fileId) => { body: { fileId, }, - auth: { user: user.userId, pass: user.password }, + // auth: { user: user.userId, pass: user.password }, headers: { 'OCS-ApiRequest': 'true', 'Content-Type': 'application/x-www-form-urlencoded', @@ -88,4 +88,19 @@ describe('Direct editing (legacy)', function() { }) }) + it('Open a remotely shared file', () => { + cy.createRandomUser().then(shareRecipient => { + cy.login(randUser) + cy.shareFileToRemoteUser(randUser, '/document.odt', shareRecipient) + .then(incomingFileId => { + createDirectEditingLink(shareRecipient, incomingFileId) + .then((token) => { + cy.logout() + cy.visit(token) + cy.waitForCollabora(false) + }) + }) + }) + }) + }) diff --git a/cypress/e2e/share-federated.spec.js b/cypress/e2e/share-federated.spec.js new file mode 100644 index 0000000000..f0a7e1748a --- /dev/null +++ b/cypress/e2e/share-federated.spec.js @@ -0,0 +1,43 @@ +/** + * SPDX-FileCopyrightText: 2023 Julius Härtl + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { User } from '@nextcloud/cypress' +import { randHash } from '../utils/index.js' +const shareOwner = new User(randHash(), randHash()) +const shareRecipient = new User(randHash(), randHash()) + +describe('Federated sharing of office documents', function() { + + before(function() { + cy.nextcloudEnableApp('testing') + cy.nextcloudTestingAppConfigSet('richdocuments', 'uiDefaults-UIMode', 'notebookbar') + cy.createUser(shareRecipient) + cy.createUser(shareOwner) + + cy.uploadFile(shareOwner, 'document.odt', 'application/vnd.oasis.opendocument.text', '/document.odt') + }) + + it('Open a remotely shared file', function() { + const filename = 'document.odt' + + cy.login(shareOwner) + cy.shareFileToRemoteUser(shareOwner, '/document.odt', shareRecipient) + cy.login(shareRecipient) + + cy.visit('/apps/files', { + onBeforeLoad(win) { + cy.spy(win, 'postMessage').as('postMessage') + }, + }) + cy.openFile(filename) + cy.waitForViewer() + cy.waitForCollabora() + + // Validate closing + cy.get('@loleafletframe').within(() => { + cy.get('#closebutton').click() + }) + cy.get('#viewer', { timeout: 5000 }).should('not.exist') + }) +}) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index ccb776dcd5..08e9e2baea 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -109,6 +109,44 @@ Cypress.Commands.add('shareFileToUser', (user, path, targetUser, shareData = {}) }) }) +Cypress.Commands.add('shareFileToRemoteUser', (user, path, targetUser, shareData = {}) => { + cy.login(user) + const federatedId = `${targetUser.userId}@${url}` + return cy.ocsRequest(user, { + method: 'POST', + url: `${url}/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json`, + body: { + path, + shareType: 6, + shareWith: federatedId, + ...shareData, + }, + }).then(response => { + cy.log(`${user.userId} shared ${path} with ${federatedId}`, response.status) + cy.login(targetUser) + return cy.ocsRequest(targetUser, { + method: 'GET', + url: `${url}/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending?format=json`, + }) + }).then(({ body }) => { + for (const index in body.ocs.data) { + cy.ocsRequest(targetUser, { + method: 'POST', + url: `${url}/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/${body.ocs.data[index].id}`, + }) + return cy.wrap(body.ocs.data[index].id) + } + }).then((shareId) => { + cy.ocsRequest(targetUser, { + method: 'GET', + url: `${url}/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/${shareId}?format=json`, + }).then((response) => { + cy.login(user) + return cy.wrap(response.body.ocs.data['file_id']) + }) + }) +}) + Cypress.Commands.add('shareLink', (user, path, shareData = {}) => { cy.login(user) cy.ocsRequest(user, {