From 65c0203a94fed94dc63790ae35e0d0edd65956be Mon Sep 17 00:00:00 2001 From: sdrozdsap <163305268+sdrozdsap@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:32:56 +0100 Subject: [PATCH] test: Failing scroll-position-restoration spec (#18772) --- .../scroll-position-restoration.e2e.cy.ts | 53 +++++++++++++------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/scrolling/scroll-position-restoration.e2e.cy.ts b/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/scrolling/scroll-position-restoration.e2e.cy.ts index 5ba47e29db9..7572fa1d85b 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/scrolling/scroll-position-restoration.e2e.cy.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/scrolling/scroll-position-restoration.e2e.cy.ts @@ -6,28 +6,47 @@ context('scroll Position Restoration', () => { it('should restore scroll position', () => { + cy.intercept({ + method: 'GET', + pathname: `${Cypress.env('OCC_PREFIX')}/${Cypress.env( + 'BASE_SITE' + )}/cms/pages`, + query: { + pageType: 'ProductPage', + }, + }).as('getPage'); + cy.visit('/'); cy.log('Go to category page'); cy.get('cx-category-navigation a').eq(0).click(); cy.get('cx-product-list-item').should('exist'); - cy.get('cx-product-list-item').eq(3).scrollIntoView(); - cy.get('cx-product-list-item .cx-product-name').eq(3).click(); - - cy.log('Go to product details page'); - cy.get('.ProductDetailsPageTemplate').should('exist'); - cy.window().scrollTo('bottom'); - - cy.log('Go back to product list'); - cy.go(-1); - cy.window().its('scrollY').should('be.greaterThan', 0); - - cy.log('Go forward to product details'); - cy.go(1); - cy.get('.ProductDetailsPageTemplate').should('exist'); - cy.window().then(($window) => { - expect($window.scrollY).to.be.greaterThan(0); - }); + cy.get('cx-product-list-item .cx-product-name') + .eq(3) + .then(($productItem) => { + const productName = $productItem.text(); + cy.wrap($productItem).scrollIntoView().click(); + + cy.log('Go to product details page'); + verifyProductPageLoaded(productName); + cy.window().scrollTo('bottom'); + + cy.log('Go back to product list'); + cy.go(-1); + cy.window().its('scrollY').should('be.greaterThan', 0); + + cy.log('Go forward to product details'); + cy.go(1); + verifyProductPageLoaded(productName); + cy.window().then(($window) => { + expect($window.scrollY).to.be.greaterThan(0); + }); + }); }); }); + +const verifyProductPageLoaded = (productName: string) => { + cy.wait('@getPage').its('response.statusCode').should('eq', 200); + cy.get(`cx-breadcrumb h1`).should('contain', productName); +};