Skip to content

Commit

Permalink
tests(cy): use @nextcloud/cypress login and logout
Browse files Browse the repository at this point in the history
They authenticate using the API rather than the UI.
This is much faster.

Visiting the desired url then happens separately.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Oct 22, 2023
1 parent 6309c05 commit fd1b31d
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 74 deletions.
10 changes: 6 additions & 4 deletions cypress/e2e/apps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe('The apps', function() {
describe('Collectives', function() {

it('allows creating a new collective', function() {
cy.login('jane')
cy.loginAs('jane')
cy.visit('apps/collectives')
cy.get('#app-navigation-vue')
.should('contain', 'New collective')
})
Expand All @@ -40,17 +41,18 @@ describe('The apps', function() {
describe('Disabled circles app does not break files view', function() {

before(function() {
cy.login('admin', { route: '/' })
cy.loginAs('admin')
cy.disableApp('circles')
})

after(function() {
cy.login('admin', { route: '/' })
cy.loginAs('admin')
cy.enableApp('circles')
})

it('Renders the default files list', function() {
cy.login('jane', { route: 'apps/files' })
cy.loginAs('jane')
cy.visit('apps/files')
cy.fileList().should('contain', 'welcome')
})

Expand Down
10 changes: 4 additions & 6 deletions cypress/e2e/circle-with-group.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@
*/
describe('Pages are accessible via group membership to circle', function() {
before(function() {
cy.login('jane')
cy.loginAs('jane')
cy.visit('apps/collectives')
cy.deleteAndSeedCollective('Group Collective')
cy.seedCircleMember('Group Collective', 'Bobs Group', 2, 8)
cy.logout()
cy.clearCookies()
cy.getCookies().should('be.empty')
})

it('Lists the collective', function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.get('.app-navigation').contains('Group Collective').click()
cy.get('#text h1').should('contain', 'Welcome to your new collective')
cy.logout()
})
})
6 changes: 4 additions & 2 deletions cypress/e2e/collective-members.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@

describe('Collective members', function() {
before(function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.deleteCollective('Members Collective')
cy.deleteAndSeedCollective('Members Collective')
})

beforeEach(function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.openCollectiveMenu('Members Collective')
cy.clickMenuButton('Manage members')
})
Expand Down
7 changes: 4 additions & 3 deletions cypress/e2e/collective-readonly.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@
describe('Read-only collective', function() {

before(function() {
cy.login('alice')
cy.loginAs('alice')
cy.visit('apps/collectives')
cy.deleteAndSeedCollective('PermissionCollective')
cy.seedPage('SecondPage', '', 'Readme.md')
cy.seedCollectivePermissions('PermissionCollective', 'edit', 4)
cy.seedCircleMember('PermissionCollective', 'bob')
cy.logout()
})

describe('in read-only collective', function() {
beforeEach(function() {
cy.login('bob', { route: '/apps/collectives/PermissionCollective/SecondPage' })
cy.loginAs('bob')
cy.visit('/apps/collectives/PermissionCollective/SecondPage')
})

it('not able to edit collective', function() {
Expand Down
6 changes: 4 additions & 2 deletions cypress/e2e/collective-settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@

describe('Collective settings', function() {
before(function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.deleteCollective('Change me now')
cy.deleteAndSeedCollective('Change me')
})

beforeEach(function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
})

describe('set emoji', function() {
Expand Down
11 changes: 7 additions & 4 deletions cypress/e2e/collective-share.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ describe('Collective Share', function() {
let shareUrl

before(function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('/apps/collectives')
cy.deleteAndSeedCollective('Share me')
})

describe('collective share', function() {
it('Allows sharing a collective', function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('/apps/collectives', {
onBeforeLoad(win) {
// navigator.clipboard doesn't exist on HTTP requests (in CI), so let's create it
Expand Down Expand Up @@ -80,7 +81,8 @@ describe('Collective Share', function() {
cy.getEditor().should('not.exist')
})
it('Allows toggling the editable flag for a collective share', function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.openCollectiveMenu('Share me')
cy.intercept('PUT', '**/_api/*/share/*').as('updateShare')
cy.get('input#shareEditable')
Expand Down Expand Up @@ -113,7 +115,8 @@ describe('Collective Share', function() {
.click()
})
it('Allows unsharing a collective', function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.openCollectiveMenu('Share me')
cy.intercept('DELETE', '**/_api/*/share/*').as('deleteShare')
cy.clickMenuButton('Unshare')
Expand Down
35 changes: 23 additions & 12 deletions cypress/e2e/collective.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,25 @@ describe('Collective', function() {
const specialCollective = 'stupid !@#$%^&()_ special chars'

before(function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.deleteCollective('Preexisting Circle')
cy.deleteCollective('History Club')
cy.deleteCollective(specialCollective)
cy.deleteAndSeedCollective('Preexisting Collective')
cy.seedCircleMember('Preexisting Collective', 'jane')
cy.seedCircle('Preexisting Circle')
cy.seedCircle('History Club', { visible: true, open: true })
cy.login('jane')
cy.loginAs('jane')
cy.visit('apps/collectives')
cy.deleteCollective('Foreign Circle')
cy.seedCircle('Foreign Circle', { visible: true, open: true })
})

describe('in the files app', function() {
before(function() {
cy.login('bob', { route: '/apps/files' })
cy.loginAs('bob')
cy.visit('/apps/files')
})
it('has a matching folder', function() {
const breadcrumbsSelector = '.files-controls .breadcrumb, [data-cy-files-content-breadcrumbs] a'
Expand All @@ -60,20 +63,23 @@ describe('Collective', function() {

describe('name conflicts', function() {
it('Reports existing circle', function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.createCollective('Foreign Circle')
cy.get('.modal-collective-name-error').should('contain', 'A collective with this name already exists')
})
it('Reports existing collective', function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.createCollective('Preexisting Collective')
cy.get('main .empty-content').should('contain', 'build shared knowledge')
cy.get('.toast-warning').should('contain', 'Could not create the collective')
cy.get('.toast-warning').should('contain', 'Collective already exists')
})
it('creates collectives by picking circle',
function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.get('button').contains('New collective').click()
cy.get('button span.circles-icon').click()
// cy.get('.circle-selector ul').should('not.contain', 'Foreign')
Expand All @@ -88,12 +94,14 @@ describe('Collective', function() {
})
it('collectives of visible circles only show for members',
function() {
cy.login('jane')
cy.loginAs('jane')
cy.visit('apps/collectives')
cy.get('.app-navigation-entry').should('not.contain', 'History Club')
})
it('creates collectives for admins of corresponding circle',
function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.createCollective('Preexisting Circle')
cy.get('#titleform input').invoke('val').should('contain', 'Preexisting Circle')
cy.get('.toast-info').should('contain',
Expand All @@ -109,7 +117,8 @@ describe('Collective', function() {
describe('non ascii characters', function() {
it('can handle special chars in collective name',
function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.createCollective(specialCollective)
cy.get('#titleform input').invoke('val').should('contain', specialCollective)
})
Expand All @@ -127,7 +136,8 @@ describe('Collective', function() {
describe('after creation', function() {
const randomName = 'Created just now ' + Math.random().toString(36).substr(2, 4)
it('has all the ui elements', function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.createCollective(randomName, ['jane', 'john'])
cy.log('Check name in the disabled titleform')
cy.get('#titleform input').invoke('val').should('contain', randomName)
Expand All @@ -146,7 +156,7 @@ describe('Collective', function() {

describe('in non-admin collective', function() {
it('can leave collective and undo', function() {
cy.login('jane')
cy.loginAs('jane')
cy.visit('/apps/collectives')

// Leave collective
Expand Down Expand Up @@ -184,7 +194,8 @@ describe('Collective', function() {

describe('reloading works', function() {
before(function() {
cy.login('bob', { route: '/apps/collectives/Preexisting%20Collective' })
cy.loginAs('bob')
cy.visit('/apps/collectives/Preexisting%20Collective')
cy.get('#titleform input').should('have.value', 'Preexisting Collective')
})
it('Shows the name in the disabled titleform', function() {
Expand Down
12 changes: 8 additions & 4 deletions cypress/e2e/collectives-trash.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
describe('Collective', function() {
describe('move collective to trash and restore', function() {
before(function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.deleteAndSeedCollective('Delete me')
})
it('Allows moving the collective to trash', function() {
Expand All @@ -43,7 +44,8 @@ describe('Collective', function() {
.should('contain', 'Delete me')
})
it('Allows restoring the collective from trash', function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.get('#collectives-trash')
.click()
cy.openTrashedCollectiveMenu('Delete me')
Expand All @@ -55,7 +57,8 @@ describe('Collective', function() {

describe('move collective to trash and delete permanently', function() {
it('Allows moving the collective to trash', function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.openCollectiveMenu('Delete me')
cy.clickMenuButton('Settings')
cy.get('button')
Expand All @@ -67,7 +70,8 @@ describe('Collective', function() {
.should('contain', 'Delete me')
})
it('Allows deleting the collective and circle from trash', function() {
cy.login('bob')
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.get('#collectives-trash')
.click()
cy.openTrashedCollectiveMenu('Delete me')
Expand Down
6 changes: 4 additions & 2 deletions cypress/e2e/page-details.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

describe('Page details', function() {
before(function() {
cy.login('bob', { route: '/apps/collectives' })
cy.loginAs('bob')
cy.visit('/apps/collectives')
cy.deleteAndSeedCollective('Our Garden')
cy.seedPage('Day 1', '', 'Readme.md')
cy.seedPageContent('Our Garden/Day 2.md', 'A test string with Day 2 in the middle and a [link to Day 1](/index.php/apps/collectives/Our%20Garden/Day%201).')
Expand All @@ -35,7 +36,8 @@ describe('Page details', function() {
})

beforeEach(function() {
cy.login('bob', { route: '/apps/collectives/Our Garden' })
cy.loginAs('bob')
cy.visit('/apps/collectives/Our Garden')
// make sure the page list loaded properly
cy.contains('.app-content-list-item a', 'Day 1')
})
Expand Down
9 changes: 6 additions & 3 deletions cypress/e2e/page-landingpage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const collective = 'Landingpage Collective'

describe('Page landing page', function() {
before(function() {
cy.login('bob', { route: '/apps/collectives' })
cy.loginAs('bob')
cy.visit('/apps/collectives')
cy.deleteAndSeedCollective(collective)
cy.seedCircleMember(collective, 'alice')
cy.seedCircleMember(collective, 'jane')
Expand All @@ -39,7 +40,8 @@ describe('Page landing page', function() {
})

beforeEach(function() {
cy.login('bob', { route: `/apps/collectives/${collective}` })
cy.loginAs('bob')
cy.visit(`/apps/collectives/${collective}`)
// make sure the page list loaded properly
cy.contains('.app-content-list-item a', 'Page 1')
})
Expand Down Expand Up @@ -85,7 +87,8 @@ describe('Page landing page', function() {
})

it('Allows to open members modal as member', function() {
cy.login('alice', { route: `/apps/collectives/${collective}` })
cy.loginAs('alice')
cy.visit(`/apps/collectives/${collective}`)
cy.get('.members-widget .avatardiv[title="bob"]')
cy.get('.members-widget .button-vue[title="Show members"]')
.click()
Expand Down
10 changes: 6 additions & 4 deletions cypress/e2e/page-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

describe('Page list', function() {
before(function() {
cy.login('bob', { route: '/apps/collectives' })
cy.loginAs('bob')
cy.visit('apps/collectives')
cy.deleteAndSeedCollective('Our Garden')
cy.seedPage('Day 1', '', 'Readme.md')
// Wait 1 second to make sure that page order by time is right
Expand All @@ -38,7 +39,8 @@ describe('Page list', function() {
})

beforeEach(function() {
cy.login('bob', { route: '/apps/collectives/Our Garden' })
cy.loginAs('bob')
cy.visit('apps/collectives/Our Garden')
// make sure the page list loaded properly
cy.contains('.app-content-list-item a', 'Day 1')
})
Expand Down Expand Up @@ -86,7 +88,7 @@ describe('Page list', function() {
cy.seedPage('Move me', '', 'Readme.md')
cy.seedPage('Target', '', 'Readme.md')
cy.seedPage('Target Subpage', '', 'Target.md')
cy.visit('/apps/collectives/Our%20Garden')
cy.visit('apps/collectives/Our%20Garden')
cy.openPageMenu('Move me')
cy.clickMenuButton('Move page')
cy.get('.picker-page-list li')
Expand Down Expand Up @@ -127,7 +129,7 @@ describe('Page list', function() {
describe('Print view', function() {
it('renders all the pages', function() {
let printStub
cy.visit('/apps/collectives/_/print/Our%20Garden', {
cy.visit('apps/collectives/_/print/Our%20Garden', {
onBeforeLoad: (win) => {
printStub = cy.stub(win, 'print').as('print')
},
Expand Down
Loading

0 comments on commit fd1b31d

Please sign in to comment.