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 }}

diff --git a/packages/gafl-webapp-service/src/processors/__tests__/page-language-helper.spec.js b/packages/gafl-webapp-service/src/processors/__tests__/page-language-helper.spec.js new file mode 100644 index 0000000000..1a3f820994 --- /dev/null +++ b/packages/gafl-webapp-service/src/processors/__tests__/page-language-helper.spec.js @@ -0,0 +1,19 @@ +import { welshEnabledAndApplied } from '../page-language-helper.js' + +describe('welshEnabledAndApplied', () => { + describe('welshEnabledAndApplied', () => { + it('returns false when the lang is not set to cy', async () => { + const request = { query: { lang: 'en' } } + + const result = welshEnabledAndApplied(request) + expect(result).toEqual(false) + }) + + it('returns true when the lang is set to cy', async () => { + const request = { query: { lang: 'cy' } } + + const result = welshEnabledAndApplied(request) + expect(result).toEqual(true) + }) + }) +}) diff --git a/packages/gafl-webapp-service/src/processors/page-language-helper.js b/packages/gafl-webapp-service/src/processors/page-language-helper.js new file mode 100644 index 0000000000..2b7830d05d --- /dev/null +++ b/packages/gafl-webapp-service/src/processors/page-language-helper.js @@ -0,0 +1 @@ +export const welshEnabledAndApplied = request => request.query.lang === 'cy' diff --git a/packages/gafl-webapp-service/src/routes/__tests__/misc-routes-handlers.spec.js b/packages/gafl-webapp-service/src/routes/__tests__/misc-routes-handlers.spec.js index aef9db7358..8ac694baf3 100644 --- a/packages/gafl-webapp-service/src/routes/__tests__/misc-routes-handlers.spec.js +++ b/packages/gafl-webapp-service/src/routes/__tests__/misc-routes-handlers.spec.js @@ -2,6 +2,7 @@ import uri from '../../uri.js' import miscRoutes from '../misc-routes.js' import constants from '../../constants.js' import { addLanguageCodeToUri } from '../../processors/uri-helper.js' +import { welshEnabledAndApplied } from '../../processors/page-language-helper.js' jest.mock('../../uri.js', () => ({ ...jest.requireActual('../../uri.js'), @@ -20,6 +21,7 @@ jest.mock('../../constants.js', () => ({ })) jest.mock('../../processors/uri-helper.js') +jest.mock('../../processors/page-language-helper.js') describe('guidance page handlers', () => { const cookiesPageHandler = miscRoutes.find(r => r.path === uri.COOKIES.uri).handler @@ -215,7 +217,8 @@ describe('guidance page handlers', () => { { pageHandler: accessibilityPageHandler, handlerName: 'Accessibility' }, { pageHandler: privacyPolicyPageHandler, handlerName: 'Privacy policy' }, { pageHandler: refundPolicyPageHandler, handlerName: 'Refund policy' }, - { pageHandler: osTermsPageHandler, handlerName: 'OS Terms' } + { pageHandler: osTermsPageHandler, handlerName: 'OS Terms' }, + { pageHandler: newPricesPageHandler, handlerName: 'New Prices Page Handler' } ])('language code tests for $handlerName page', ({ pageHandler }) => { it('uses addLanguageCodeToUri to get back url', async () => { const toolkit = getMockToolkit() @@ -243,6 +246,22 @@ describe('guidance page handlers', () => { }) ) }) + + it('returns the value of welshEnabledAndApplied for pageLanguageSetToWelsh', async () => { + const toolkit = getMockToolkit() + const request = getMockRequest() + const expectedValue = Symbol('expected') + welshEnabledAndApplied.mockReturnValueOnce(expectedValue) + + await pageHandler(request, toolkit) + + expect(toolkit.view).toHaveBeenCalledWith( + expect.any(String), + expect.objectContaining({ + pageLanguageSetToWelsh: expectedValue + }) + ) + }) }) const getMockRequest = (i18nValues, search = '') => { diff --git a/packages/gafl-webapp-service/src/routes/misc-routes.js b/packages/gafl-webapp-service/src/routes/misc-routes.js index 4f0e12c7bd..3fa37ae8e4 100644 --- a/packages/gafl-webapp-service/src/routes/misc-routes.js +++ b/packages/gafl-webapp-service/src/routes/misc-routes.js @@ -24,6 +24,7 @@ import controllerHandler from '../handlers/controller-handler.js' import authenticationHandler from '../handlers/authentication-handler.js' import { addLanguageCodeToUri } from '../processors/uri-helper.js' import analytics from '../handlers/analytics-handler.js' +import { welshEnabledAndApplied } from '../processors/page-language-helper.js' const simpleView = view => ({ method: 'GET', @@ -31,9 +32,11 @@ const simpleView = view => ({ handler: async (request, h) => { const mssgs = request.i18n.getCatalog() const altLang = request.i18n.getLocales().filter(locale => locale !== request.i18n.getLocale()) + const pageLanguageSetToWelsh = welshEnabledAndApplied(request) return h.view(view.page, { mssgs, altLang, + pageLanguageSetToWelsh, uri: { back: addLanguageCodeToUri(request, CONTROLLER.uri) } @@ -92,9 +95,11 @@ export default [ path: COOKIES.uri, handler: async (request, h) => { const altLang = request.i18n.getLocales().filter(locale => locale !== request.i18n.getLocale()) + const pageLanguageSetToWelsh = welshEnabledAndApplied(request) return h.view(COOKIES.page, { altLang, + pageLanguageSetToWelsh, mssgs: request.i18n.getCatalog(), cookie: { csrf: process.env.CSRF_TOKEN_COOKIE_NAME || CSRF_TOKEN_COOKIE_NAME_DEFAULT, @@ -113,9 +118,11 @@ export default [ path: NEW_PRICES.uri, handler: async (request, h) => { const altLang = request.i18n.getLocales().filter(locale => locale !== request.i18n.getLocale()) + const pageLanguageSetToWelsh = welshEnabledAndApplied(request) return h.view(NEW_PRICES.page, { altLang, + pageLanguageSetToWelsh, mssgs: request.i18n.getCatalog(), uri: { back: addLanguageCodeToUri(request, CONTROLLER.uri)