From e4ca2a1325a2392effe1a08427696e977ed97300 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 17 Oct 2023 13:50:04 +0200 Subject: [PATCH 1/5] test(cy): click on page instead of visit Navigate inside the collective instead of loading the entire page again. Original test run: 57 sec. After this commit: 42 sec. Signed-off-by: Max --- cypress/e2e/page-details.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/page-details.spec.js b/cypress/e2e/page-details.spec.js index 6a6660c09..40d56ce73 100644 --- a/cypress/e2e/page-details.spec.js +++ b/cypress/e2e/page-details.spec.js @@ -42,7 +42,7 @@ describe('Page details', function() { describe('Display table of contents', function() { it('Allows to display/close TOC and switch page modes in between', function() { - cy.visit('/apps/collectives/Our%20Garden/TableOfContents') + cy.contains('.app-content-list-item a', 'TableOfContents').click() cy.get('#titleform .action-item__menutoggle') .click() @@ -73,7 +73,7 @@ describe('Page details', function() { describe('Displaying backlinks', function() { it('Lists backlinks for a page', function() { cy.intercept('PUT', '**/apps/text/session/create').as('textCreateSession') - cy.visit('/apps/collectives/Our%20Garden/Day%201') + cy.contains('.app-content-list-item a', 'Day 1').click() cy.wait('@textCreateSession') cy.get('button.action-item .icon-menu-sidebar').click() cy.get('a#backlinks').click() From e6c20dba8b41efda31aef6b70607317d6db62b3a Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 17 Oct 2023 15:54:26 +0200 Subject: [PATCH 2/5] test(cy): introduce basic navigation actions Signed-off-by: Max --- cypress/e2e/collective-members.spec.js | 10 +--- cypress/e2e/collective-settings.spec.js | 65 ++++++------------------- cypress/e2e/collective-share.spec.js | 23 ++------- cypress/e2e/collective.spec.js | 18 ++----- cypress/e2e/collectives-trash.spec.js | 36 +++----------- cypress/e2e/page-details.spec.js | 4 +- cypress/e2e/page-list.spec.js | 23 +++------ cypress/e2e/pages-links.spec.js | 13 ++--- cypress/e2e/pages.spec.js | 14 +++--- cypress/support/e2e.js | 1 + cypress/support/navigation.js | 38 +++++++++++++++ 11 files changed, 94 insertions(+), 151 deletions(-) create mode 100644 cypress/support/navigation.js diff --git a/cypress/e2e/collective-members.spec.js b/cypress/e2e/collective-members.spec.js index 3f48d175a..c9bd0eadf 100644 --- a/cypress/e2e/collective-members.spec.js +++ b/cypress/e2e/collective-members.spec.js @@ -33,14 +33,8 @@ describe('Collective members', function() { beforeEach(function() { cy.login('bob') - - cy.get('.collectives_list_item') - .contains('li', 'Members Collective') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Manage members') - .click() + cy.openCollectiveMenu('Members Collective') + cy.clickMenuButton('Manage members') }) describe('Manage members', function() { diff --git a/cypress/e2e/collective-settings.spec.js b/cypress/e2e/collective-settings.spec.js index 4a8f6e1e4..51b43707d 100644 --- a/cypress/e2e/collective-settings.spec.js +++ b/cypress/e2e/collective-settings.spec.js @@ -37,14 +37,8 @@ describe('Collective settings', function() { describe('set emoji', function() { it('Allows setting an emoji', function() { - cy.visit('/apps/collectives') - cy.get('.collectives_list_item') - .contains('li', 'Change me') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Settings') - .click() + cy.openCollectiveMenu('Change me') + cy.clickMenuButton('Settings') cy.get('button.button-emoji') .click() cy.contains('.emoji-mart-scroll .emoji-mart-emoji', '🥰').click() @@ -55,13 +49,8 @@ describe('Collective settings', function() { .find('.app-navigation-entry-icon').should('contain', '🥰') // Unset emoji - cy.get('.collectives_list_item') - .contains('li', 'Change me') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Settings') - .click() + cy.openCollectiveMenu('Change me') + cy.clickMenuButton('Settings') cy.get('button.button-emoji') .click() cy.contains('.emoji-mart-emoji.emoji-selected', '🥰').click() @@ -75,13 +64,8 @@ describe('Collective settings', function() { describe('rename collective', function() { it('Allows to rename the collective', function() { - cy.get('.collectives_list_item') - .contains('li', 'Change me') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Settings') - .click() + cy.openCollectiveMenu('Change me') + cy.clickMenuButton('Settings') cy.get('div.collective-name input[type="text"]').type(' now{enter}') cy.reload() cy.get('.collectives_list_item') @@ -91,13 +75,8 @@ describe('Collective settings', function() { describe('change edit permissions', function() { it('Allows to change editing permissions', function() { - cy.get('.collectives_list_item') - .contains('li', 'Change me now') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Settings') - .click() + cy.openCollectiveMenu('Change me now') + cy.clickMenuButton('Settings') cy.get('div.permissions-input-edit > :first-child > .checkbox-radio-switch__label') .click() cy.get('div.toast-success').should('contain', 'Editing permissions updated') @@ -106,13 +85,8 @@ describe('Collective settings', function() { describe('change share permissions', function() { it('Allows to change sharing permissions', function() { - cy.get('.collectives_list_item') - .contains('li', 'Change me now') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Settings') - .click() + cy.openCollectiveMenu('Change me now') + cy.clickMenuButton('Settings') cy.get('div.permissions-input-share > :first-child > .checkbox-radio-switch__label') .click() cy.get('div.toast-success').should('contain', 'Sharing permissions updated') @@ -121,13 +95,8 @@ describe('Collective settings', function() { describe('change page mode', function() { it('Allows to change page mode', function() { - cy.get('.collectives_list_item') - .contains('li', 'Change me now') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Settings') - .click() + cy.openCollectiveMenu('Change me now') + cy.clickMenuButton('Settings') cy.get('a.navigation-list__link') .contains('Page settings') .click() @@ -139,13 +108,9 @@ describe('Collective settings', function() { describe('open settings from landing page actions', function() { it('Allows to open settings from landing page actions', function() { - cy.visit('/apps/collectives/Change%20me%20now') - cy.contains('.app-content-list-item', 'Change me now') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Settings') - .click() + cy.openCollective('Change me now') + cy.openPageMenu('Change me now') + cy.clickMenuButton('Settings') cy.get('div.permissions-input-edit') }) }) diff --git a/cypress/e2e/collective-share.spec.js b/cypress/e2e/collective-share.spec.js index 543eb360a..5197c043b 100644 --- a/cypress/e2e/collective-share.spec.js +++ b/cypress/e2e/collective-share.spec.js @@ -52,14 +52,9 @@ describe('Collective Share', function() { .as('clipBoardWriteText') }, }) - cy.get('.collectives_list_item') - .contains('li', 'Share me') - .find('.action-item__menutoggle') - .click({ force: true }) + cy.openCollectiveMenu('Share me') cy.intercept('POST', '**/_api/*/share').as('createShare') - cy.get('button') - .contains('Share link') - .click() + cy.clickMenuButton('Share link') cy.wait('@createShare') cy.get('div.open ul') .contains('Share link').should('not.be.visible') @@ -86,10 +81,7 @@ describe('Collective Share', function() { }) it('Allows toggling the editable flag for a collective share', function() { cy.login('bob') - cy.get('.collectives_list_item') - .contains('li', 'Share me') - .find('.action-item__menutoggle') - .click({ force: true }) + cy.openCollectiveMenu('Share me') cy.intercept('PUT', '**/_api/*/share/*').as('updateShare') cy.get('input#shareEditable') .check({ force: true }) @@ -122,14 +114,9 @@ describe('Collective Share', function() { }) it('Allows unsharing a collective', function() { cy.login('bob') - cy.get('.collectives_list_item') - .contains('li', 'Share me') - .find('.action-item__menutoggle') - .click({ force: true }) + cy.openCollectiveMenu('Share me') cy.intercept('DELETE', '**/_api/*/share/*').as('deleteShare') - cy.get('button') - .contains('Unshare') - .click() + cy.clickMenuButton('Unshare') cy.wait('@deleteShare') cy.get('div.open ul') .contains('Share link').should('be.visible') diff --git a/cypress/e2e/collective.spec.js b/cypress/e2e/collective.spec.js index c877a9070..74bc011f1 100644 --- a/cypress/e2e/collective.spec.js +++ b/cypress/e2e/collective.spec.js @@ -153,13 +153,8 @@ describe('Collective', function() { cy.visit('/apps/collectives') // Leave collective - cy.get('.collectives_list_item') - .contains('li', 'Preexisting Collective') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Leave collective') - .click() + cy.openCollectiveMenu('Preexisting Collective') + cy.clickMenuButton('Leave collective') cy.get('.app-navigation-entry') .contains('Preexisting Collective') .should('not.be.visible') @@ -176,14 +171,9 @@ describe('Collective', function() { .should('be.visible') // Leave collective and wait for 10 seconds - cy.get('.collectives_list_item') - .contains('li', 'Preexisting Collective') - .find('.action-item__menutoggle') - .click({ force: true }) + cy.openCollectiveMenu('Preexisting Collective') cy.intercept('PUT', '**/apps/circles/circles/**/leave').as('leaveCircle') - cy.get('button.action-button') - .contains('Leave collective') - .click() + cy.clickMenuButton('Leave collective') cy.get('.app-navigation-entry') .contains('Preexisting Collective') .should('not.be.visible') diff --git a/cypress/e2e/collectives-trash.spec.js b/cypress/e2e/collectives-trash.spec.js index bae773a63..4f9fea4f9 100644 --- a/cypress/e2e/collectives-trash.spec.js +++ b/cypress/e2e/collectives-trash.spec.js @@ -32,13 +32,8 @@ describe('Collective', function() { }) it('Allows moving the collective to trash', function() { cy.visit('/apps/collectives') - cy.get('.collectives_list_item') - .contains('li', 'Delete me') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Settings') - .click() + cy.openCollectiveMenu('Delete me') + cy.clickMenuButton('Settings') cy.get('button') .contains('Delete collective') .click() @@ -51,13 +46,8 @@ describe('Collective', function() { cy.login('bob') cy.get('#collectives-trash') .click() - cy.get('.collectives_trash_list_item') - .contains('li', 'Delete me') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button') - .contains('Restore') - .click() + cy.openTrashedCollectiveMenu('Delete me') + cy.clickMenuButton('Restore') cy.get('.collectives_list_item') .should('contain', 'Delete me') }) @@ -66,13 +56,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.get('.collectives_list_item') - .contains('li', 'Delete me') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Settings') - .click() + cy.openCollectiveMenu('Delete me') + cy.clickMenuButton('Settings') cy.get('button') .contains('Delete collective') .click() @@ -85,13 +70,8 @@ describe('Collective', function() { cy.login('bob') cy.get('#collectives-trash') .click() - cy.get('.collectives_trash_list_item') - .contains('li', 'Delete me') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button') - .contains('Delete permanently') - .click() + cy.openTrashedCollectiveMenu('Delete me') + cy.clickMenuButton('Delete permanently') cy.get('button') .contains('Collective and circle') .click() diff --git a/cypress/e2e/page-details.spec.js b/cypress/e2e/page-details.spec.js index 40d56ce73..1c9b34b5c 100644 --- a/cypress/e2e/page-details.spec.js +++ b/cypress/e2e/page-details.spec.js @@ -42,7 +42,7 @@ describe('Page details', function() { describe('Display table of contents', function() { it('Allows to display/close TOC and switch page modes in between', function() { - cy.contains('.app-content-list-item a', 'TableOfContents').click() + cy.openPage('TableOfContents') cy.get('#titleform .action-item__menutoggle') .click() @@ -73,7 +73,7 @@ describe('Page details', function() { describe('Displaying backlinks', function() { it('Lists backlinks for a page', function() { cy.intercept('PUT', '**/apps/text/session/create').as('textCreateSession') - cy.contains('.app-content-list-item a', 'Day 1').click() + cy.openPage('Day 1') cy.wait('@textCreateSession') cy.get('button.action-item .icon-menu-sidebar').click() cy.get('a#backlinks').click() diff --git a/cypress/e2e/page-list.spec.js b/cypress/e2e/page-list.spec.js index 5bff0b0e6..929345a7f 100644 --- a/cypress/e2e/page-list.spec.js +++ b/cypress/e2e/page-list.spec.js @@ -87,12 +87,8 @@ describe('Page list', function() { cy.seedPage('Target', '', 'Readme.md') cy.seedPage('Target Subpage', '', 'Target.md') cy.visit('/apps/collectives/Our%20Garden') - cy.contains('.app-content-list-item', 'Move me') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Move page') - .click() + cy.openPageMenu('Move me') + cy.clickMenuButton('Move page') cy.get('.picker-page-list li') .contains('Target') .click() @@ -102,7 +98,7 @@ describe('Page list', function() { .contains('Move page here') .click() - cy.visit('/apps/collectives/Our%20Garden/Target') + cy.openPage('Target') cy.contains('.page-list-drag-item', 'Target') .get('.page-list-indent .app-content-list-item') .first() @@ -149,7 +145,7 @@ describe('Page list', function() { describe('Page trash', function() { it('allows to trash and restore page with subpage and attachment', function() { - cy.visit('/apps/collectives/Our%20Garden/Day%201') + cy.openPage('Day 1') // Insert attachment cy.intercept({ method: 'POST', url: '**/text/attachment/upload*' }).as('attachmentUpload') @@ -159,12 +155,8 @@ describe('Page list', function() { cy.switchPageMode(0) // Trash page - cy.contains('.page-list .app-content-list-item', 'Day 1') - .find('.action-item__menutoggle') - .click({ force: true }) - cy.get('button.action-button') - .contains('Delete page and subpages') - .click() + cy.openPageMenu('Day 1') + cy.clickMenuButton('Delete page and subpages') cy.get('.page-list .app-content-list-item') .should('not.contain', 'Day 1') @@ -177,8 +169,9 @@ describe('Page list', function() { .click() cy.get('table tr') .should('not.exist') + cy.get('button.modal-container__close').click() - cy.visit('/apps/collectives/Our%20Garden/Day%201') + cy.openPage('Day 1') if (Cypress.env('ncVersion') === 'stable25') { cy.getEditor() .find('img.image__main') diff --git a/cypress/e2e/pages-links.spec.js b/cypress/e2e/pages-links.spec.js index 928f1049e..8e1db160c 100644 --- a/cypress/e2e/pages-links.spec.js +++ b/cypress/e2e/pages-links.spec.js @@ -265,7 +265,7 @@ describe('Page Link Handling', function() { } }) it('Opens link with relative path from index page to page in this collective with fileId in same/new tab depending on view/edit mode', function() { - cy.visit('/apps/collectives/Link%20Testing/Parent') + cy.openPage('Parent') // Link without origin and containing `fileId` param gets rewritten by editor rendering // const href = `../Link%20Target.md?fileId=${linkTargetPageId}` const href = `/index.php/apps/files/?dir=&openfile=${linkTargetPageId}#relPath=../Link%20Target.md` @@ -276,7 +276,7 @@ describe('Page Link Handling', function() { // testLinkToNewTab(href, { edit: true }) }) it('Opens link with relative path from landing page to page in this collective with fileId in same/new tab depending on view/edit mode', function() { - cy.visit('/apps/collectives/Link%20Testing') + cy.openPage('Link Testing') // Link without origin and containing `fileId` param gets rewritten by editor rendering // const href = `./Link%20Target?fileId=${linkTargetPageId}` const href = `/index.php/apps/files/?dir=/&openfile=${linkTargetPageId}#relPath=./Link%20Target` @@ -338,14 +338,9 @@ describe('Page Link Handling', function() { .as('clipBoardWriteText') }, }) - cy.get('.collectives_list_item') - .contains('li', 'Link Testing') - .find('.action-item__menutoggle') - .click({ force: true }) + cy.openCollectiveMenu('Link Testing') cy.intercept('POST', '**/_api/*/share').as('createShare') - cy.get('button') - .contains('Share link') - .click() + cy.clickMenuButton('Share link') cy.wait('@createShare') cy.intercept('PUT', '**/_api/*/share/*').as('updateShare') cy.get('input#shareEditable') diff --git a/cypress/e2e/pages.spec.js b/cypress/e2e/pages.spec.js index 9de75abbf..9c51f8478 100644 --- a/cypress/e2e/pages.spec.js +++ b/cypress/e2e/pages.spec.js @@ -55,7 +55,7 @@ describe('Page', function() { describe('Set page emoji', function() { it('Allows setting a page emoji from title bar', function() { - cy.visit('/apps/collectives/Our%20Garden/Day%201') + cy.openPage('Day 1') cy.get('#titleform .page-title-icon') .click() cy.contains('.emoji-mart-scroll .emoji-mart-emoji', '🥰').click() @@ -155,7 +155,7 @@ describe('Page', function() { describe('Editing a page', function() { it('Supports page content editing and switching to read mode', function() { - cy.visit('/apps/collectives/Our%20Garden/Day%201') + cy.openPage('Day 1') cy.log('Inserting an image') cy.intercept({ method: 'POST', url: '**/text/attachment/upload*' }).as('attachmentUpload') @@ -197,7 +197,7 @@ describe('Page', function() { .should('contain', 'admin') }) it('Lists attachments for the page and allows restore', function() { - cy.visit('/apps/collectives/Our%20Garden/Day%201') + cy.openPage('Day 1') // Switch to edit mode cy.switchPageMode(1) @@ -235,7 +235,7 @@ describe('Page', function() { if (Cypress.env('ncVersion') !== 'stable25') { describe('Using the reference picker', function() { it('Supports selecting a page from a collective', function() { - cy.visit('/apps/collectives/Our%20Garden/Page%20Title') + cy.openPage('Page Title') cy.getEditor() .should('be.visible') @@ -262,7 +262,7 @@ describe('Page', function() { describe('Changing page mode', function() { it('Opens edit mode per default', function() { cy.seedCollectivePageMode('Our Garden', 1) - cy.visit('/apps/collectives/Our%20Garden/Day%202') + cy.openPage('Day 2') cy.getEditor() .should('be.visible') cy.getReadOnlyEditor() @@ -271,7 +271,7 @@ describe('Page', function() { it('Opens view mode per default', function() { cy.seedCollectivePageMode('Our Garden', 0) - cy.visit('/apps/collectives/Our%20Garden/Day%202') + cy.openPage('Day 2') cy.getReadOnlyEditor() .should('be.visible') cy.getEditor() @@ -281,7 +281,7 @@ describe('Page', function() { describe('Full width view', function() { it('Allows to toggle persistent full-width view', function() { - cy.visit('/apps/collectives/Our%20Garden/Day%202') + cy.openPage('Day 2') cy.get('#titleform').should('have.css', 'max-width', '100%') cy.get('#read-only-editor').invoke('outerWidth').should('eq', 670) diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 73c0c67db..6f0dfcb4c 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -1,3 +1,4 @@ // This file is loaded before all e2e tests import './commands.js' +import './navigation.js' diff --git a/cypress/support/navigation.js b/cypress/support/navigation.js new file mode 100644 index 000000000..c7e9b2668 --- /dev/null +++ b/cypress/support/navigation.js @@ -0,0 +1,38 @@ +Cypress.Commands.add('openApp', (appName) => { + cy.get(`nav.app-menu li[data-app-id="${appName}"] a`).click() +}) + +Cypress.Commands.add('openPage', (pageName) => { + cy.contains('.app-content-list-item a', pageName).click() +}) + +Cypress.Commands.add('openPageMenu', (pageName) => { + cy.contains('.app-content-list-item', pageName) + .find('.action-item__menutoggle') + .click({ force: true }) +}) + +Cypress.Commands.add('openCollective', (collectiveName) => { + cy.get(`.collectives_list_item a[title="${collectiveName}"]`) + .click() +}) + +Cypress.Commands.add('openCollectiveMenu', (collectiveName) => { + cy.get('.collectives_list_item') + .contains('li', collectiveName) + .find('.action-item__menutoggle') + .click({ force: true }) +}) + +Cypress.Commands.add('openTrashedCollectiveMenu', (collectiveName) => { + cy.get('.collectives_trash_list_item') + .contains('li', collectiveName) + .find('.action-item__menutoggle') + .click({ force: true }) +}) + +Cypress.Commands.add('clickMenuButton', (title) => { + cy.get('button.action-button') + .contains(title) + .click() +}) From 1ff36552d1ffeb18d555b70315fb3e4ce7ebb5a9 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 21 Oct 2023 10:42:20 +0200 Subject: [PATCH 3/5] test(cy): use a precise selector for the default folder `A Collective` also contains the string `Collec`. Make sure to pick the toplevel folder rather than the mountpoint of `A Collective`. Signed-off-by: Max --- cypress/e2e/settings.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/e2e/settings.spec.js b/cypress/e2e/settings.spec.js index c9fea3fc8..2d71e54fb 100644 --- a/cypress/e2e/settings.spec.js +++ b/cypress/e2e/settings.spec.js @@ -87,7 +87,7 @@ describe('Settings', function() { cy.wait('@propfindFolder') // Open and select default folder - cy.get(filePickerListSelector).contains('Collec') + cy.get(filePickerListSelector).contains('Collectives') .click() cy.get('button').contains('Choose') .click() From 0c1dfcbe3d81e35f77a57d4c4b71e325a70befe8 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 21 Oct 2023 10:43:01 +0200 Subject: [PATCH 4/5] test(cy): introduce fileList and openFile commands Signed-off-by: Max --- cypress/e2e/apps.spec.js | 3 +-- cypress/e2e/collective.spec.js | 11 ++++------- cypress/e2e/settings.spec.js | 5 ++--- cypress/support/navigation.js | 5 +++++ 4 files changed, 12 insertions(+), 12 deletions(-) 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()) From 58fec0c47ee85939bd870daf2220068c8ca20d36 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 21 Oct 2023 11:10:53 +0200 Subject: [PATCH 5/5] test(cy): remove unnecessary visit Signed-off-by: Max --- cypress/support/commands.js | 1 - 1 file changed, 1 deletion(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 9d6c74cdd..c18c94209 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -293,7 +293,6 @@ Cypress.Commands.add('seedPageContent', (pagePath, content) => { */ Cypress.Commands.add('seedCircle', (name, config = null) => { cy.log(`Seeding circle ${name}`) - cy.visit('/apps/collectives') cy.window() .its('app') .then(async app => {