Skip to content

Commit

Permalink
Merge pull request #2874 from nextcloud/bugfix/2873
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Mar 29, 2023
2 parents bc5fc06 + fc9d675 commit a0fac1f
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 10 deletions.
67 changes: 67 additions & 0 deletions cypress/e2e/direct.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* SPDX-FileLicenseText: 2023 Julius Härtl <jus@bitgrid.net>
* 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 <http://www.gnu.org/licenses/>.
*
*/

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')
})
})

})
30 changes: 21 additions & 9 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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) {
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a0fac1f

Please sign in to comment.