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
8 changes: 4 additions & 4 deletions cypress/e2e/propfind.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const user = randUser()

// Retries fail because folders / files already exist.
describe('Text PROPFIND extension ', { retries: 0 }, function () {
const richWorkspace = '{http://nextcloud.org/ns}rich-workspace'
const richWorkspace = 'nc:rich-workspace'

before(function () {
cy.createUser(user)
Expand Down Expand Up @@ -48,11 +48,11 @@ describe('Text PROPFIND extension ', { retries: 0 }, function () {
// For now the dashboard avoids that we have failing requests due to conflicts when updating the file
cy.visit('/apps/dashboard')
cy.propfindFolder('/', 1)
.then((results) => results.pop().propStat[0].properties)
.then((results) => results.pop())
.should('have.property', richWorkspace, '')
cy.uploadFile('test.md', 'text/markdown', '/workspace/Readme.md')
cy.propfindFolder('/', 1)
.then((results) => results.pop().propStat[0].properties)
.then((results) => results.pop())
.should('have.property', richWorkspace, '## Hello world\n')
})
})
Expand All @@ -71,7 +71,7 @@ describe('Text PROPFIND extension ', { retries: 0 }, function () {
cy.propfindFolder('/').should('not.have.property', richWorkspace)
cy.createFolder('/without-workspace')
cy.propfindFolder('/', 1)
.then((results) => results.pop().propStat[0].properties)
.then((results) => results.pop())
.should('not.have.property', richWorkspace)
})
})
Expand Down
79 changes: 59 additions & 20 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,66 @@ Cypress.Commands.add('getFileContent', (path) => {
})

Cypress.Commands.add('propfindFolder', (path, depth = 0) => {
return cy.window(silent).then((win) => {
const files = win.OC.Files
const PROPERTY_WORKSPACE_FILE = `{${files.Client.NS_NEXTCLOUD}}rich-workspace-file`
const PROPERTY_WORKSPACE = `{${files.Client.NS_NEXTCLOUD}}rich-workspace`
const properties = [
...files.getClient().getPropfindProperties(),
PROPERTY_WORKSPACE_FILE,
PROPERTY_WORKSPACE,
]
const client = files.getClient().getClient()
return client
.propFind(client.baseUrl + path, properties, depth)
.then((results) => {
cy.log(`Propfind returned ${results.status}`)
if (depth) {
return results.body
} else {
return results.body.propStat[0].properties
}
const rootPath = `${url}/remote.php/webdav/`
const requestPath = path === '/' ? rootPath : `${rootPath}${path}`

return axios
.request({
method: 'PROPFIND',
url: requestPath,
headers: {
Depth: depth,
'Content-Type': 'application/xml',
},
data: `<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:"
xmlns:oc="http://owncloud.org/ns"
xmlns:nc="http://nextcloud.org/ns">
<d:prop>
<nc:rich-workspace />
<nc:rich-workspace-file />
</d:prop>
</d:propfind>`,
})
.then((response) => {
const parser = new DOMParser()
const xmlDoc = parser.parseFromString(response.data, 'text/xml')
const responses = xmlDoc.querySelectorAll('d\\:response, response')
const results = Array.from(responses).map((resp) => {
const props = {}
const propStats = resp.querySelectorAll('d\\:propstat, propstat')
propStats.forEach((propStat) => {
const status =
propStat.querySelector('d\\:status, status')?.textContent

// Skip properties with 404 status ( not found)
if (status?.includes('404')) {
return
}

const propElements = resp.querySelectorAll(
'd\\:prop > *, prop > * ',
)

propElements.forEach((prop) => {
const tagName = prop.localName
const namespace = prop.namespaceURI

let key = tagName
if (namespace === 'http://nextcloud.org/ns') {
key = `nc:${tagName}`
} else if (namespace === 'http://owncloud.org/ns') {
key = `oc:${tagName}`
}

props[key] = prop.textContent || ''
})
})
return props
})
})

return depth > 0 ? results : results[0] || {}
})
})

Cypress.Commands.add('reloadFileList', () => {
Expand Down
Loading
Loading