Skip to content

Commit

Permalink
Merge branch 'latest' of github.com:bbc/simorgh into ukchina-homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
karinathomasbbc committed Feb 7, 2025
2 parents 8503665 + 580fea4 commit 43ccf11
Show file tree
Hide file tree
Showing 25 changed files with 306 additions and 1,014 deletions.
253 changes: 239 additions & 14 deletions cypress/e2e/pages/articles/index.cy.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,241 @@
import runTestsForPage from '../../../support/helpers/runTestsForPage';
import { testsThatAlwaysRun, testsThatFollowSmokeTestConfig } from './tests';
import { testsThatFollowSmokeTestConfigForAMPOnly } from './testsForAMPOnly';
import { testsThatFollowSmokeTestConfigForCanonicalOnly } from './testsForCanonicalOnly';
import { testsForLiteOnly } from './testsForLiteOnly';
/* eslint-disable import/no-relative-packages */
import runTestsForPage from '#nextjs/cypress/support/helpers/runTestsForPage';
import { testsThatAlwaysRunForAllPages as testsForAllPages } from '../testsForAllPages';
import { testsThatFollowSmokeTestConfigForAllCanonicalPages as testsForAllCanonicalPages } from '../testsForAllCanonicalPages';
import { testsThatFollowSmokeTestConfigForAllAMPPages as testsForAllAMPPages } from '../testsForAllAMPPages';
import canonicalAndAmpArticleTests from './tests';
import ampArticleTests from './testsForAMPOnly';
import canonicalArticleTests from './testsForCanonicalOnly';
import liteArticleTests from './testsForLiteOnly';

const testsForPage = {
const canonicalTests = [
testsForAllPages,
testsForAllCanonicalPages,
canonicalAndAmpArticleTests,
canonicalArticleTests,
];

const ampTests = [
testsForAllPages,
testsForAllAMPPages,
canonicalAndAmpArticleTests,
ampArticleTests,
];

const smokeCanonicalTestSuites = [
{
path: '/gahuza/articles/c5y51yxeg53o',
runforEnv: ['local', 'live'],
service: 'gahuza',
tests: [...canonicalTests],
},
{
path: '/mundo/articles/ce42wzqr2mko',
runforEnv: ['local', 'test'],
service: 'mundo',
tests: [...canonicalTests],
},
{
path: '/mundo/articles/ce7p1pw7165o',
runforEnv: ['live'],
service: 'mundo',
tests: [...canonicalTests],
},
{
path: '/persian/articles/cej3lzd5e0go',
runforEnv: ['local', 'test'],
service: 'persian',
tests: [...canonicalTests],
},
{
path: '/persian/articles/cld9872jgyjo',
runforEnv: ['live'],
service: 'persian',
tests: [...canonicalTests],
},
{
path: '/persian/articles/crgxnrdl1xvo',
runforEnv: ['live'],
service: 'persian',
tests: [...canonicalTests],
},
{
path: '/pidgin/articles/cgwk9w4zlg8o',
runforEnv: ['live'],
service: 'pidgin',
tests: [...canonicalTests],
},
{
path: '/pidgin/articles/crrrkxz2k0ko',
runforEnv: ['test'],
service: 'pidgin',
tests: [...canonicalTests],
},
{
path: '/pidgin/articles/cwl08rd38l6o',
runforEnv: ['local', 'test'],
service: 'pidgin',
tests: [...canonicalTests],
},
{
path: '/pidgin/articles/cw8qv1d11l9o',
runforEnv: ['live'],
service: 'pidgin',
tests: [...canonicalTests],
},
{
path: '/scotland/articles/czwj5l0n210o',
runforEnv: ['local'],
service: 'scotland',
tests: [...canonicalTests],
},
{
path: '/serbian/articles/c805k05kr73o/cyr',
runforEnv: ['local'],
service: 'serbian',
variant: 'cyr',
tests: [...canonicalTests],
},
{
path: '/serbian/articles/c805k05kr73o/lat',
runforEnv: ['local'],
service: 'serbian',
variant: 'lat',
tests: [...canonicalTests],
},
{
path: '/zhongwen/articles/c3xd4x9prgyo/simp',
runforEnv: ['local'],
service: 'zhongwen',
variant: 'simp',
tests: [...canonicalTests],
},
{
path: '/zhongwen/articles/c3xd4x9prgyo/trad',
runforEnv: ['local'],
service: 'zhongwen',
variant: 'trad',
tests: [...canonicalTests],
},
];

const nonSmokeCanonicalTestSuites = [
{
path: '/afaanoromoo/articles/c4g19kgl85ko',
runforEnv: ['test'],
service: 'afaanoromoo',
tests: [...canonicalTests],
},
{
path: '/afrique/articles/cz216x22106o',
runforEnv: ['test'],
service: 'afrique',
tests: [...canonicalTests],
},
{
path: '/azeri/articles/cv0lm08kngmo',
runforEnv: ['live'],
service: 'azeri',
tests: [...canonicalTests],
},
{
path: '/gahuza/articles/cey23zx8wx8o',
runforEnv: ['test'],
service: 'gahuza',
tests: [...canonicalTests],
},
{
path: '/japanese/articles/cdd6p3r9g7jo',
runforEnv: ['test'],
service: 'japanese',
tests: [...canonicalTests],
},
{
path: '/japanese/articles/cj4m7n5nrd8o',
runforEnv: ['live'],
service: 'japanese',
tests: [...canonicalTests],
},
{
path: '/kyrgyz/articles/c414v42gy75o',
runforEnv: ['live'],
service: 'kyrgyz',
tests: [...canonicalTests],
},
{
path: '/kyrgyz/articles/c41knv20gk7o',
runforEnv: ['live'],
service: 'kyrgyz',
tests: [...canonicalTests],
},
{
path: '/kyrgyz/articles/cpgx4k72wv4o',
runforEnv: ['live'],
service: 'kyrgyz',
tests: [...canonicalTests],
},
{
path: '/mundo/articles/ce7p1pw7165o',
runforEnv: ['live'],
service: 'mundo',
tests: [...canonicalTests],
},

{
path: '/nepali/articles/c16ljg1v008o',
runforEnv: ['live'],
service: 'nepali',
tests: [...canonicalTests],
},
{
path: '/ukrainian/articles/c8zv0eed9gko',
runforEnv: ['live'],
service: 'ukrainian',
tests: [...canonicalTests],
},
];

const canonicalTestSuites = Cypress.env.SMOKE
? smokeCanonicalTestSuites
: nonSmokeCanonicalTestSuites;

const ampTestSuites = canonicalTestSuites.map(testSuite => {
return {
...testSuite,
path: `${testSuite.path}.amp`,
tests: [...ampTests],
};
});

// Additional scenarios for news on higher environments
ampTestSuites.push(
...[
{
path: '/news/articles/cn7k01xp8kxo.amp',
runforEnv: ['local', 'test'],
service: 'news',
tests: [...ampTests],
},
{
path: '/news/articles/cj7xrxz0e8zo.amp',
runforEnv: ['live'],
service: 'news',
tests: [...ampTests],
},
],
);

const liteTestSuites = canonicalTestSuites
.filter(({ service }) => service !== 'news')
.map(testSuite => {
return {
...testSuite,
path: `${testSuite.path}.lite`,
tests: [liteArticleTests],
};
});

runTestsForPage({
pageType: 'articles',
testsThatAlwaysRun,
testsThatFollowSmokeTestConfig,
testsThatFollowSmokeTestConfigForCanonicalOnly,
testsThatFollowSmokeTestConfigForAMPOnly,
testsForLiteOnly,
};

runTestsForPage(testsForPage);
testSuites: [...canonicalTestSuites, ...ampTestSuites, ...liteTestSuites],
});
16 changes: 4 additions & 12 deletions cypress/e2e/pages/articles/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,18 @@ const serviceHasTimestamp = service => ['news', 'urdu'].includes(service);
const serviceHasInlineLink = service =>
service === 'news' || service === 'afaanoromoo';

// 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(`Running testsToAlwaysRun 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,
variant,
}) => {
export default ({ service, pageType, variant = 'default' }) => {
describe(`Running tests for ${service} ${pageType}`, () => {
describe(`Metadata`, () => {
const serviceID = config[service]?.name || service;

// Here we should only have metadata tests that are unique to articles pages
it('should have the correct articles metadata', () => {
cy.get('meta[name="article:author"]').should(
'have.attr',
'content',
appConfig[config[service].name][variant].articleAuthor,
appConfig[serviceID][variant].articleAuthor,
);
});

Expand Down
6 changes: 1 addition & 5 deletions cypress/e2e/pages/articles/testsForAMPOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ const articleHasPlayer = articleId =>
].includes(articleId);

// For testing features that may differ across services but share a common logic e.g. translated strings.
export const testsThatFollowSmokeTestConfigForAMPOnly = ({
service,
pageType,
variant,
}) => {
export default ({ service, pageType, variant = 'default' }) => {
let articleId;
describe(`Running testsForAMPOnly for ${service} ${pageType}`, () => {
before(() => {
Expand Down
8 changes: 2 additions & 6 deletions cypress/e2e/pages/articles/testsForCanonicalOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import { getBlockData, getBlockByType, getVideoEmbedUrl } from './helpers';
const serviceHasCaption = service => service === 'news';

// For testing features that may differ across services but share a common logic e.g. translated strings.
export const testsThatFollowSmokeTestConfigForCanonicalOnly = ({
service,
pageType,
variant,
}) =>
export default ({ service, pageType, variant = 'default' }) =>
describe(`Canonical Tests for ${service} ${pageType}`, () => {
if (appToggles.chartbeatAnalytics.enabled) {
describe('Chartbeat', () => {
Expand Down Expand Up @@ -142,7 +138,7 @@ export const testsThatFollowSmokeTestConfigForCanonicalOnly = ({
});
});
if (service === 'pidgin') {
it('should render an iframe with a valid URL when a user clicks play', () => {
it('should render a media player with a valid embed URL when a user clicks play', () => {
cy.window().then(win => {
const body = win.SIMORGH_DATA.pageData;
const media = getBlockData('video', body);
Expand Down
13 changes: 6 additions & 7 deletions cypress/e2e/pages/articles/testsForLiteOnly.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable import/prefer-default-export */
import { liteEnabledServices } from '#app/components/LiteSiteCta/liteSiteConfig';

export const testsForLiteOnly = ({ service, pageType }) => {
describe(`Running testsForLiteOnly for ${service} ${pageType}`, () => {
describe('CTA: Lite', () => {
if (liteEnabledServices.includes(service)) {
export default ({ service, pageType }) => {
if (liteEnabledServices.includes(service)) {
describe(`Running testsForLiteOnly for ${service} ${pageType}`, () => {
describe('CTA: Lite', () => {
it('Clicking the link to the main site should navigate to canonical site', () => {
cy.get('[data-e2e="to-main-site"]').within(() => {
cy.get('a')
Expand All @@ -29,7 +28,7 @@ export const testsForLiteOnly = ({ service, pageType }) => {
});
cy.go('back');
});
}
});
});
});
}
};
17 changes: 9 additions & 8 deletions cypress/e2e/pages/mostReadPage/mostReadAssertions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { serviceNumerals } from '../../../../src/app/components/MostRead/Canonical/Rank';
import config from '../../../support/config/services';
import appConfig from '../../../../src/server/utilities/serviceConfigs';
import { getMostReadEndpoint } from '../../../../src/app/lib/utilities/getUrlHelpers/getMostReadUrls';
import getAppEnv from '../../../support/helpers/getAppEnv';
import ampOnlyServices from '../../../support/helpers/ampOnlyServices';
/* eslint-disable import/no-unresolved */
import appConfig from '#src/server/utilities/serviceConfigs';
import { getMostReadEndpoint } from '#lib/utilities/getUrlHelpers/getMostReadUrls';
import { serviceNumerals } from '#app/components/MostRead/Canonical/Rank';
import config from '#cypress/support/config/services';
import getAppEnv from '#cypress/support/helpers/getAppEnv';
import ampOnlyServices from '#cypress/support/helpers/ampOnlyServices';

// news, newsround, and sport are services we serve on amp, but do not want to run most read tests on
const MOST_READ_EXCLUDED_SERVICES = [...ampOnlyServices, 'ukchina'];

export const crossPlatform = ({ service, variant }) => {
export const crossPlatform = ({ service, variant = 'default' }) => {
const serviceID = config[service]?.name || service;

if (!MOST_READ_EXCLUDED_SERVICES.includes(serviceID)) {
Expand Down Expand Up @@ -67,7 +68,7 @@ export const crossPlatform = ({ service, variant }) => {
}
};

export const ampOnly = ({ service, variant }) => {
export const ampOnly = ({ service, variant = 'default' }) => {
const serviceID = config[service]?.name || service;

if (!MOST_READ_EXCLUDED_SERVICES.includes(serviceID)) {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/pages/testsForAllAMPPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const testsThatFollowSmokeTestConfigForAllAMPPages = ({
}) => {
describe(`testsThatFollowSmokeTestConfigForAllAMPPages to run for ${service} ${pageType}`, () => {
describe('Header Tests', () => {
const serviceName = config[service].name;
const serviceName = config[service]?.name || service;
// limit number of tests to 2 services for navigation toggling
const testMobileNav =
serviceName === 'ukchina' || serviceName === 'persian';
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/pages/testsForAllCanonicalPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const testsThatFollowSmokeTestConfigForAllCanonicalPages = ({
}

describe('Header Tests', () => {
const serviceName = config[service].name;
const serviceName = config[service]?.name || service;
// limit number of tests to 2 services for navigation toggling
const testMobileNav =
serviceName === 'ukchina' || serviceName === 'persian';
Expand Down
Loading

0 comments on commit 43ccf11

Please sign in to comment.