Skip to content

Commit

Permalink
Merge pull request #12058 from bbc/WSTEAM1-1349-lite-site-cta
Browse files Browse the repository at this point in the history
WSTEAM1-1349: Lite Site CTA
  • Loading branch information
HarveyPeachey authored Oct 30, 2024
2 parents 275b924 + f751cab commit 46b9938
Show file tree
Hide file tree
Showing 28 changed files with 7,214 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cypress/e2e/pages/articles/index.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import runTestsForPage from '../../../support/helpers/runTestsForPage';
import { testsThatAlwaysRun, testsThatFollowSmokeTestConfig } from './tests';
import { testsThatFollowSmokeTestConfigForAMPOnly } from './testsForAMPOnly';
import { testsThatFollowSmokeTestConfigForCanonicalOnly } from './testsForCanonicalOnly';
import { testsForLiteOnly } from './testsForLiteOnly';

const testsForPage = {
pageType: 'articles',
testsThatAlwaysRun,
testsThatFollowSmokeTestConfig,
testsThatFollowSmokeTestConfigForCanonicalOnly,
testsThatFollowSmokeTestConfigForAMPOnly,
testsForLiteOnly,
};

runTestsForPage(testsForPage);
35 changes: 35 additions & 0 deletions cypress/e2e/pages/articles/testsForLiteOnly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* 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)) {
it('Clicking the link to the main site should navigate to canonical site', () => {
cy.get('[data-e2e="to-main-site"]').within(() => {
cy.get('a')
.should('have.attr', 'href')
.then($href => {
cy.get('a').click();
cy.url().should('eq', $href).should('not.contain', '.lite');
});
});
cy.go('back');
});

it('Clicking the link to the Information page should navigate to lite site', () => {
cy.get('[data-e2e="information-page"]').within(() => {
cy.get('a')
.should('have.attr', 'href')
.then($href => {
cy.get('a').click();
cy.url().should('eq', $href);
})
.and('contain', '.lite');
});
cy.go('back');
});
}
});
});
};
6 changes: 3 additions & 3 deletions cypress/support/config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1518,11 +1518,11 @@ module.exports = () => ({
enabled: false,
},
local: {
paths: ['/gahuza/articles/cey23zx8wx8o'],
enabled: false,
paths: ['/gahuza/articles/c5y51yxeg53o'],
enabled: true,
},
},
smoke: false,
smoke: true,
},
errorPage404: {
environments: {
Expand Down
16 changes: 16 additions & 0 deletions cypress/support/helpers/getLiteUrl/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Url from 'url-parse';

export default path => {
/**
* Appends .lite to the pathname, before appending query string values
*
* */

const urlFromPath = new Url(path);

if (!urlFromPath.pathname.includes('.lite')) {
urlFromPath.set('pathname', `${urlFromPath.pathname}.lite`);
}

return urlFromPath.href;
};
35 changes: 35 additions & 0 deletions cypress/support/helpers/getLiteUrl/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { default: getLiteUrl } = require('.');

describe('getLiteUrl', () => {
[
'http://localhost:7080',
'https://www.test.bbc.com',
'https://www.bbc.com',
].forEach(baseUrl => {
describe(`with base url ${baseUrl}`, () => {
it('should return lite url', () => {
expect(getLiteUrl(`${baseUrl}/pathname`)).toEqual(
`${baseUrl}/pathname.lite`,
);
});

it('should not append .lite to lite path', () => {
expect(getLiteUrl(`${baseUrl}/pathname.lite`)).toEqual(
`${baseUrl}/pathname.lite`,
);
});

it('should return lite url for path with query string params', () => {
expect(getLiteUrl(`${baseUrl}/pathname?query_string=value`)).toEqual(
`${baseUrl}/pathname.lite?query_string=value`,
);
});

it('should not append .lite to lite path with query string params', () => {
expect(
getLiteUrl(`${baseUrl}/pathname.lite?query_string=value`),
).toEqual(`${baseUrl}/pathname.lite?query_string=value`);
});
});
});
});
24 changes: 24 additions & 0 deletions cypress/support/helpers/runTestsForPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import serviceHasPageType from './serviceHasPageType';
import ampOnlyServices from './ampOnlyServices';
import visitPage from './visitPage';
import getAmpUrl from './getAmpUrl';
import getLiteUrl from './getLiteUrl';

// This function takes all types of tests we have and runs in this series of steps with the fewest possible page visits

Expand All @@ -26,6 +27,7 @@ const runTestsForPage = ({
testsThatNeverRunDuringSmokeTesting = noOp,
testsThatNeverRunDuringSmokeTestingForCanonicalOnly = noOp,
testsThatNeverRunDuringSmokeTestingForAMPOnly = noOp,
testsForLiteOnly = noOp,
}) => {
// For each Service and Page Type in the config file it visits the path and it writes a describe saying this.

Expand Down Expand Up @@ -137,6 +139,28 @@ const runTestsForPage = ({
}
}
});

// Switch to Lite page URL (NB only some of our pages have AMP variants)
describe(`${pageType} - ${currentPath} - Lite`, () => {
// TC2 MAPs are not loading the media player which causes the tests to fail when the page is visited, this is accepted behaviour
// The substring '/20' is common to all the TC2 MAPs test URLs in the settings and we will not be adding more
if (!currentPath.includes('/20')) {
before(() => {
Cypress.env('currentPath', currentPath);

visitPage(getLiteUrl(currentPath), pageType);
});

const testArgs = {
service,
pageType,
variant: config[service].variant,
isAmp: true,
};

testsForLiteOnly(testArgs);
}
});
});
});
};
Expand Down
Loading

0 comments on commit 46b9938

Please sign in to comment.