Skip to content

Commit

Permalink
Merge branch 'develop' into feature/CXSPA-6932
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhepS authored Apr 26, 2024
2 parents ca252fe + 65c0203 commit 0157214
Showing 1 changed file with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit 0157214

Please sign in to comment.