Skip to content

Commit

Permalink
test(cypress): Add simple federated editing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Aug 20, 2024
1 parent b649ea4 commit f0dce12
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cypress/e2e/direct.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
})
})
})
})

})
43 changes: 43 additions & 0 deletions cypress/e2e/share-federated.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* SPDX-FileCopyrightText: 2023 Julius Härtl <jus@bitgrid.net>
* 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')
})
})
38 changes: 38 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit f0dce12

Please sign in to comment.