Skip to content

Commit

Permalink
Cypress replaced wait with assertions (#5998)
Browse files Browse the repository at this point in the history
  • Loading branch information
ichim-david authored May 6, 2024
1 parent 0307e86 commit 46569c4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
22 changes: 16 additions & 6 deletions packages/volto/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,10 @@ Cypress.Commands.add('clearSlate', (selector) => {
return cy
.get(selector)
.focus()
.click({ force: true }) // fix sporadic failure this element is currently animating
.wait(1000)
.type('{selectAll}')
.wait(1000)
.type('{backspace}');
.click({ force: true })
.type('{selectAll}', { delay: 20 })
.type('{backspace}', { delay: 20 })
.wait(200);
});

Cypress.Commands.add('getSlate', (createNewSlate = false) => {
Expand Down Expand Up @@ -784,6 +783,15 @@ Cypress.Commands.add('typeInSlate', { prevSubject: true }, (subject, text) => {
);
});

Cypress.Commands.add(
'typeWithDelay',
{ prevSubject: 'element' },
(subject, text, options) => {
const delay = options && options.delay ? options.delay : 20;
cy.wrap(subject).type(text, { delay });
},
);

Cypress.Commands.add('lineBreakInSlate', { prevSubject: true }, (subject) => {
return (
cy
Expand Down Expand Up @@ -873,7 +881,9 @@ Cypress.Commands.add('addNewBlock', (blockName, createNewSlate = false) => {
});

Cypress.Commands.add('navigate', (route = '') => {
return cy.window().its('appHistory').invoke('push', route);
cy.intercept('GET', '**/*').as('navGetCall');
cy.window().its('appHistory').invoke('push', route);
cy.wait('@navGetCall');
});

Cypress.Commands.add('store', () => {
Expand Down
14 changes: 6 additions & 8 deletions packages/volto/cypress/tests/core/basic/locking.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,16 @@ describe('Document locking', () => {

cy.visit('/logout');
cy.wait('@logout');
cy.findByRole('alert')
.get('.toast-inner-content')
.should('contain', 'You have been logged out');
cy.get('.toast-dismiss-action').click();

// As another editor I can see the locked document
cy.autologin('editor2', 'password');
cy.visit('/document');
cy.wait('@content');

cy.findByRole('alert')
.get('.toast-inner-content')
.contains('This item was locked by Editor 1 on');
cy.get('.toolbar-body').should('be.visible');

// As another editor I can unlock the document
cy.findByLabelText('Unlock').click();
Expand All @@ -114,14 +115,11 @@ describe('Document locking', () => {
cy.findByLabelText('Edit').click();

// As another editor I can edit the document
cy.clearSlateTitle().type('New title by Editor 2');
cy.clearSlateTitle().typeWithDelay('New title by Editor 2');
cy.get('#toolbar-save').click();
// cy.waitForResourceToLoad('document');
cy.wait('@saveDoc');
cy.wait('@getDoc');

// cy.pause();

cy.url().should('eq', Cypress.config().baseUrl + '/document');
cy.contains('New title by Editor 2');
cy.get('h1.documentFirstHeading').should('not.be.empty');
Expand Down
32 changes: 18 additions & 14 deletions packages/volto/cypress/tests/core/blocks/listing/blocks-listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -1077,38 +1077,42 @@ describe('Listing Block Tests', () => {
cy.wait('@save');
cy.wait('@content');

// The wait is needed to solve the flakyness introduced because that component
// is removed momentarilly from the DOM when saving
cy.wait(1000);
//test second pagination click
cy.get('.ui.pagination.menu a[value="2"]').first().click();
cy.get('.ui.pagination.menu a[value="2"]')
.first()
.should('be.visible')
.click();
//test f5
cy.reload();
cy.isInHTML({ parent: '.listing-item', content: 'My Folder 3' });
cy.url().should('include', '=2');
// const listing2 = cy.get('.ui.pagination.menu').last();
//test third pagination click on second listing
cy.get('.ui.pagination.menu a[value="3"]').first().click();
cy.get('.ui.pagination.menu a[value="3"]')
.first()
.should('be.visible')
.click();
//test f5
cy.reload();
cy.isInHTML({ parent: '.listing-item', content: 'My Folder 3' });
cy.url().should('include', '=2');
cy.url().should('include', '=3');
//on logo click go to home page and remove ?page=2 from path
cy.get('.logo').first().click();
cy.get('.logo').first().should('be.visible').click();
cy.url().should('not.include', '=2');
cy.url().should('not.include', '=3');

// we need to wait for the page to load otherwise we navigate /my-page
// followed by / from the logo click
cy.wait(1000);

cy.navigate('/my-page');
cy.wait(1000);
cy.get('.ui.pagination.menu a[value="2"]').first().click({ force: true });
cy.get('.ui.pagination.menu a[value="3"]').first().click({ force: true });
cy.get('.ui.pagination.menu a[value="2"]')
.first()
.should('be.visible')
.click({ force: true });
cy.get('.ui.pagination.menu a[value="3"]')
.first()
.should('be.visible')
.click({ force: true });
cy.go(-1);
cy.wait(1000);
cy.wait('@content');
cy.isInHTML({ parent: '.listing-item', content: 'My Folder 3' });
cy.url().should('not.include', '=3');
cy.go(-1);
Expand Down
3 changes: 3 additions & 0 deletions packages/volto/news/5998.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Modified `locking` and `block-listing` cypress tests
to use more `assertions` instead of wait times in order to improve
the reliability of the tests. @ichim-david

0 comments on commit 46569c4

Please sign in to comment.