Skip to content

Commit

Permalink
test(cypress): Adjust sharing tests to new UI and add page share tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Dec 13, 2023
1 parent e1b379a commit 29d28d9
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 29 deletions.
140 changes: 118 additions & 22 deletions cypress/e2e/collective-share.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.seedPage('Sharesubpage', '', 'Sharepage.md')
cy.seedPageContent('Share%20me/Sharepage/Readme.md', '## Shared page')
})

describe('collective share', function() {
Expand All @@ -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() {
Expand All @@ -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()
Expand Down Expand Up @@ -123,20 +129,110 @@ 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()
cy.visit(shareUrl, { failOnStatusCode: false })
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/)
})
})
})
16 changes: 9 additions & 7 deletions cypress/e2e/pages-links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down

0 comments on commit 29d28d9

Please sign in to comment.