Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recommendation test fix #32

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/snap-preact-demo/templates/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let config: SnapTemplatesConfig = {
lazyRender: {
enabled: false,
},
speed: 0,
chrisFrazier77 marked this conversation as resolved.
Show resolved Hide resolved
},
recommendationBundle: {
lazyRender: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* the applicable tests will be skipped.
*
*/
Cypress.config('animationDistanceThreshold', 20);

const config = {
url: 'https://localhost:2222/templates/recommendations.html',
Expand Down Expand Up @@ -141,35 +142,40 @@ describe('Recommendations', () => {
it('renders carousel next buttons', function () {
cy.document().then((doc) => {
cy.snapController(integration?.selectors?.recommendation.controller).then(({ store }) => {
cy.get(integration?.selectors?.recommendation.nextArrow).should('exist');
cy.get(integration?.selectors?.recommendation.prevArrow).should('exist');

cy.get(integration?.selectors?.recommendation.activeSlide).should('exist');
// Wait for elements to be visible and interactable
cy.get(integration?.selectors?.recommendation.nextArrow).should('be.visible').should('not.be.disabled');
cy.get(integration?.selectors?.recommendation.prevArrow).should('be.visible');
cy.get(integration?.selectors?.recommendation.activeSlide).should('be.visible');

//get the initial active product
const intialActive = doc.querySelector(
// Get initial active product with retry
cy.get(
`${integration?.selectors?.recommendation.activeSlide} ${integration?.selectors?.recommendation.result} .ss__result__details__title a`
).innerHTML;
let newActive;
//click the next button
cy.get(integration?.selectors?.recommendation.nextArrow)
.click()
.then(($button) => {
//get the new active product
newActive = doc.querySelector(
`${integration?.selectors?.recommendation.activeSlide} ${integration?.selectors?.recommendation.result} .ss__result__details__title a`
).innerHTML;

//get the new active again
)
.should('be.visible')
.invoke('text')
.then((intialActive) => {
// Click next with force option
cy.get(integration?.selectors?.recommendation.nextArrow)
.click({ force: true })
.then(() => {
// Wait for slide transition
cy.wait(100); // Add small delay for slide transition

const newerActiveIndex = doc
.querySelector(`${integration?.selectors?.recommendation.activeSlide}`)
.getAttribute('data-swiper-slide-index');
const storeTitle = store.results[parseInt(newerActiveIndex)].mappings.core.name;
cy.get(
`${integration?.selectors?.recommendation.activeSlide} ${integration?.selectors?.recommendation.result} .ss__result__details__title a`
)
.should('be.visible')
.invoke('text')
.then((newActive) => {
const newerActiveIndex = doc
.querySelector(`${integration?.selectors?.recommendation.activeSlide}`)
.getAttribute('data-swiper-slide-index');
const storeTitle = store.results[parseInt(newerActiveIndex)].mappings.core.name;

//should have changed
expect(newActive).to.not.equal(intialActive);
expect(newActive).to.equal(storeTitle);
expect(newActive).to.not.equal(intialActive);
expect(newActive).to.equal(storeTitle);
});
});
});
});
});
Expand Down Expand Up @@ -253,4 +259,4 @@ describe('Recommendations', () => {
});
});
});
});
});
Loading