Skip to content

Commit

Permalink
Merge pull request #10405 from bbc/recommendations-image-title-check
Browse files Browse the repository at this point in the history
Tests recommendations have images and title on every item (a bug that was fixed before)
  • Loading branch information
LilyL0u authored Nov 16, 2022
2 parents 557feb7 + 41a3eff commit 1e135aa
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
72 changes: 70 additions & 2 deletions cypress/integration/pages/storyPage/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ 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 }) => {
describe(`No testsToAlwaysRun to run for ${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 }) => {
Expand Down Expand Up @@ -121,6 +124,71 @@ export const testsThatFollowSmokeTestConfig = ({ service, pageType }) => {
}
});
});
describe(`Recommendations on ${service} ${pageType}`, () => {
it('Recommendations have images', () => {
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', () => {
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');
}
});
});
};

// For testing low priority things e.g. cosmetic differences, and a safe place to put slow tests.
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4180,7 +4180,7 @@ module.exports = () => ({
environments: {
live: {
paths: ['/mundo/noticias-54274735'],
enabled: false,
enabled: true,
},
test: {
paths: ['/mundo/23263889'],
Expand Down
1 change: 1 addition & 0 deletions cypress/support/helpers/runTestsForPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e135aa

Please sign in to comment.