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 <[email protected]>
  • Loading branch information
juliusknorr committed Aug 20, 2024
1 parent b649ea4 commit 6bcd4b0
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
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)
})
})
})
})

})
40 changes: 40 additions & 0 deletions cypress/e2e/share-federated.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* SPDX-FileCopyrightText: 2023 Julius Härtl <[email protected]>
* 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(true, true).within(() => {
cy.get('#closebutton').click()
cy.get('#viewer', { timeout: 5000 }).should('not.exist')
})
})
})
51 changes: 48 additions & 3 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 Expand Up @@ -190,9 +228,10 @@ Cypress.Commands.add('waitForViewer', () => {
.and('not.have.class', 'icon-loading')
})

Cypress.Commands.add('waitForCollabora', (wrapped = false) => {
Cypress.Commands.add('waitForCollabora', (wrapped = false, federated = false) => {
const wrappedFrameIdentifier = federated ? 'coolframe' : 'documentframe'
if (wrapped) {
cy.get('[data-cy="documentframe"]', { timeout: 30000 })
cy.get(`[data-cy="${wrappedFrameIdentifier}"]`, { timeout: 30000 })
.its('0.contentDocument')
.its('body').should('not.be.empty')
.should('be.visible').should('not.be.empty')
Expand All @@ -207,7 +246,13 @@ Cypress.Commands.add('waitForCollabora', (wrapped = false) => {
.its('0.contentDocument')
.its('body').should('not.be.empty')
.as('loleafletframe')
cy.get('@loleafletframe').find('#main-document-content').should('be.visible')

cy.get('@loleafletframe')
.within(() => {
cy.get('#main-document-content').should('be.visible')
})

return cy.get('@loleafletframe')
})

Cypress.Commands.add('waitForPostMessage', (messageId, values = undefined) => {
Expand Down

0 comments on commit 6bcd4b0

Please sign in to comment.