From 0df0438172461ffd19682277d7afcbb0f2e7e478 Mon Sep 17 00:00:00 2001 From: LilyL0u Date: Tue, 8 Nov 2022 15:16:44 +0000 Subject: [PATCH 1/2] test image & title on recs --- cypress/integration/pages/storyPage/tests.js | 64 +++++++++++++++++++- cypress/support/config/settings.js | 2 +- cypress/support/helpers/runTestsForPage.js | 1 + 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/cypress/integration/pages/storyPage/tests.js b/cypress/integration/pages/storyPage/tests.js index 9c2d2b8a341..d86a21bb659 100644 --- a/cypress/integration/pages/storyPage/tests.js +++ b/cypress/integration/pages/storyPage/tests.js @@ -3,7 +3,6 @@ import path from 'ramda/src/path'; import getDataUrl from '../../../support/helpers/getDataUrl'; import topicTagsTest from '../../../support/helpers/topicTagsTest'; import envConfig from '../../../support/config/envs'; - // For testing important features that differ between services, e.g. Timestamps. // We recommend using inline conditional logic to limit tests to services which differ. export const testsThatAlwaysRun = ({ service, pageType }) => { @@ -11,7 +10,11 @@ export const testsThatAlwaysRun = ({ service, pageType }) => { }; // For testing features that may differ across services but share a common logic e.g. translated strings. -export const testsThatFollowSmokeTestConfig = ({ service, pageType }) => { +export const testsThatFollowSmokeTestConfig = ({ + service, + pageType, + isAmp, +}) => { describe(`testsThatFollowSmokeTestConfig to run for ${service} ${pageType}`, () => { it('should render a description for the page', () => { cy.request(`${Cypress.env('currentPath')}.json`).then(({ body }) => { @@ -121,6 +124,63 @@ export const testsThatFollowSmokeTestConfig = ({ service, pageType }) => { } }); }); + describe(`Recommendations on ${service} ${pageType}`, () => { + it('Recommendations have images', () => { + cy.getToggles(service); + cy.fixture(`toggles/${service}.json`).then(toggles => { + const recommendationsEnabled = path( + ['cpsRecommendations', 'enabled'], + toggles, + ); + cy.log(`Recommendations enabled? ${recommendationsEnabled}`); + if (recommendationsEnabled) { + cy.get(`[data-e2e=recommendations-heading]`).scrollIntoView(); + cy.get('[data-e2e=recommendations-heading] > div > ul > li').each( + (item, index) => { + cy.wrap(item).within(() => { + cy.log(`List item number: ${index}`); + cy.log(`isAmp= ${isAmp}`); + if (isAmp) { + cy.get( + `[data-e2e=story-promo-wrapper] > div > [data-e2e=image-placeholder] > amp-img`, + ).should('have.attr', 'width'); + } else { + cy.get( + `[data-e2e=story-promo-wrapper] > div > [data-e2e=image-placeholder] > div > picture > img`, + ).should('have.attr', 'width'); + } + }); + }, + ); + } + }); + }); + it('Recommendations have titles', () => { + cy.getToggles(service); + cy.fixture(`toggles/${service}.json`).then(toggles => { + const recommendationsEnabled = path( + ['cpsRecommendations', 'enabled'], + toggles, + ); + cy.log(`Recommendations enabled? ${recommendationsEnabled}`); + if (recommendationsEnabled) { + cy.get(`[data-e2e=recommendations-heading]`).scrollIntoView(); + cy.get('[data-e2e=recommendations-heading] > div > ul > li').each( + (item, index) => { + cy.wrap(item).within(() => { + cy.log(`List item number: ${index + 1}`); + cy.get(`[data-e2e=story-promo-wrapper] > div > div > a`) + .invoke('text') + .then(text => { + expect(text.length).to.be.at.least(1); + }); + }); + }, + ); + } + }); + }); + }); }; // For testing low priority things e.g. cosmetic differences, and a safe place to put slow tests. diff --git a/cypress/support/config/settings.js b/cypress/support/config/settings.js index f0a70d78e88..497ce64339f 100644 --- a/cypress/support/config/settings.js +++ b/cypress/support/config/settings.js @@ -4180,7 +4180,7 @@ module.exports = () => ({ environments: { live: { paths: ['/mundo/noticias-54274735'], - enabled: false, + enabled: true, }, test: { paths: ['/mundo/23263889'], diff --git a/cypress/support/helpers/runTestsForPage.js b/cypress/support/helpers/runTestsForPage.js index 09620b17846..8f83748f380 100644 --- a/cypress/support/helpers/runTestsForPage.js +++ b/cypress/support/helpers/runTestsForPage.js @@ -121,6 +121,7 @@ const runTestsForPage = ({ service, pageType, variant: config[service].variant, + isAmp: true, }; // Enables overriding of the smoke test values in the config/settings.js file From 3879bd58e4b31a8da51e14d297cf2dd11771832c Mon Sep 17 00:00:00 2001 From: LilyL0u Date: Tue, 8 Nov 2022 16:17:41 +0000 Subject: [PATCH 2/2] limit tests to live --- cypress/integration/pages/storyPage/tests.js | 106 ++++++++++--------- 1 file changed, 57 insertions(+), 49 deletions(-) diff --git a/cypress/integration/pages/storyPage/tests.js b/cypress/integration/pages/storyPage/tests.js index d86a21bb659..a49834333e9 100644 --- a/cypress/integration/pages/storyPage/tests.js +++ b/cypress/integration/pages/storyPage/tests.js @@ -126,59 +126,67 @@ export const testsThatFollowSmokeTestConfig = ({ }); describe(`Recommendations on ${service} ${pageType}`, () => { it('Recommendations have images', () => { - cy.getToggles(service); - cy.fixture(`toggles/${service}.json`).then(toggles => { - const recommendationsEnabled = path( - ['cpsRecommendations', 'enabled'], - toggles, - ); - cy.log(`Recommendations enabled? ${recommendationsEnabled}`); - if (recommendationsEnabled) { - cy.get(`[data-e2e=recommendations-heading]`).scrollIntoView(); - cy.get('[data-e2e=recommendations-heading] > div > ul > li').each( - (item, index) => { - cy.wrap(item).within(() => { - cy.log(`List item number: ${index}`); - cy.log(`isAmp= ${isAmp}`); - if (isAmp) { - cy.get( - `[data-e2e=story-promo-wrapper] > div > [data-e2e=image-placeholder] > amp-img`, - ).should('have.attr', 'width'); - } else { - cy.get( - `[data-e2e=story-promo-wrapper] > div > [data-e2e=image-placeholder] > div > picture > img`, - ).should('have.attr', 'width'); - } - }); - }, + if (Cypress.env('APP_ENV') === 'live') { + cy.getToggles(service); + cy.fixture(`toggles/${service}.json`).then(toggles => { + const recommendationsEnabled = path( + ['cpsRecommendations', 'enabled'], + toggles, ); - } - }); + cy.log(`Recommendations enabled? ${recommendationsEnabled}`); + if (recommendationsEnabled) { + cy.get(`[data-e2e=recommendations-heading]`).scrollIntoView(); + cy.get('[data-e2e=recommendations-heading] > div > ul > li').each( + (item, index) => { + cy.wrap(item).within(() => { + cy.log(`List item number: ${index}`); + cy.log(`isAmp= ${isAmp}`); + if (isAmp) { + cy.get( + `[data-e2e=story-promo-wrapper] > div > [data-e2e=image-placeholder] > amp-img`, + ).should('have.attr', 'width'); + } else { + cy.get( + `[data-e2e=story-promo-wrapper] > div > [data-e2e=image-placeholder] > div > picture > img`, + ).should('have.attr', 'width'); + } + }); + }, + ); + } + }); + } else { + cy.log('Only tests live due to not much test data'); + } }); it('Recommendations have titles', () => { - cy.getToggles(service); - cy.fixture(`toggles/${service}.json`).then(toggles => { - const recommendationsEnabled = path( - ['cpsRecommendations', 'enabled'], - toggles, - ); - cy.log(`Recommendations enabled? ${recommendationsEnabled}`); - if (recommendationsEnabled) { - cy.get(`[data-e2e=recommendations-heading]`).scrollIntoView(); - cy.get('[data-e2e=recommendations-heading] > div > ul > li').each( - (item, index) => { - cy.wrap(item).within(() => { - cy.log(`List item number: ${index + 1}`); - cy.get(`[data-e2e=story-promo-wrapper] > div > div > a`) - .invoke('text') - .then(text => { - expect(text.length).to.be.at.least(1); - }); - }); - }, + if (Cypress.env('APP_ENV') === 'live') { + cy.getToggles(service); + cy.fixture(`toggles/${service}.json`).then(toggles => { + const recommendationsEnabled = path( + ['cpsRecommendations', 'enabled'], + toggles, ); - } - }); + cy.log(`Recommendations enabled? ${recommendationsEnabled}`); + if (recommendationsEnabled) { + cy.get(`[data-e2e=recommendations-heading]`).scrollIntoView(); + cy.get('[data-e2e=recommendations-heading] > div > ul > li').each( + (item, index) => { + cy.wrap(item).within(() => { + cy.log(`List item number: ${index + 1}`); + cy.get(`[data-e2e=story-promo-wrapper] > div > div > a`) + .invoke('text') + .then(text => { + expect(text.length).to.be.at.least(1); + }); + }); + }, + ); + } + }); + } else { + cy.log('Only tests live due to not much test data'); + } }); }); };