From d771d1f51aefe3b803f4c15c9b992e1fb1b5d98b Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 13 Dec 2023 13:04:02 +0100 Subject: [PATCH] test(cypress): Adjust sharing tests to new UI and add page share tests Signed-off-by: Jonas --- cypress/e2e/collective-share.spec.js | 140 ++++++++++++++++++++++----- cypress/e2e/pages-links.spec.js | 16 +-- 2 files changed, 127 insertions(+), 29 deletions(-) diff --git a/cypress/e2e/collective-share.spec.js b/cypress/e2e/collective-share.spec.js index bb05251179..0e23dc8053 100644 --- a/cypress/e2e/collective-share.spec.js +++ b/cypress/e2e/collective-share.spec.js @@ -31,6 +31,9 @@ describe('Collective Share', function() { cy.loginAs('bob') cy.visit('/apps/collectives') cy.deleteAndSeedCollective('Share me') + cy.seedPage('Sharepage', '', 'Readme.md') + cy.seedPageContent('Sharepage.md', '## Shared page') + cy.seedPage('Sharesubpage', '', 'Sharepage.md') }) describe('collective share', function() { @@ -54,19 +57,17 @@ describe('Collective Share', function() { }, }) cy.openCollectiveMenu('Share me') + cy.clickMenuButton('Manage share links') cy.intercept('POST', '**/_api/*/share').as('createShare') - cy.clickMenuButton('Share link') + cy.get('.sharing-entry button.new-share-link') + .click() cy.wait('@createShare') - cy.get('div.open ul') - .contains('Share link').should('not.be.visible') - cy.get('div.open ul') - .contains('Copy share link').should('be.visible') - cy.get('div.open ul') - .contains('Unshare').should('be.visible') - cy.get('button') - .contains('Copy share link') + cy.get('.toast-success').should('contain', 'Collective "Share me" has been shared') + cy.get('.sharing-entry .share-select') + .should('contain', 'View only') + cy.get('button.sharing-entry__copy') .click() - cy.get('.toast-success').should('contain', 'Link copied to the clipboard.') + cy.get('.toast-success').should('contain', 'Link copied') cy.get('@clipBoardWriteText').should('have.been.calledOnce') }) it('Allows opening a shared (non-editable) collective', function() { @@ -81,16 +82,21 @@ describe('Collective Share', function() { .should('not.exist') cy.getEditor().should('not.exist') }) - it('Allows toggling the editable flag for a collective share', function() { + it('Allows setting a collective share to editable', function() { cy.loginAs('bob') cy.visit('apps/collectives') cy.openCollectiveMenu('Share me') + cy.clickMenuButton('Manage share links') + cy.get('.sharing-entry .share-select') + .click() cy.intercept('PUT', '**/_api/*/share/*').as('updateShare') - cy.get('input#shareEditable') - .check({ force: true }) + cy.get('.sharing-entry .share-select .dropdown-item') + .contains('Can edit') + .click() cy.wait('@updateShare') - cy.get('input#shareEditable') - .should('be.checked') + cy.get('.toast-success').should('contain', 'Share link of collective "Share me" has been updated') + cy.get('.sharing-entry .share-select') + .should('contain', 'Can edit') }) it('Allows opening and editing a shared (editable) collective', function() { cy.logout() @@ -123,15 +129,14 @@ describe('Collective Share', function() { cy.loginAs('bob') cy.visit('apps/collectives') cy.openCollectiveMenu('Share me') + cy.clickMenuButton('Manage share links') + cy.get('.sharing-entry__actions') + .click() cy.intercept('DELETE', '**/_api/*/share/*').as('deleteShare') - cy.clickMenuButton('Unshare') + cy.get('.unshare-button') + .click() cy.wait('@deleteShare') - cy.get('div.open ul') - .contains('Share link').should('be.visible') - cy.get('div.open ul') - .contains('Copy share link').should('not.be.visible') - cy.get('div.open ul') - .contains('Unshare').should('not.be.visible') + cy.get('.toast-success').should('contain', 'Collective "Share me" has been unshared') }) it('Opening unshared collective fails', function() { cy.logout() @@ -139,4 +144,95 @@ describe('Collective Share', function() { cy.get('.body-login-container').contains(/(File|Page) not found/) }) }) + + describe('page share', function() { + it('Allows sharing a page', function() { + cy.loginAs('bob') + cy.visit('/apps/collectives', { + onBeforeLoad(win) { + // navigator.clipboard doesn't exist on HTTP requests (in CI), so let's create it + if (!win.navigator.clipboard) { + win.navigator.clipboard = { + __proto__: { + writeText: () => {}, + }, + } + } + // overwrite navigator.clipboard.writeText with cypress stub + cy.stub(win.navigator.clipboard, 'writeText', (text) => { + shareUrl = text + }) + .as('clipBoardWriteText') + }, + }) + cy.openCollective('Share me') + cy.openPage('Sharepage') + cy.get('button.action-item .icon-menu-sidebar').click() + cy.get('a#sharing').click() + cy.intercept('POST', '**/_api/*/_pages/*/share').as('createShare') + cy.get('.sharing-entry button.new-share-link') + .click() + cy.wait('@createShare') + cy.get('.toast-success').should('contain', 'Page "Sharepage" has been shared') + cy.get('.sharing-entry .share-select') + .should('contain', 'View only') + cy.get('button.sharing-entry__copy') + .click() + cy.get('.toast-success').should('contain', 'Link copied') + cy.get('@clipBoardWriteText').should('have.been.calledOnce') + }) + it('Allows opening a shared (non-editable) page', function() { + cy.logout() + cy.visit(shareUrl) + cy.get('#titleform input').should('have.value', 'Sharepage') + cy.get('button.titleform-button').should('not.exist') + cy.getReadOnlyEditor() + .should('be.visible') + .find('h2').should('contain', 'Shared page') + cy.get('.app-content-list-item.toplevel') + .should('contain', 'Sharepage') + cy.get('.app-content-list-item.toplevel') + .find('button.icon.add') + .should('not.exist') + cy.getEditor().should('not.exist') + }) + it('Allows setting a page share to editable', function() { + cy.loginAs('bob') + cy.visit('/apps/collectives') + cy.openCollective('Share me') + cy.openPage('Sharepage') + cy.get('button.action-item .icon-menu-sidebar').click() + cy.get('a#sharing').click() + cy.get('.sharing-entry .share-select') + .click() + cy.intercept('PUT', '**/_api/*/_pages/*/share/*').as('updateShare') + cy.get('.sharing-entry .share-select .dropdown-item') + .contains('Can edit') + .click() + cy.wait('@updateShare') + cy.get('.toast-success').should('contain', 'Share link of page "Sharepage" has been updated') + cy.get('.sharing-entry .share-select') + .should('contain', 'Can edit') + }) + it('Allows unsharing a page', function() { + cy.loginAs('bob') + cy.visit('/apps/collectives') + cy.openCollective('Share me') + cy.openPage('Sharepage') + cy.get('button.action-item .icon-menu-sidebar').click() + cy.get('a#sharing').click() + cy.get('.sharing-entry__actions') + .click() + cy.intercept('DELETE', '**/_api/*/_pages/*/share/*').as('deleteShare') + cy.get('.unshare-button') + .click() + cy.wait('@deleteShare') + cy.get('.toast-success').should('contain', 'Page "Sharepage" has been unshared') + }) + it('Opening unshared page fails', function() { + cy.logout() + cy.visit(shareUrl, { failOnStatusCode: false }) + cy.get('.body-login-container').contains(/(File|Page) not found/) + }) + }) }) diff --git a/cypress/e2e/pages-links.spec.js b/cypress/e2e/pages-links.spec.js index f00b22a4c4..1e6ff1c5a6 100644 --- a/cypress/e2e/pages-links.spec.js +++ b/cypress/e2e/pages-links.spec.js @@ -342,17 +342,19 @@ describe('Page Link Handling', function() { }, }) cy.openCollectiveMenu('Link Testing') + cy.clickMenuButton('Manage share links') cy.intercept('POST', '**/_api/*/share').as('createShare') - cy.clickMenuButton('Share link') + cy.get('.sharing-entry button.new-share-link') + .click() cy.wait('@createShare') + cy.get('.sharing-entry .share-select') + .click() cy.intercept('PUT', '**/_api/*/share/*').as('updateShare') - cy.get('input#shareEditable') - .check({ force: true }) + cy.get('.sharing-entry .share-select .dropdown-item') + .contains('Can edit') + .click() cy.wait('@updateShare') - cy.get('input#shareEditable') - .should('be.checked') - cy.get('button') - .contains('Copy share link') + cy.get('button.sharing-entry__copy') .click() cy.get('@clipBoardWriteText').should('have.been.calledOnce') })