Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions cypress/e2e/attachments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

import { initUserAndFiles, randHash, randUser } from '../utils/index.js'
import 'cypress-file-upload'

const user = randUser()
const recipient = randUser()
Expand All @@ -41,7 +40,12 @@ function attachFile(name, requestAlias = null) {
}
return cy.getEditor()
.find('input[type="file"][data-text-el="attachment-file-input"]')
.attachFile(name)
.selectFile([
{
contents: 'cypress/fixtures/' + name,
fileName: name,
},
], { force: true })
}

/**
Expand Down Expand Up @@ -406,10 +410,4 @@ describe('Test all attachment insertion methods', () => {
}
})
})

it('Delete the user', () => {
cy.deleteUser(user)
cy.deleteUser(recipient)
})

})
1 change: 0 additions & 1 deletion cypress/e2e/nodes/ImageView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('Image View', () => {
before(() => {
cy.createUser(user)
cy.login(user)
cy.visit('/apps/files')

// Upload test files to user's storage
cy.createFolder('child-folder')
Expand Down
1 change: 0 additions & 1 deletion cypress/e2e/nodes/Mentions.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { initUserAndFiles, randUser } from '../../utils/index.js'
import 'cypress-file-upload'

const user = randUser()
const mentionMe = randUser()
Expand Down
5 changes: 5 additions & 0 deletions cypress/e2e/sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ describe('Sync', () => {

it('recovers from a lost connection', () => {
let count = 0
cy.intercept({ method: 'PUT', url: '**/apps/text/session/create' })
.as('createSession')
cy.intercept({ method: 'POST', url: '**/apps/text/session/*' }, (req) => {
if (count < 4) {
req.destroy()
Expand All @@ -86,6 +88,9 @@ describe('Sync', () => {
cy.wait('@syncAfterRecovery', { timeout: 30000 })
cy.get('#editor-container .document-status', { timeout: 30000 })
.should('not.contain', 'File could not be loaded')
// FIXME: There seems to be a bug where typed words maybe lost if not waiting for the new session
cy.wait('@createSession')
cy.wait('@syncAfterRecovery')
cy.getContent().type('* more content added after the lost connection{enter}')
cy.wait('@syncAfterRecovery')
cy.closeFile()
Expand Down
88 changes: 51 additions & 37 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,61 @@ addCommands()
// and also to determine paths, urls and the like.
let auth
Cypress.Commands.overwrite('login', (login, user) => {
cy.window().then((win) => {
win.location.href = 'about:blank'
})
auth = { user: user.userId, password: user.password }
login(user)
})

Cypress.Commands.add('ocsRequest', (options) => {
return cy.request({
form: true,
auth,
headers: {
'OCS-ApiRequest': 'true',
'Content-Type': 'application/x-www-form-urlencoded',
},
...options,
})
return cy.request('/csrftoken')
.then(({ body }) => body.token)
.then(requesttoken => {
return cy.request({
form: true,
auth,
headers: {
'OCS-ApiRequest': 'true',
'Content-Type': 'application/x-www-form-urlencoded',
requesttoken,
},
...options,
})
})
})

Cypress.Commands.add('uploadFile', (fileName, mimeType, target) => {
return cy.fixture(fileName, 'base64')
.then(Cypress.Blob.base64StringToBlob)
return cy.fixture(fileName, 'binary')
.then(Cypress.Blob.binaryStringToBlob)
.then(blob => {
const file = new File([blob], fileName, { type: mimeType })
if (typeof target !== 'undefined') {
fileName = target
}
return cy.request('/csrftoken')
.then(({ body }) => body.token)
.then(requesttoken => {
return axios.put(`${url}/remote.php/webdav/${fileName}`, file, {
cy.request('/csrftoken')
.then(({ body }) => {
return cy.wrap(body.token)
})
.then(async (requesttoken) => {
return cy.request({
url: `${url}/remote.php/webdav/${fileName}`,
method: 'put',
body: blob.size > 0 ? blob : '',
auth,
headers: {
requesttoken,
'Content-Type': mimeType,
},
}).then(response => {
const fileId = Number(
response.headers['oc-fileid']?.split('oc')?.[0]
)
cy.log(`Uploaded ${fileName}`,
response.status,
{ fileId }
)
return fileId
})
}).then(response => {
const fileId = Number(
response.headers['oc-fileid']?.split('oc')?.[0]
)
cy.log(`Uploaded ${fileName}`,
response.status,
{ fileId }
)
return cy.wrap(fileId)
})
})
})
Expand All @@ -95,27 +108,27 @@ Cypress.Commands.add('downloadFile', (fileName) => {
})

Cypress.Commands.add('createFile', (target, content, mimeType = 'text/markdown') => {
const fileName = target.split('/').pop()

const blob = new Blob([content], { type: mimeType })
const file = new File([blob], fileName, { type: mimeType })

return cy.window()
.then(async win => {
const response = await axios.put(`${url}/remote.php/webdav/${target}`, file, {
return cy.request('/csrftoken')
.then(({ body }) => body.token)
.then(requesttoken => {
return cy.request({
url: `${url}/remote.php/webdav/${target}`,
method: 'put',
body: blob.size > 0 ? blob : '',
auth,
headers: {
requesttoken: win.OC.requestToken,
'Content-Type': mimeType,
requesttoken,
},
}).then((response) => {
return cy.log(`Uploaded ${target}`, response.status)
})

return cy.log(`Uploaded ${fileName}`, response.status)
})

})

Cypress.Commands.add('shareFileToUser', (path, targetUser, shareData = {}) => {
cy.clearCookies()
cy.ocsRequest({
method: 'POST',
url: `${url}/ocs/v2.php/apps/files_sharing/api/v1/shares`,
Expand Down Expand Up @@ -212,7 +225,8 @@ Cypress.Commands.add('createFolder', (target) => {
return cy.request('/csrftoken')
.then(({ body }) => body.token)
.then(requesttoken => {
return axios.request(`${rootPath}/${dirPath}`, {
return cy.request({
url: `${rootPath}/${dirPath}`,
method: 'MKCOL',
auth,
headers: {
Expand Down
20 changes: 0 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
"@vue/test-utils": "^1.3.0 <2",
"@vue/vue2-jest": "^29.2.4",
"cypress": "^12.15.0",
"cypress-file-upload": "^5.0.8",
"eslint-plugin-cypress": "^2.13.3",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.5.0",
Expand Down