diff --git a/cypress/e2e/apps.spec.js b/cypress/e2e/apps.spec.js index 5d9c1ea47..7acb0debf 100644 --- a/cypress/e2e/apps.spec.js +++ b/cypress/e2e/apps.spec.js @@ -50,9 +50,8 @@ describe('The apps', function() { }) it('Renders the default files list', function() { - const fileListSelector = '.files-fileList a, [data-cy-files-list-row] a' cy.login('jane', { route: 'apps/files' }) - cy.get(fileListSelector).should('contain', 'welcome') + cy.fileList().should('contain', 'welcome') }) }) diff --git a/cypress/e2e/collective.spec.js b/cypress/e2e/collective.spec.js index 74bc011f1..7d1922b8b 100644 --- a/cypress/e2e/collective.spec.js +++ b/cypress/e2e/collective.spec.js @@ -46,16 +46,13 @@ describe('Collective', function() { cy.login('bob', { route: '/apps/files' }) }) it('has a matching folder', function() { - const fileListSelector = '.files-fileList a, [data-cy-files-list-row] a' const breadcrumbsSelector = '.files-controls .breadcrumb, [data-cy-files-content-breadcrumbs] a' - cy.get(fileListSelector).should('contain', 'Collectives') - cy.get(fileListSelector).contains('Collectives').click() + cy.openFile('Collectives') cy.get(breadcrumbsSelector).should('contain', 'Collectives') - cy.get(fileListSelector).should('contain', 'Preexisting Collective') - cy.get(fileListSelector).contains('Preexisting Collective').click() + cy.openFile('Preexisting Collective') cy.get(breadcrumbsSelector).should('contain', 'Preexisting Collective') - cy.get(fileListSelector).should('contain', 'Readme') - cy.get(fileListSelector).should('contain', '.md') + cy.fileList().should('contain', 'Readme') + cy.fileList().should('contain', '.md') cy.get('.filelist-collectives-wrapper') .should('contain', 'The content of this folder is best viewed in the Collectives app.') }) diff --git a/cypress/e2e/settings.spec.js b/cypress/e2e/settings.spec.js index 2d71e54fb..75df67192 100644 --- a/cypress/e2e/settings.spec.js +++ b/cypress/e2e/settings.spec.js @@ -34,7 +34,6 @@ describe('Settings', function() { it('Allows changing the collective user folder', function() { const randomFolder = Math.random().toString(36).replace(/[^a-z]+/g, '').slice(0, 10) const filePickerListSelector = '#picker-filestable tr, .file-picker__row' - const fileListSelector = '.files-fileList a, [data-cy-files-list-row] a' const breadcrumbsSelector = '.files-controls .breadcrumb, [data-cy-files-content-breadcrumbs] a' cy.login('bob') @@ -68,9 +67,9 @@ describe('Settings', function() { // Check if collectives are found in new folder in Files app cy.log('Check if collectives are in configured user folder') cy.visit('/apps/files') - cy.get(fileListSelector).contains(randomFolder).click() + cy.openFile(randomFolder) cy.get(breadcrumbsSelector).should('contain', randomFolder) - cy.get(fileListSelector).should('contain', 'A Collective') + cy.fileList().should('contain', 'A Collective') // Change user folder back to default cy.log('Change user folder back to default') diff --git a/cypress/support/navigation.js b/cypress/support/navigation.js index c7e9b2668..6719f8ffd 100644 --- a/cypress/support/navigation.js +++ b/cypress/support/navigation.js @@ -36,3 +36,8 @@ Cypress.Commands.add('clickMenuButton', (title) => { .contains(title) .click() }) + +const FILE_LIST_SELECTOR = '.files-fileList a, [data-cy-files-list-row] a' +Cypress.Commands.add('fileList', () => cy.get(FILE_LIST_SELECTOR)) + +Cypress.Commands.add('openFile', (name) => cy.fileList().contains(name).click())