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

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 0 additions & 10 deletions packages/snap-preact-demo/templates/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ let config: SnapTemplatesConfig = {
style: globalStyles,
overrides: {
components: {
recommendation: {
lazyRender: {
enabled: false,
},
},
recommendationBundle: {
lazyRender: {
enabled: false,
},
},
noResults: {
templates: {
recommendation: {
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 @@ -52,36 +53,37 @@ describe('Recommendations', () => {
config.integrations.forEach((integration) => {
describe(`${integration.label}`, () => {
describe('Setup', () => {
cy.on('window:before:load', (win) => {
win.mergeSnapConfig = {
themes: {
custom: {
extends: 'bocachica',
overrides: {
components: {
recommendation: {
lazyRender: {
enabled: false,
it('has valid config', () => {
cy.wrap(config).its('url').should('have.length.at.least', 1);

cy.on('window:before:load', (win) => {
win.mergeSnapConfig = {
themes: {
custom: {
extends: 'bocachica',
overrides: {
components: {
recommendation: {
lazyRender: {
enabled: false,
},
speed: 0,
},
speed: 0,
},
},
},
},
},
recommendation: {
default: {
Default: {
component: 'Recommendation',
theme: 'custom',
recommendation: {
default: {
Default: {
component: 'Recommendation',
theme: 'custom',
},
},
},
},
};
});
};
});

it('has valid config', () => {
cy.wrap(config).its('url').should('have.length.at.least', 1);
cy.visit(config.url);
console.log(Cypress.browser);
});
Expand Down Expand Up @@ -141,35 +143,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');
// 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');

cy.get(integration?.selectors?.recommendation.activeSlide).should('exist');

//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 +260,4 @@ describe('Recommendations', () => {
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,35 @@ describe('BundledRecommendations', () => {
describe('Setup', () => {
it('has valid config', () => {
cy.wrap(config).its('url').should('have.length.at.least', 1);

cy.on('window:before:load', (win) => {
win.mergeSnapConfig = {
themes: {
custom: {
extends: 'bocachica',
overrides: {
components: {
recommendationBundle: {
lazyRender: {
enabled: false,
},
speed: 0,
},
},
},
},
},
recommendation: {
bundle: {
Bundle: {
component: 'RecommendationBundle',
theme: 'custom',
},
},
},
};
});

cy.visit(config.url);
console.log(Cypress.browser);
});
Expand Down Expand Up @@ -198,11 +227,27 @@ describe('BundledRecommendations', () => {

cy.on('window:before:load', (win) => {
win.mergeSnapConfig = {
themes: {
custom: {
extends: 'bocachica',
overrides: {
components: {
recommendationBundle: {
lazyRender: {
enabled: false,
},
speed: 0,
},
},
},
},
},
recommendation: {
bundle: {
Bundle: {
component: 'RecommendationBundle',
resultComponent: 'CustomResult',
theme: 'custom',
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('BundledRecommendations', () => {
lazyRender: {
enabled: false,
},
speed: 0,
},
},
},
Expand Down Expand Up @@ -135,11 +136,27 @@ describe('BundledRecommendations', () => {

cy.on('window:before:load', (win) => {
win.mergeSnapConfig = {
themes: {
custom: {
extends: 'bocachica',
overrides: {
components: {
recommendationBundle: {
lazyRender: {
enabled: false,
},
speed: 0,
},
},
},
},
},
recommendation: {
bundle: {
Bundle: {
component: 'RecommendationBundleEasyAdd',
resultComponent: 'CustomResult',
theme: 'custom',
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,26 @@ describe('BundledRecommendations', () => {
cy.wrap(config).its('url').should('have.length.at.least', 1);
cy.on('window:before:load', (win) => {
win.mergeSnapConfig = {
themes: {
custom: {
extends: 'bocachica',
overrides: {
components: {
recommendationBundle: {
lazyRender: {
enabled: false,
},
speed: 0,
},
},
},
},
},
recommendation: {
bundle: {
Bundle: {
component: 'RecommendationBundleList',
theme: 'custom',
},
},
},
Expand Down Expand Up @@ -134,11 +150,27 @@ describe('BundledRecommendations', () => {

cy.on('window:before:load', (win) => {
win.mergeSnapConfig = {
themes: {
custom: {
extends: 'bocachica',
overrides: {
components: {
recommendationBundle: {
lazyRender: {
enabled: false,
},
speed: 0,
},
},
},
},
},
recommendation: {
bundle: {
Bundle: {
component: 'RecommendationBundleList',
resultComponent: 'CustomResult',
theme: 'custom',
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,26 @@ describe('BundledRecommendations', () => {
cy.wrap(config).its('url').should('have.length.at.least', 1);
cy.on('window:before:load', (win) => {
win.mergeSnapConfig = {
themes: {
custom: {
extends: 'bocachica',
overrides: {
components: {
recommendationBundle: {
lazyRender: {
enabled: false,
},
speed: 0,
},
},
},
},
},
recommendation: {
bundle: {
Bundle: {
component: 'RecommendationBundleVertical',
theme: 'custom',
},
},
},
Expand Down Expand Up @@ -146,11 +162,27 @@ describe('BundledRecommendations', () => {

cy.on('window:before:load', (win) => {
win.mergeSnapConfig = {
themes: {
custom: {
extends: 'bocachica',
overrides: {
components: {
recommendationBundle: {
lazyRender: {
enabled: false,
},
speed: 0,
},
},
},
},
},
recommendation: {
bundle: {
Bundle: {
component: 'RecommendationBundleVertical',
resultComponent: 'CustomResult',
theme: 'custom',
},
},
},
Expand Down
Loading