Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax <max@nextcloud.com>2022-08-31 12:18:32 +0300
committerMax <max@nextcloud.com>2022-08-31 17:42:10 +0300
commitf3d2383e38a2b29b19f4e8fc4bdfab5884cdbce4 (patch)
tree84b0b73143037fdf609cd0fdd87320ae3118a40f /cypress
parentba2c4934391debe36b43bad85fd36f1934875e63 (diff)
cy: use API request to share rather than UI.
Signed-off-by: Max <max@nextcloud.com>
Diffstat (limited to 'cypress')
-rw-r--r--cypress/e2e/share.spec.js63
-rw-r--r--cypress/support/commands.js34
2 files changed, 52 insertions, 45 deletions
diff --git a/cypress/e2e/share.spec.js b/cypress/e2e/share.spec.js
index 75e55d348..e8a8aefcf 100644
--- a/cypress/e2e/share.spec.js
+++ b/cypress/e2e/share.spec.js
@@ -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()
@@ -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()
@@ -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')
@@ -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')
diff --git a/cypress/support/commands.js b/cypress/support/commands.js
index fa5acc877..7076e4ef1 100644
--- a/cypress/support/commands.js
+++ b/cypress/support/commands.js
@@ -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))
)