Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
cy: use API request to share rather than UI.
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Aug 31, 2022
commit f3d2383e38a2b29b19f4e8fc4bdfab5884cdbce4
63 changes: 18 additions & 45 deletions cypress/e2e/share.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,11 @@ describe('Open test.md in viewer', function() {
})

it('Shares the file as a public read only link', function() {
cy.visit('/apps/files')
cy.get('.files-fileList tr[data-file="test.md"] a.action-share')
.click({ force: true })
cy.get('#app-sidebar-vue')
.should('be.visible')
cy.get('#app-sidebar-vue a#sharing').trigger('click')
cy.get('#app-sidebar-vue button.new-share-link').trigger('click')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => cy.visit(href))
cy.shareFile('/test.md')
.then((token) => {
cy.logout()
cy.visit(`/s/${token}`)
})
.then(() => {
cy.getEditor().should('be.visible')
cy.getContent()
Expand All @@ -64,20 +59,10 @@ describe('Open test.md in viewer', function() {
})

it('Shares the file as a public link with write permissions', function() {
cy.visit('/apps/files')
cy.get('.files-fileList tr[data-file="test2.md"] a.action-share')
.click({ force: true })
cy.get('#app-sidebar-vue')
.should('be.visible')
cy.get('#app-sidebar-vue a#sharing').trigger('click')
cy.get('#app-sidebar-vue button.new-share-link').trigger('click')
cy.get('#app-sidebar-vue .sharing-link-list .action-item__menutoggle').trigger('click')
const checkboxAllowEditing = '.popover.open input[type=checkbox]'
cy.get(checkboxAllowEditing).first().check({ force: true })
cy.get(checkboxAllowEditing).first().should('be.checked')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => cy.visit(href))
cy.shareFile('/test2.md', { edit: true })
.then((token) => {
cy.visit(`/s/${token}`)
})
.then(() => {
cy.getEditor().should('be.visible')
cy.getContent()
Expand All @@ -92,17 +77,10 @@ describe('Open test.md in viewer', function() {
})

it('Opens the editor as guest', function() {
cy.visit('/apps/files')
cy.get('.files-fileList tr[data-file="test2.md"] a.action-share')
.click({ force: true })
cy.get('#app-sidebar-vue')
.should('be.visible')
cy.get('#app-sidebar-vue a#sharing').trigger('click')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => {
return cy.logout()
.then(() => cy.visit(href))
cy.shareFile('/test2.md', { edit: true })
.then((token) => {
cy.logout()
cy.visit(`/s/${token}`)
})
.then(() => {
cy.getEditor().should('be.visible')
Expand All @@ -118,16 +96,11 @@ describe('Open test.md in viewer', function() {
})

it('Shares a folder as a public read only link', function() {
cy.visit('/apps/files')
cy.get('.files-fileList tr[data-file="folder"] a.action-share')
.click({ force: true })
cy.get('#app-sidebar-vue')
.should('be.visible')
cy.get('#app-sidebar-vue a#sharing').trigger('click')
cy.get('#app-sidebar-vue button.new-share-link').trigger('click')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => cy.visit(href))
cy.shareFile('/folder')
.then((token) => {
cy.logout()
cy.visit(`/s/${token}`)
})
.then(() => {
cy.get('#rich-workspace').should('contain', 'Hello world')
cy.openFile('test.md')
Expand Down
34 changes: 34 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,40 @@ Cypress.Commands.add('shareFileToUser', (userId, password, path, targetUserId) =
})
})

Cypress.Commands.add('shareFile', (path, options = {}) => {
return cy.window().then(async window => {
try {
const headers = { requesttoken: window.OC.requestToken }
const request = await axios.post(
`${Cypress.env('baseUrl')}/ocs/v2.php/apps/files_sharing/api/v1/shares`,
{ path, shareType: window.OC.Share.SHARE_TYPE_LINK },
{ headers }
)
const token = request.data?.ocs?.data?.token
const id = request.data?.ocs?.data?.id
if (!token || !id || token.length === 0) {
throw request
}
cy.log(`Share link created: ${token}`)

if (options.edit) {
// Same permissions makeing the share editable in the UI would set
// 1 = read; 2 = write; 16 = share;
const permissions = 19
await axios.put(
`${Cypress.env('baseUrl')}/ocs/v2.php/apps/files_sharing/api/v1/shares/${id}`,
{ permissions },
{ headers }
)
cy.log(`Made share ${token} editable.`)
}
return cy.wrap(token)
} catch (error) {
console.error(error)
}
}).should('have.length', 15)
})

Cypress.Commands.add('createFolder', dirName => cy.window()
.then(win => win.OC.Files.getClient().createDirectory(dirName))
)
Expand Down