diff --git a/cypress/e2e/pages/errorPage404/index.cy.js b/cypress/e2e/pages/errorPage404/index.cy.js deleted file mode 100644 index 5bf9b48b3c2..00000000000 --- a/cypress/e2e/pages/errorPage404/index.cy.js +++ /dev/null @@ -1,53 +0,0 @@ -import runTestsForPage from '#nextjs/cypress/support/helpers/runTestsForPage'; -import testsForAllPages from './tests'; -import { ERROR_PAGE } from '../../../../src/app/routes/utils/pageTypes'; - -const tests = [testsForAllPages]; - -const canonicalTestSuites = [ - { - path: '/arabic/articles/c123456abcdo', - service: 'arabic', - runforEnv: ['local', 'test', 'live'], - tests, - }, - { - path: '/mundo/articles/c123456abcdo', - service: 'mundo', - runforEnv: ['local', 'test', 'live'], - tests, - }, - { - path: '/serbian/articles/c123456abcdo/cyr', - service: 'serbian', - runforEnv: ['local', 'test', 'live'], - variant: 'cyr', - tests, - }, - { - path: '/serbian/articles/c123456abcdo/lat', - service: 'serbian', - runforEnv: ['local', 'test', 'live'], - variant: 'lat', - tests, - }, - { - path: '/ukrainian/articles/c123456abcdo', - service: 'ukrainian', - runforEnv: ['local', 'test', 'live'], - tests, - }, -]; - -const ampTestSuites = [...canonicalTestSuites].map(testSuite => { - return { - ...testSuite, - path: `${testSuite.path}.amp`, - }; -}); - -runTestsForPage({ - failOnStatusCode: false, - pageType: ERROR_PAGE, - testSuites: [...canonicalTestSuites, ...ampTestSuites], -}); diff --git a/cypress/e2e/pages/errorPage404/tests.js b/cypress/e2e/pages/errorPage404/tests.js deleted file mode 100644 index 2047ea40915..00000000000 --- a/cypress/e2e/pages/errorPage404/tests.js +++ /dev/null @@ -1,38 +0,0 @@ -/* eslint-disable import/prefer-default-export */ -import envConfig from '../../../support/config/envs'; -import appConfig from '../../../../src/server/utilities/serviceConfigs'; - -// For testing features that may differ across services but share a common logic e.g. translated strings. -export default ({ service, pageType, variant = 'default' }) => - describe(`Tests for ${service} ${pageType}`, () => { - if (envConfig.standaloneErrorPages) { - describe(`${service} error page routes`, () => { - it(`/${service}/404 should have response code 200`, () => { - cy.testResponseCodeAndType({ - path: `/${service}/404`, - responseCode: 200, - type: 'text/html', - }); - cy.visit(`${service}/404`) - .get('[data-e2e="status-code"]') - .should( - 'contain', - appConfig[service][variant].translations.error[404].statusCode, - ); - }); - it(`/${service}/500 should have response code 200`, () => { - cy.testResponseCodeAndType({ - path: `/${service}/500`, - responseCode: 200, - type: 'text/html', - }); - cy.visit(`${service}/500`) - .get('[data-e2e="status-code"]') - .should( - 'contain', - appConfig[service][variant].translations.error[500].statusCode, - ); - }); - }); - } - }); diff --git a/cypress/e2e/pages/errorPage404/testsForAMPOnly.js b/cypress/e2e/pages/errorPage404/testsForAMPOnly.js deleted file mode 100644 index 8adadbc007d..00000000000 --- a/cypress/e2e/pages/errorPage404/testsForAMPOnly.js +++ /dev/null @@ -1,11 +0,0 @@ -// For testing features that may differ across services but share a common logic e.g. translated strings. -export default ({ service, pageType, path }) => - describe(`Amp Tests for ${service} ${pageType}`, () => { - it('should return a 404 error code', () => { - cy.testResponseCodeAndType({ - path: `${path}.amp`, - responseCode: 404, - type: 'text/html', - }); - }); - }); diff --git a/cypress/e2e/pages/errorPage404/testsForCanonicalOnly.js b/cypress/e2e/pages/errorPage404/testsForCanonicalOnly.js deleted file mode 100644 index 27b4c136a9d..00000000000 --- a/cypress/e2e/pages/errorPage404/testsForCanonicalOnly.js +++ /dev/null @@ -1,11 +0,0 @@ -// For testing features that may differ across services but share a common logic e.g. translated strings. -export default ({ service, pageType, path }) => - describe(`Canonical Tests for ${service} ${pageType}`, () => { - it('should return a 404 error code', () => { - cy.testResponseCodeAndType({ - path, - responseCode: 404, - type: 'text/html', - }); - }); - }); diff --git a/cypress/e2e/pages/mostReadPage/index.cy.js b/ws-nextjs-app/cypress/e2e/mostReadPage/index.cy.ts similarity index 62% rename from cypress/e2e/pages/mostReadPage/index.cy.js rename to ws-nextjs-app/cypress/e2e/mostReadPage/index.cy.ts index 96beaf38d9d..324876e9bcc 100644 --- a/cypress/e2e/pages/mostReadPage/index.cy.js +++ b/ws-nextjs-app/cypress/e2e/mostReadPage/index.cy.ts @@ -1,23 +1,23 @@ -import runTestsForPage from '#nextjs/cypress/support/helpers/runTestsForPage'; -import testsForCanonicalOnly from './testsForCanonicalOnly'; -import crossPlatformTests from './tests'; -import testsForAllPages from '../testsForAllPages'; -import testsForAllCanonicalPages from '../testsForAllCanonicalPages'; -import { assertPageView } from '../../specialFeatures/atiAnalytics/assertions'; -import getPathWithSuffix from '../../../support/helpers/getPathWithSuffix'; -import { assertLiteSiteSummaryComponentToMainSiteClick } from '../../specialFeatures/atiAnalytics/assertions/liteSiteSummary'; +import { MOST_READ_PAGE } from '#app/routes/utils/pageTypes'; +import runTestsForPage from '../../support/helpers/runTestsForPage'; +import { + assertMostReadComponentClick, + assertMostReadComponentView, +} from '../specialFeatures/atiAnalytics/assertions/mostRead'; import { assertDropdownNavigationComponentClick, assertDropdownNavigationComponentView, assertScrollableNavigationComponentClick, assertScrollableNavigationComponentView, -} from '../../specialFeatures/atiAnalytics/assertions/navigation'; -import { - assertMostReadComponentClick, - assertMostReadComponentView, -} from '../../specialFeatures/atiAnalytics/assertions/mostRead'; +} from '../specialFeatures/atiAnalytics/assertions/navigation'; +import { assertLiteSiteSummaryComponentToMainSiteClick } from '../specialFeatures/atiAnalytics/assertions/liteSiteSummary'; +import getPathWithSuffix from '../../support/helpers/getPathWithSuffix'; +import { assertPageView } from '../specialFeatures/atiAnalytics/assertions'; +import testsForAllCanonicalPages from '../testsForAllCanonicalPages'; +import testsForAllPages from '../testsForAllPages'; +import crossPlatformTests from './tests'; +import testsForCanonicalOnly from './testsForCanonicalOnly'; -const pageType = 'mostReadPage'; const tests = [ crossPlatformTests, testsForCanonicalOnly, @@ -25,13 +25,6 @@ const tests = [ testsForAllCanonicalPages, ]; -/** - * Use a selection of services to ensure Most Read page renders as expected - * arabic: RTL service - * igbo: small service, only 5 items displayed - * pidgin: LTR service - * serbian: service with variant - */ const testSuites = [ { path: '/pidgin/popular/read', @@ -42,32 +35,24 @@ const testSuites = [ { path: '/arabic/popular/read', service: 'arabic', - runforEnv: ['local', 'test', 'live'], + runforEnv: ['test', 'live'], tests, }, { path: '/igbo/popular/read', service: 'igbo', - runforEnv: ['local', 'test', 'live'], + runforEnv: ['test', 'live'], tests, }, { path: '/serbian/cyr/popular/read', service: 'serbian', variant: 'cyr', - runforEnv: ['local', 'test', 'live'], + runforEnv: ['test', 'live'], tests, }, ]; -const ampTestSuites = testSuites.map(testSuite => { - return { - ...testSuite, - path: `${testSuite.path}.amp`, - tests: [crossPlatformTests], - }; -}); - const liteTestSuites = testSuites.map(testSuite => { return { ...testSuite, @@ -78,11 +63,11 @@ const liteTestSuites = testSuites.map(testSuite => { const atiAnalyticsTestSuites = [ { - path: '/gahuza/popular/read', + path: '/pidgin/popular/read', runforEnv: ['local', 'test', 'live'], - service: 'gahuza', - pageIdentifier: 'gahuza.popular.read.page', - siteId: 40, + service: 'pidgin', + pageIdentifier: 'pidgin.popular.read.page', + siteId: 70, applicationType: 'responsive', contentType: 'list-datadriven', tests: [ @@ -97,15 +82,6 @@ const atiAnalyticsTestSuites = [ }, ]; -const atiAnalyticsAmpTestSuites = atiAnalyticsTestSuites.map(testSuite => { - return { - ...testSuite, - path: getPathWithSuffix({ path: testSuite.path, suffix: '.amp' }), - applicationType: 'amp', - tests: [assertPageView], - }; -}); - const atiAnalyticsLiteTestSuites = atiAnalyticsTestSuites.map(testSuite => { const excludedLiteTests = [ assertDropdownNavigationComponentView, // Dropdown navigation removed from all pages, as it requires JS @@ -128,17 +104,17 @@ const atiAnalyticsLiteTestSuites = atiAnalyticsTestSuites.map(testSuite => { }); runTestsForPage({ - pageType, - testSuites: [...testSuites, ...ampTestSuites, ...liteTestSuites], + pageType: MOST_READ_PAGE, + testSuites: [...testSuites, ...liteTestSuites], }); runTestsForPage({ - pageType, + pageType: MOST_READ_PAGE, testSuites: atiAnalyticsTestSuites, testIsolation: true, }); runTestsForPage({ - pageType, - testSuites: [...atiAnalyticsAmpTestSuites, ...atiAnalyticsLiteTestSuites], + pageType: MOST_READ_PAGE, + testSuites: [...atiAnalyticsLiteTestSuites], }); diff --git a/cypress/e2e/pages/mostReadPage/mostReadAssertions.js b/ws-nextjs-app/cypress/e2e/mostReadPage/mostReadAssertions.ts similarity index 58% rename from cypress/e2e/pages/mostReadPage/mostReadAssertions.js rename to ws-nextjs-app/cypress/e2e/mostReadPage/mostReadAssertions.ts index 99f304b16ae..d10f741685e 100644 --- a/cypress/e2e/pages/mostReadPage/mostReadAssertions.js +++ b/ws-nextjs-app/cypress/e2e/mostReadPage/mostReadAssertions.ts @@ -1,14 +1,10 @@ /* 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 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']; +const MOST_READ_EXCLUDED_SERVICES = ['ukchina']; -export const crossPlatform = ({ service, variant = 'default' }) => { +export default ({ service, variant = 'default' }) => { if (!MOST_READ_EXCLUDED_SERVICES.includes(service)) { const { mostRead: { hasMostRead, numberOfItems }, @@ -64,38 +60,3 @@ export const crossPlatform = ({ service, variant = 'default' }) => { } } }; - -export const ampOnly = ({ service, variant = 'default' }) => { - if (!MOST_READ_EXCLUDED_SERVICES.includes(service)) { - const { - mostRead: { hasMostRead }, - } = appConfig[service][variant]; - if (hasMostRead) { - describe('Most Read Component', () => { - beforeEach(() => { - cy.getToggles(service); - }); - it('should not render when data fetch fails', () => { - const mostReadPath = getMostReadEndpoint({ - variant: variant !== 'default' && variant, - isBff: getAppEnv() !== 'local', - }); - cy.intercept( - { - method: 'GET', - pathname: mostReadPath, - }, - { statusCode: 404 }, - ); - cy.reload(); - cy.fixture(`toggles/${service}.json`).then(toggles => { - if (toggles.mostRead?.enabled) { - cy.get('[data-e2e="most-read"]').scrollIntoView(); - cy.get('[data-e2e="most-read"] li').should('not.exist'); - } - }); - }); - }); - } - } -}; diff --git a/cypress/e2e/pages/mostReadPage/tests.js b/ws-nextjs-app/cypress/e2e/mostReadPage/tests.ts similarity index 54% rename from cypress/e2e/pages/mostReadPage/tests.js rename to ws-nextjs-app/cypress/e2e/mostReadPage/tests.ts index 32e56b6fa62..fc73f404a42 100644 --- a/cypress/e2e/pages/mostReadPage/tests.js +++ b/ws-nextjs-app/cypress/e2e/mostReadPage/tests.ts @@ -1,4 +1,4 @@ -import { crossPlatform as mostReadAssertions } from './mostReadAssertions'; +import mostReadAssertions from './mostReadAssertions'; export default ({ service, variant }) => { mostReadAssertions({ service, variant }); diff --git a/cypress/e2e/pages/mostReadPage/testsForCanonicalOnly.js b/ws-nextjs-app/cypress/e2e/mostReadPage/testsForCanonicalOnly.ts similarity index 71% rename from cypress/e2e/pages/mostReadPage/testsForCanonicalOnly.js rename to ws-nextjs-app/cypress/e2e/mostReadPage/testsForCanonicalOnly.ts index 295ca53d94a..b07fc0785c7 100644 --- a/cypress/e2e/pages/mostReadPage/testsForCanonicalOnly.js +++ b/ws-nextjs-app/cypress/e2e/mostReadPage/testsForCanonicalOnly.ts @@ -1,4 +1,4 @@ -import chartbeatTests from '../../../support/helpers/chartbeatTests'; +import chartbeatTests from '../../support/helpers/chartbeatTests'; export default ({ service, pageType, variant = 'default' }) => { describe(`testsForCanonicalOnly for ${service} ${pageType} ${variant}`, () => { diff --git a/ws-nextjs-app/pages/[service]/popular/[read]/[[...variant]].page.test.tsx b/ws-nextjs-app/pages/[service]/popular/[read]/[[...variant]].page.test.tsx index 0e25d67364c..692fdaefa62 100644 --- a/ws-nextjs-app/pages/[service]/popular/[read]/[[...variant]].page.test.tsx +++ b/ws-nextjs-app/pages/[service]/popular/[read]/[[...variant]].page.test.tsx @@ -41,6 +41,22 @@ describe('handleMostReadRoute', () => { expect(result.props.pageType).toEqual(MOST_READ_PAGE); }); + it('returns correct metadata.atiAnalytics', () => { + return handleMostReadRoute(mockGetServerSidePropsContext).then(result => { + expect(result.props.pageData.metadata.atiAnalytics).toEqual({ + contentType: 'list-datadriven', + pageIdentifier: 'pidgin.popular.read.page', + timePublished: + pidginMostReadTopicFixture?.data?.curations?.[0]?.mostRead + ?.firstRecordTimeStamp, + timeUpdated: + pidginMostReadTopicFixture?.data?.curations?.[0]?.mostRead + ?.lastRecordTimeStamp, + pageTitle: pidginMostReadTopicFixture?.data?.title || null, + }); + }); + }); + it('returns error props if data fetch returns 500', async () => { jest.spyOn(getPageDataModule, 'default').mockResolvedValue({ data: { diff --git a/ws-nextjs-app/pages/[service]/popular/[read]/[[...variant]].page.tsx b/ws-nextjs-app/pages/[service]/popular/[read]/[[...variant]].page.tsx index 5bcb2c38a5c..e0e8d9575e4 100644 --- a/ws-nextjs-app/pages/[service]/popular/[read]/[[...variant]].page.tsx +++ b/ws-nextjs-app/pages/[service]/popular/[read]/[[...variant]].page.tsx @@ -101,6 +101,10 @@ export const getServerSideProps = async ( ...data.pageData, metadata: { ...data.pageData.metadata, + atiAnalytics: { + ...data.pageData.metadata.atiAnalytics, + pageTitle: data.pageData.title || null, + }, type: MOST_READ_PAGE, }, },