diff --git a/packages/gafl-webapp-service/src/handlers/__tests__/page-handler.spec.js b/packages/gafl-webapp-service/src/handlers/__tests__/page-handler.spec.js index 49a73d74b7..7411943aae 100644 --- a/packages/gafl-webapp-service/src/handlers/__tests__/page-handler.spec.js +++ b/packages/gafl-webapp-service/src/handlers/__tests__/page-handler.spec.js @@ -1,12 +1,14 @@ import pageHandler from '../page-handler.js' import journeyDefinition from '../../routes/journey-definition.js' import { addLanguageCodeToUri } from '../../processors/uri-helper.js' +import { welshEnabledAndApplied } from '../../processors/page-language-helper.js' import GetDataRedirect from '../get-data-redirect.js' import { ANALYTICS } from '../../constants.js' import { AGREED, IDENTIFY, LICENCE_DETAILS, LICENCE_FOR, ORDER_COMPLETE, PAYMENT_CANCELLED, PAYMENT_FAILED } from '../../uri.js' jest.mock('../../routes/journey-definition.js', () => []) jest.mock('../../processors/uri-helper.js') +jest.mock('../../processors/page-language-helper.js') jest.mock('../../constants', () => ({ ANALYTICS: { @@ -138,6 +140,7 @@ describe('The page handler function', () => { it('sets the value of pageData with displayAnalytics true', async () => { addLanguageCodeToUri.mockReturnValueOnce('/buy/process-analytics-preferences') + welshEnabledAndApplied.mockReturnValueOnce(false) const { get } = pageHandler('', 'view', '/next/page') const toolkit = getMockToolkit() await get(getMockRequest(), toolkit) @@ -146,6 +149,7 @@ describe('The page handler function', () => { it('sets the value of pageData with displayAnalytics false', async () => { addLanguageCodeToUri.mockReturnValueOnce('/buy/process-analytics-preferences') + welshEnabledAndApplied.mockReturnValueOnce(false) const { get } = pageHandler('', 'view', '/next/page') const toolkit = getMockToolkit() await get(getMockRequest({ path: '/we/are/here' }), toolkit) @@ -243,8 +247,9 @@ describe('The page handler function', () => { }) describe('pageLanguageSetToWelsh', () => { - it('returns false when SHOW_WELSH_CONTENT is not true', async () => { - process.env.SHOW_WELSH_CONTENT = false + it('returns the value of welshEnabledAndApplied', async () => { + const expectedValue = Symbol('expected') + welshEnabledAndApplied.mockReturnValueOnce(expectedValue) const { get } = pageHandler('', 'view', '/next/page') const toolkit = getMockToolkit() @@ -253,39 +258,7 @@ describe('The page handler function', () => { expect(toolkit.view).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ - pageLanguageSetToWelsh: false - }) - ) - }) - - it('returns false when SHOW_WELSH_CONTENT is true but the lang is not set to cy', async () => { - process.env.SHOW_WELSH_CONTENT = true - const { get } = pageHandler('', 'view', '/next/page') - const toolkit = getMockToolkit() - - await get(getMockRequest(), toolkit) - - expect(toolkit.view).toHaveBeenCalledWith( - expect.any(String), - expect.objectContaining({ - pageLanguageSetToWelsh: false - }) - ) - }) - - it('returns true when SHOW_WELSH_CONTENT is true and the lang is set to cy', async () => { - process.env.SHOW_WELSH_CONTENT = true - const { get } = pageHandler('', 'view', '/next/page') - const query = { lang: 'cy' } - const request = getMockRequest({ query }) - const toolkit = getMockToolkit() - - await get(request, toolkit) - - expect(toolkit.view).toHaveBeenCalledWith( - expect.any(String), - expect.objectContaining({ - pageLanguageSetToWelsh: true + pageLanguageSetToWelsh: expectedValue }) ) }) @@ -298,7 +271,7 @@ const getAnalytics = overides => ({ ...overides }) -const getMockRequest = ({ setCurrentPermission = () => {}, path = '/buy/we/are/here', query = {}, analytics, set = () => {} } = {}) => ({ +const getMockRequest = ({ setCurrentPermission = () => {}, path = '/buy/we/are/here', analytics, set = () => {} } = {}) => ({ cache: () => ({ helpers: { page: { @@ -324,7 +297,6 @@ const getMockRequest = ({ setCurrentPermission = () => {}, path = '/buy/we/are/h getLocale: () => '' }, path, - query, url: { search: '' } diff --git a/packages/gafl-webapp-service/src/handlers/page-handler.js b/packages/gafl-webapp-service/src/handlers/page-handler.js index 5bf8b70e11..a0f86ce43b 100644 --- a/packages/gafl-webapp-service/src/handlers/page-handler.js +++ b/packages/gafl-webapp-service/src/handlers/page-handler.js @@ -14,6 +14,7 @@ import { import GetDataRedirect from './get-data-redirect.js' import journeyDefinition from '../routes/journey-definition.js' import { addLanguageCodeToUri } from '../processors/uri-helper.js' +import { welshEnabledAndApplied } from '../processors/page-language-helper.js' const pagesToOmitAnalyticsBanner = [AGREED.uri, LICENCE_DETAILS.uri, ORDER_COMPLETE.uri, PAYMENT_CANCELLED.uri, PAYMENT_FAILED.uri] const pagesJourneyBeginning = [LICENCE_FOR.uri, IDENTIFY.uri] @@ -40,11 +41,6 @@ const omitPageFromAnalytics = async request => { } } -const pageLanguageSetToWelsh = request => { - const showWelshContent = process.env.SHOW_WELSH_CONTENT?.toLowerCase() === 'true' - return showWelshContent && request.query.lang === 'cy' -} - /** * Flattens the error structure from joi for use in the templates * @param e @@ -128,7 +124,7 @@ export default (path, view, completion, getData) => ({ pageData.altLang = request.i18n.getLocales().filter(locale => locale !== request.i18n.getLocale()) pageData.backRef = await getBackReference(request, view) pageData.uri = { ...(pageData.uri || {}), analyticsFormAction: addLanguageCodeToUri(request, PROCESS_ANALYTICS_PREFERENCES.uri) } - pageData.pageLanguageSetToWelsh = pageLanguageSetToWelsh(request) + pageData.pageLanguageSetToWelsh = welshEnabledAndApplied(request) const analytics = await request.cache().helpers.analytics.get() pageData.analyticsMessageDisplayed = analytics ? analytics[ANALYTICS.seenMessage] : false diff --git a/packages/gafl-webapp-service/src/pages/layout/layout.njk b/packages/gafl-webapp-service/src/pages/layout/layout.njk index 515e1bab90..8ab18eb601 100644 --- a/packages/gafl-webapp-service/src/pages/layout/layout.njk +++ b/packages/gafl-webapp-service/src/pages/layout/layout.njk @@ -42,7 +42,7 @@ {{ mssgs.analytics_banner_preamble_1 }}
- {{ mssgs.analytics_banner_preamble_2 }} {{ mssgs.cookie_banner_link }} + {{ mssgs.analytics_banner_preamble_2 }} {{ mssgs.cookie_banner_link }}