diff --git a/src/server/accessibility/controller.test.js b/src/server/accessibility/controller.test.js index 49d8f23b..98d44322 100644 --- a/src/server/accessibility/controller.test.js +++ b/src/server/accessibility/controller.test.js @@ -1,4 +1,4 @@ -import { accessibilityHandler } from './controller' +import { accessibilityController } from './controller' describe('Accessibility Handler', () => { const mockRequest = { @@ -26,14 +26,22 @@ describe('Accessibility Handler', () => { it('should redirect to the Welsh version if the language is "cy"', () => { mockRequest.query.lang = 'cy' - const result = accessibilityHandler(mockRequest, mockH, mockContent) + const result = accessibilityController.handler( + mockRequest, + mockH, + mockContent + ) expect(result).toBe('redirected') expect(mockH.redirect).toHaveBeenCalledWith('/hygyrchedd/cy?lang=cy') }) it('should render the accessibility page with the necessary data', () => { mockRequest.query.lang = 'en' - const result = accessibilityHandler(mockRequest, mockH, mockContent) + const result = accessibilityController.handler( + mockRequest, + mockH, + mockContent + ) expect(result).toBe('view rendered') expect(mockH.view).toHaveBeenCalledWith('accessibility/index', { pageTitle: 'mock pageTitle', diff --git a/src/server/accessibility/cy/controller.test.js b/src/server/accessibility/cy/controller.test.js index 76987cd3..64ed109d 100644 --- a/src/server/accessibility/cy/controller.test.js +++ b/src/server/accessibility/cy/controller.test.js @@ -1,4 +1,4 @@ -import { accessibilityHandler } from './controller' +import { accessibilityController } from './controller' describe('Accessibility Handler', () => { const mockRequest = { @@ -27,14 +27,46 @@ describe('Accessibility Handler', () => { it('should redirect to the English version if the language is "en"', () => { mockRequest.query.lang = 'en' - const result = accessibilityHandler(mockRequest, mockH, mockContent) + const result = accessibilityController.handler( + mockRequest, + mockH, + mockContent + ) expect(result).toBe('redirected') expect(mockH.redirect).toHaveBeenCalledWith('/accessibility?lang=en') }) it('should render the accessibility page with the necessary data', () => { mockRequest.query.lang = 'cy' - const result = accessibilityHandler(mockRequest, mockH, mockContent) + const result = accessibilityController.handler( + mockRequest, + mockH, + mockContent + ) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('accessibility/index', { + pageTitle: 'mock pageTitle', + title: 'mock title', + heading: 'mock heading', + headings: 'mock headings', + paragraphs: 'mock paragraphs', + displayBacklink: false, + phaseBanner: 'mock phaseBanner', + footerTxt: 'mock footerTxt', + serviceName: 'mock serviceName', + cookieBanner: 'mock cookieBanner', + lang: mockRequest.query.lang + }) + }) + + it('should render the accessibility page by Default to Welsh if language is not cy and en', () => { + mockRequest.query.lang = 'test' + mockRequest.path = '/preifatrwydd/cy' + const result = accessibilityController.handler( + mockRequest, + mockH, + mockContent + ) expect(result).toBe('view rendered') expect(mockH.view).toHaveBeenCalledWith('accessibility/index', { pageTitle: 'mock pageTitle', diff --git a/src/server/accessibility/cy/index.test.js b/src/server/accessibility/cy/index.test.js new file mode 100644 index 00000000..a5c002e3 --- /dev/null +++ b/src/server/accessibility/cy/index.test.js @@ -0,0 +1,12 @@ +import { accessibilityCy } from './index' + +describe('accessibility index plugin - cy', () => { + const server = { + route: jest.fn() + } + + test('should register accessibility route - cy', () => { + accessibilityCy.plugin.register(server) + expect(server.route).toHaveBeenCalled() + }) +}) diff --git a/src/server/accessibility/cy/routes.test.js b/src/server/accessibility/cy/routes.test.js new file mode 100644 index 00000000..bcb7fdca --- /dev/null +++ b/src/server/accessibility/cy/routes.test.js @@ -0,0 +1,16 @@ +import { routes } from './routes' +import { accessibilityController } from './controller' + +jest.mock('./controller') + +describe('Accessibility cy Routes', () => { + it('should define the accessibility route - cy', () => { + expect(routes).toEqual([ + { + method: 'GET', + path: '/hygyrchedd/cy', + ...accessibilityController + } + ]) + }) +}) diff --git a/src/server/accessibility/index.test.js b/src/server/accessibility/index.test.js new file mode 100644 index 00000000..1514427b --- /dev/null +++ b/src/server/accessibility/index.test.js @@ -0,0 +1,12 @@ +import { accessibility } from './index' + +describe('accessibility index plugin', () => { + const server = { + route: jest.fn() + } + + test('should register accessibility route', () => { + accessibility.plugin.register(server) + expect(server.route).toHaveBeenCalled() + }) +}) diff --git a/src/server/check-local-air-quality/controller.test.js b/src/server/check-local-air-quality/controller.test.js index 2744b5a2..476e3600 100644 --- a/src/server/check-local-air-quality/controller.test.js +++ b/src/server/check-local-air-quality/controller.test.js @@ -1,4 +1,4 @@ -import { handleHomeRequest } from '~/src/server/home/controller' +import { homeController } from './controller' import { english } from '~/src/server/data/en/en.js' describe('Home Controller', () => { @@ -18,14 +18,14 @@ describe('Home Controller', () => { it('should redirect to the Welsh version if the language is "cy"', () => { mockRequest.query.lang = 'cy' - const result = handleHomeRequest(mockRequest, mockH, mockContent) + const result = homeController.handler(mockRequest, mockH, mockContent) expect(result).toBe('redirected') expect(mockH.redirect).toHaveBeenCalledWith('cy') }) it('should render the home page with the necessary data', () => { mockRequest.query.lang = 'en' - const result = handleHomeRequest(mockRequest, mockH, mockContent) + const result = homeController.handler(mockRequest, mockH, mockContent) expect(result).toBe('view rendered') expect(mockH.view).toHaveBeenCalledWith('home/index', { pageTitle: mockContent.home.pageTitle, diff --git a/src/server/check-local-air-quality/cy/controller.test.js b/src/server/check-local-air-quality/cy/controller.test.js index b7443b92..4f7c2edd 100644 --- a/src/server/check-local-air-quality/cy/controller.test.js +++ b/src/server/check-local-air-quality/cy/controller.test.js @@ -1,5 +1,5 @@ // Generated by Copilot -import { handleHomeRequest } from '~/src/server/home/controller' +import { homeController } from './controller' import { welsh } from '~/src/server/data/cy/cy.js' describe('Home Controller', () => { @@ -19,14 +19,14 @@ describe('Home Controller', () => { }) it('should redirect to the English version if the language is "en"', () => { - mockRequest.query.lang = 'cy' - const result = handleHomeRequest(mockRequest, mockH, mockContent) + mockRequest.query.lang = 'en' + const result = homeController.handler(mockRequest, mockH, mockContent) expect(result).toBe('redirected') - expect(mockH.redirect).toHaveBeenCalledWith('cy') + expect(mockH.redirect).toHaveBeenCalledWith('/?lang=en') }) it('should render the home page with the necessary data', () => { - const result = handleHomeRequest(mockRequest, mockH, mockContent) + const result = homeController.handler(mockRequest, mockH, mockContent) expect(result).toBe('view rendered') expect(mockH.view).toHaveBeenCalledWith('home/index', { pageTitle: mockContent.home.pageTitle, @@ -39,7 +39,7 @@ describe('Home Controller', () => { backlink: mockContent.backlink, cookieBanner: mockContent.cookieBanner, serviceName: '', - lang: 'en' + lang: 'cy' }) }) }) diff --git a/src/server/check-local-air-quality/cy/index.test.js b/src/server/check-local-air-quality/cy/index.test.js new file mode 100644 index 00000000..75aecd3d --- /dev/null +++ b/src/server/check-local-air-quality/cy/index.test.js @@ -0,0 +1,12 @@ +import { homeCy } from './index' + +describe('homeCy index plugin - cy', () => { + const server = { + route: jest.fn() + } + + test('should register homeCy route - cy', () => { + homeCy.plugin.register(server) + expect(server.route).toHaveBeenCalled() + }) +}) diff --git a/src/server/check-local-air-quality/index.test.js b/src/server/check-local-air-quality/index.test.js new file mode 100644 index 00000000..28bb3541 --- /dev/null +++ b/src/server/check-local-air-quality/index.test.js @@ -0,0 +1,12 @@ +import { home } from './index' + +describe('home index plugin', () => { + const server = { + route: jest.fn() + } + + test('should register home route', () => { + home.plugin.register(server) + expect(server.route).toHaveBeenCalled() + }) +}) diff --git a/src/server/check-local-air-quality/routes.test.js b/src/server/check-local-air-quality/routes.test.js index 768ffb7e..07bbe6ea 100644 --- a/src/server/check-local-air-quality/routes.test.js +++ b/src/server/check-local-air-quality/routes.test.js @@ -1,5 +1,5 @@ -import { configureRoutes } from '~/src/server/home/routes' -import { homeController } from '~/src/server/home/controller' +import { configureRoutes } from './routes' +import { homeController } from './controller' describe('Route Configuration', () => { it('should configure the routes correctly', () => { diff --git a/src/server/cookies/controller.test.js b/src/server/cookies/controller.test.js index 6927dfc8..c9ab4182 100644 --- a/src/server/cookies/controller.test.js +++ b/src/server/cookies/controller.test.js @@ -1,4 +1,4 @@ -import { cookiesHandler } from '~/src/server/cookies/controller' +import { cookiesController } from './controller' import { welsh } from '~/src/server/data/cy/cy.js' describe('Cookies Handler', () => { @@ -19,14 +19,14 @@ describe('Cookies Handler', () => { it('should redirect to the Welsh version if the language is "cy"', () => { mockRequest.query.lang = 'cy' - const result = cookiesHandler(mockRequest, mockH, mockContent) + const result = cookiesController.handler(mockRequest, mockH, mockContent) expect(result).toBe('redirected') expect(mockH.redirect).toHaveBeenCalledWith('/briwsion/cy?lang=cy') }) it('should render the cookies page with the necessary data', () => { mockRequest.query.lang = 'en' - const result = cookiesHandler(mockRequest, mockH, mockContent) + const result = cookiesController.handler(mockRequest, mockH, mockContent) expect(result).toBe('view rendered') expect(mockH.view).toHaveBeenCalledWith('cookies/index', { pageTitle: mockContent.footer.cookies.pageTitle, @@ -41,14 +41,14 @@ describe('Cookies Handler', () => { footerTxt: mockContent.footerTxt, serviceName: mockContent.multipleLocations.serviceName, cookieBanner: mockContent.cookieBanner, - lang: 'en' + lang: mockRequest.query.lang }) }) it('should default to English if language is not "cy" or "en" and path is "/cookies"', () => { mockRequest.query.lang = 'fr' mockRequest.path = '/cookies' - const result = cookiesHandler(mockRequest, mockH, mockContent) + const result = cookiesController.handler(mockRequest, mockH, mockContent) expect(result).toBe('view rendered') expect(mockH.view).toHaveBeenCalledWith('cookies/index', { pageTitle: mockContent.footer.cookies.pageTitle, diff --git a/src/server/cookies/cy/controller.test.js b/src/server/cookies/cy/controller.test.js index fbbec442..598f1855 100644 --- a/src/server/cookies/cy/controller.test.js +++ b/src/server/cookies/cy/controller.test.js @@ -1,4 +1,4 @@ -import { cookiesHandler } from '~/src/server/cookies/controller' +import { cookiesController } from './controller' import { welsh } from '~/src/server/data/cy/cy.js' describe('Cookies Handler', () => { @@ -18,14 +18,15 @@ describe('Cookies Handler', () => { }) it('should redirect to the English version if the language is "en"', () => { - mockRequest.query.lang = 'cy' - const result = cookiesHandler(mockRequest, mockH, mockContent) + mockRequest.query.lang = 'en' + const result = cookiesController.handler(mockRequest, mockH, mockContent) expect(result).toBe('redirected') - expect(mockH.redirect).toHaveBeenCalledWith('/briwsion/cy?lang=cy') + expect(mockH.redirect).toHaveBeenCalledWith('/cookies?lang=en') }) it('should render the cookies page with the necessary data', () => { - const result = cookiesHandler(mockRequest, mockH, mockContent) + mockRequest.query.lang = 'cy' + const result = cookiesController.handler(mockRequest, mockH, mockContent) expect(result).toBe('view rendered') expect(mockH.view).toHaveBeenCalledWith('cookies/index', { pageTitle: mockContent.footer.cookies.pageTitle, @@ -39,14 +40,15 @@ describe('Cookies Handler', () => { phaseBanner: mockContent.phaseBanner, footerTxt: mockContent.footerTxt, serviceName: mockContent.multipleLocations.serviceName, - cookieBanner: mockContent.cookieBanner + cookieBanner: mockContent.cookieBanner, + lang: mockRequest.query.lang }) }) it('should default to Welsh if language is not "cy" or "en" and path is "/preifatrwydd/cy"', () => { mockRequest.query.lang = 'fr' mockRequest.path = '/preifatrwydd/cy' - const result = cookiesHandler(mockRequest, mockH, mockContent) + const result = cookiesController.handler(mockRequest, mockH, mockContent) expect(result).toBe('view rendered') expect(mockH.view).toHaveBeenCalledWith('cookies/index', { pageTitle: mockContent.footer.cookies.pageTitle, @@ -61,7 +63,7 @@ describe('Cookies Handler', () => { footerTxt: mockContent.footerTxt, serviceName: mockContent.multipleLocations.serviceName, cookieBanner: mockContent.cookieBanner, - lang: 'fr' + lang: 'cy' }) }) }) diff --git a/src/server/home/controller.test.js b/src/server/home/controller.test.js index 2744b5a2..476e3600 100644 --- a/src/server/home/controller.test.js +++ b/src/server/home/controller.test.js @@ -1,4 +1,4 @@ -import { handleHomeRequest } from '~/src/server/home/controller' +import { homeController } from './controller' import { english } from '~/src/server/data/en/en.js' describe('Home Controller', () => { @@ -18,14 +18,14 @@ describe('Home Controller', () => { it('should redirect to the Welsh version if the language is "cy"', () => { mockRequest.query.lang = 'cy' - const result = handleHomeRequest(mockRequest, mockH, mockContent) + const result = homeController.handler(mockRequest, mockH, mockContent) expect(result).toBe('redirected') expect(mockH.redirect).toHaveBeenCalledWith('cy') }) it('should render the home page with the necessary data', () => { mockRequest.query.lang = 'en' - const result = handleHomeRequest(mockRequest, mockH, mockContent) + const result = homeController.handler(mockRequest, mockH, mockContent) expect(result).toBe('view rendered') expect(mockH.view).toHaveBeenCalledWith('home/index', { pageTitle: mockContent.home.pageTitle, diff --git a/src/server/home/cy/controller.test.js b/src/server/home/cy/controller.test.js index b7443b92..4f7c2edd 100644 --- a/src/server/home/cy/controller.test.js +++ b/src/server/home/cy/controller.test.js @@ -1,5 +1,5 @@ // Generated by Copilot -import { handleHomeRequest } from '~/src/server/home/controller' +import { homeController } from './controller' import { welsh } from '~/src/server/data/cy/cy.js' describe('Home Controller', () => { @@ -19,14 +19,14 @@ describe('Home Controller', () => { }) it('should redirect to the English version if the language is "en"', () => { - mockRequest.query.lang = 'cy' - const result = handleHomeRequest(mockRequest, mockH, mockContent) + mockRequest.query.lang = 'en' + const result = homeController.handler(mockRequest, mockH, mockContent) expect(result).toBe('redirected') - expect(mockH.redirect).toHaveBeenCalledWith('cy') + expect(mockH.redirect).toHaveBeenCalledWith('/?lang=en') }) it('should render the home page with the necessary data', () => { - const result = handleHomeRequest(mockRequest, mockH, mockContent) + const result = homeController.handler(mockRequest, mockH, mockContent) expect(result).toBe('view rendered') expect(mockH.view).toHaveBeenCalledWith('home/index', { pageTitle: mockContent.home.pageTitle, @@ -39,7 +39,7 @@ describe('Home Controller', () => { backlink: mockContent.backlink, cookieBanner: mockContent.cookieBanner, serviceName: '', - lang: 'en' + lang: 'cy' }) }) }) diff --git a/src/server/nitrogen-dioxide/cy/controller.test.js b/src/server/nitrogen-dioxide/cy/controller.test.js index 1733d5b1..460bb888 100644 --- a/src/server/nitrogen-dioxide/cy/controller.test.js +++ b/src/server/nitrogen-dioxide/cy/controller.test.js @@ -8,7 +8,8 @@ describe('Nitrogen Dioxide Controller - Welsh', () => { const { nitrogenDioxide } = welsh.pollutants beforeEach(() => { mockRequest = { - query: {} + query: {}, + path: {} } mockH = { redirect: jest.fn().mockReturnValue('redirected'), @@ -41,4 +42,22 @@ describe('Nitrogen Dioxide Controller - Welsh', () => { lang: mockRequest.query.lang }) }) + + it('should redirect to the welsh version if the language is not equal to "en" and "cy"', () => { + mockRequest.query.lang = 'test' + mockRequest.path = '/llygryddion/oson/cy' + const result = nitrogenDioxideController.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('nitrogen-dioxide/index', { + pageTitle: mockContent.pollutants.nitrogenDioxide.pageTitle, + nitrogenDioxide, + page: 'Nitrogen dioxide (NO₂)', + displayBacklink: false, + phaseBanner: mockContent.phaseBanner, + footerTxt: mockContent.footerTxt, + cookieBanner: mockContent.cookieBanner, + serviceName: mockContent.multipleLocations.serviceName, + lang: 'cy' + }) + }) }) diff --git a/src/server/ozone/cy/controller.test.js b/src/server/ozone/cy/controller.test.js index 98dd33a6..0c9c80c4 100644 --- a/src/server/ozone/cy/controller.test.js +++ b/src/server/ozone/cy/controller.test.js @@ -40,4 +40,22 @@ describe('Ozone Controller - Welsh', () => { lang: mockRequest.query.lang }) }) + + it('should render the ozone cy page with the necessary data if lang is not cy | en', () => { + mockRequest.query.lang = 'test' + mockRequest.path = '/chwilio-lleoliad/cy' + const result = ozoneController.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('ozone/index', { + pageTitle: mockContent.pollutants.ozone.pageTitle, + ozone, + page: 'ozone-cy', + displayBacklink: false, + phaseBanner: mockContent.phaseBanner, + footerTxt: mockContent.footerTxt, + cookieBanner: mockContent.cookieBanner, + serviceName: mockContent.multipleLocations.serviceName, + lang: 'cy' + }) + }) }) diff --git a/src/server/particulate-matter-10/cy/controller.test.js b/src/server/particulate-matter-10/cy/controller.test.js index 589366ad..701fc673 100644 --- a/src/server/particulate-matter-10/cy/controller.test.js +++ b/src/server/particulate-matter-10/cy/controller.test.js @@ -8,7 +8,8 @@ describe('Particular matter10 Controller - Welsh', () => { const { particulateMatter10 } = welsh.pollutants beforeEach(() => { mockRequest = { - query: {} + query: {}, + path: '' } mockH = { redirect: jest.fn().mockReturnValue('redirected'), @@ -41,4 +42,22 @@ describe('Particular matter10 Controller - Welsh', () => { lang: mockRequest.query.lang }) }) + + it('should render by default to particulateMatter10 cy page if lang is not cy or en', () => { + mockRequest.query.lang = 'test' + mockRequest.path = '/llygryddion/mater-gronynnol-10/cy' + const result = particulateMatter10Controller.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('particulate-matter-10/index', { + pageTitle: mockContent.pollutants.particulateMatter10.pageTitle, + particulateMatter10, + page: 'particulate matter 10', + displayBacklink: false, + phaseBanner: mockContent.phaseBanner, + footerTxt: mockContent.footerTxt, + cookieBanner: mockContent.cookieBanner, + serviceName: mockContent.multipleLocations.serviceName, + lang: 'cy' + }) + }) }) diff --git a/src/server/particulate-matter-25/cy/controller.test.js b/src/server/particulate-matter-25/cy/controller.test.js index 78f2c80e..829229af 100644 --- a/src/server/particulate-matter-25/cy/controller.test.js +++ b/src/server/particulate-matter-25/cy/controller.test.js @@ -8,7 +8,8 @@ describe('Particular matter25 Controller - English', () => { const { particulateMatter25 } = welsh.pollutants beforeEach(() => { mockRequest = { - query: {} + query: {}, + path: '' } mockH = { redirect: jest.fn().mockReturnValue('redirected'), @@ -41,4 +42,22 @@ describe('Particular matter25 Controller - English', () => { lang: mockRequest.query.lang }) }) + + it('should render by default to particulateMatter25 page if lang is not cy or en', () => { + mockRequest.query.lang = 'test' + mockRequest.path = '/chwilio-lleoliad/cy' + const result = particulateMatter25Controller.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('particulate-matter-25/index', { + pageTitle: mockContent.pollutants.particulateMatter25.pageTitle, + particulateMatter25, + page: 'particulate matter 25', + displayBacklink: false, + phaseBanner: mockContent.phaseBanner, + footerTxt: mockContent.footerTxt, + cookieBanner: mockContent.cookieBanner, + serviceName: mockContent.multipleLocations.serviceName, + lang: 'cy' + }) + }) }) diff --git a/src/server/privacy/controller.test.js b/src/server/privacy/controller.test.js new file mode 100644 index 00000000..a0f3e1e9 --- /dev/null +++ b/src/server/privacy/controller.test.js @@ -0,0 +1,44 @@ +import { english } from '../data/en/en.js' +import { privacyController } from './controller.js' + +describe('privacy controller - English', () => { + let mockRequest + let mockH + const mockContent = english + beforeEach(() => { + mockRequest = { + query: {} + } + mockH = { + redirect: jest.fn().mockReturnValue('redirected'), + view: jest.fn().mockReturnValue('view rendered') + } + }) + + it('should redirect to the Welsh version if the language is "cy"', () => { + mockRequest.query.lang = 'cy' + const result = privacyController.handler(mockRequest, mockH) + expect(result).toBe('redirected') + expect(mockH.redirect).toHaveBeenCalledWith('/preifatrwydd/cy?lang=cy') + }) + + it('should render the privacy page with the necessary data', () => { + mockRequest.query.lang = 'en' + const result = privacyController.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('privacy/index', { + pageTitle: mockContent.footer.privacy.pageTitle, + title: mockContent.footer.privacy.title, + heading: mockContent.footer.privacy.heading, + headings: mockContent.footer.privacy.headings, + paragraphs: mockContent.footer.privacy.paragraphs, + displayBacklink: false, + phaseBanner: mockContent.phaseBanner, + footerTxt: mockContent.footerTxt, + cookieBanner: mockContent.cookieBanner, + serviceName: mockContent.multipleLocations.serviceName, + page: 'privacy', + lang: mockRequest.query.lang + }) + }) +}) diff --git a/src/server/privacy/cy/controller.test.js b/src/server/privacy/cy/controller.test.js new file mode 100644 index 00000000..8ba6f928 --- /dev/null +++ b/src/server/privacy/cy/controller.test.js @@ -0,0 +1,66 @@ +import { welsh } from '../../data/cy/cy.js' +import { privacyController } from './controller.js' + +describe('privacy controller - Welsh', () => { + let mockRequest + let mockH + const mockContent = welsh + beforeEach(() => { + mockRequest = { + query: {}, + path: '' + } + mockH = { + redirect: jest.fn().mockReturnValue('redirected'), + view: jest.fn().mockReturnValue('view rendered') + } + }) + + it('should redirect to the english version if the language is "en"', () => { + mockRequest.query.lang = 'en' + const result = privacyController.handler(mockRequest, mockH) + expect(result).toBe('redirected') + expect(mockH.redirect).toHaveBeenCalledWith('/privacy?lang=en') + }) + + it('should render the privacy page with the necessary data', () => { + mockRequest.query.lang = 'cy' + const result = privacyController.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('privacy/index', { + pageTitle: mockContent.footer.privacy.pageTitle, + title: mockContent.footer.privacy.title, + heading: mockContent.footer.privacy.heading, + headings: mockContent.footer.privacy.headings, + paragraphs: mockContent.footer.privacy.paragraphs, + displayBacklink: false, + phaseBanner: mockContent.phaseBanner, + footerTxt: mockContent.footerTxt, + cookieBanner: mockContent.cookieBanner, + serviceName: mockContent.multipleLocations.serviceName, + page: 'privacy', + lang: mockRequest.query.lang + }) + }) + + it('should render the privacy page by default when lang is not cy/en and the path is there', () => { + mockRequest.query.lang = 'su' + mockRequest.path = '/preifatrwydd/cy' + const result = privacyController.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('privacy/index', { + pageTitle: mockContent.footer.privacy.pageTitle, + title: mockContent.footer.privacy.title, + heading: mockContent.footer.privacy.heading, + headings: mockContent.footer.privacy.headings, + paragraphs: mockContent.footer.privacy.paragraphs, + displayBacklink: false, + phaseBanner: mockContent.phaseBanner, + footerTxt: mockContent.footerTxt, + cookieBanner: mockContent.cookieBanner, + serviceName: mockContent.multipleLocations.serviceName, + page: 'privacy', + lang: 'cy' + }) + }) +}) diff --git a/src/server/privacy/cy/index.test.js b/src/server/privacy/cy/index.test.js new file mode 100644 index 00000000..ff591be5 --- /dev/null +++ b/src/server/privacy/cy/index.test.js @@ -0,0 +1,30 @@ +import { privacyCy } from './index.js' +import { privacyController } from './controller' +import Hapi from '@hapi/hapi' + +describe('privacy index plugin - cy', () => { + let server + + beforeAll(async () => { + server = Hapi.server() + await privacyCy.plugin.register(server) + }) + + beforeEach(() => { + jest.mock('./controller', () => ({ + privacyController: { + handler: jest.fn(), + options: {} + } + })) + }) + + test('should register privacy route - cy', () => { + const routes = server.table() + const privacyRoute = routes.find( + (routes) => routes.path === '/preifatrwydd/cy' && routes.method === 'get' + ) + expect(privacyRoute).toBeDefined() + expect(privacyRoute.settings.handler).toBe(privacyController.handler) + }) +}) diff --git a/src/server/privacy/index.test.js b/src/server/privacy/index.test.js new file mode 100644 index 00000000..6a8afc64 --- /dev/null +++ b/src/server/privacy/index.test.js @@ -0,0 +1,30 @@ +import { privacy } from './index.js' +import { privacyController } from './controller' +import Hapi from '@hapi/hapi' + +describe('privacy index plugin - en', () => { + let server + + beforeAll(async () => { + server = Hapi.server() + await privacy.plugin.register(server) + }) + + beforeEach(() => { + jest.mock('./controller', () => ({ + privacyController: { + handler: jest.fn(), + options: {} + } + })) + }) + + test('should register privacy route - en', () => { + const routes = server.table() + const privacyRoute = routes.find( + (routes) => routes.path === '/privacy' && routes.method === 'get' + ) + expect(privacyRoute).toBeDefined() + expect(privacyRoute.settings.handler).toBe(privacyController.handler) + }) +}) diff --git a/src/server/search-location/controller.test.js b/src/server/search-location/controller.test.js new file mode 100644 index 00000000..1489306d --- /dev/null +++ b/src/server/search-location/controller.test.js @@ -0,0 +1,146 @@ +/* eslint-disable */ +import { english } from '../data/en/en.js' +import { searchLocationController } from './controller.js' + +describe('searchLocationController - english', () => { + let mockRequest + let mockH + const mockContent = english + + beforeEach(() => { + mockRequest = { + query: {}, + path: '', + yar: { + set: jest.fn(), + get: jest.fn() + } + } + mockH = { + redirect: jest.fn().mockReturnValue('redirected'), + view: jest.fn().mockReturnValue('view rendered') + } + }) + + it('should redirect to the Welsh version if the language is "cy"', () => { + mockRequest.query.lang = 'cy' + const result = searchLocationController.handler(mockRequest, mockH) + expect(result).toBe('redirected') + expect(mockH.redirect).toHaveBeenCalledWith('/chwilio-lleoliad/cy?lang=cy') + }) + + it('should redirect to search location index page', () => { + mockRequest.query.lang = 'en' + const result = searchLocationController.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('search-location/index', { + pageTitle: mockContent.searchLocation.pageTitle, + heading: mockContent.searchLocation.heading, + page: mockContent.searchLocation.page, + serviceName: mockContent.searchLocation.serviceName, + searchParams: { + label: { + text: mockContent.searchLocation.searchParams.label.text, + classes: 'govuk-label--l govuk-!-margin-bottom-6', + isPageHeading: true + }, + hint: { + text: mockContent.searchLocation.searchParams.hint.text2 + }, + id: 'location', + name: 'location' + }, + locations: mockContent.searchLocation.searchParams.locations, + button: mockContent.searchLocation.button, + footerTxt: mockContent.footerTxt, + phaseBanner: mockContent.phaseBanner, + backlink: mockContent.backlink, + cookieBanner: mockContent.cookieBanner, + lang: mockRequest.query.lang + }) + }) + + it('should redirect by default to search location index page with english version if lang is not cy/en', () => { + mockRequest.query.lang = 'fr' + mockRequest.path = '/search-location' + const result = searchLocationController.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('search-location/index', { + pageTitle: mockContent.searchLocation.pageTitle, + heading: mockContent.searchLocation.heading, + page: mockContent.searchLocation.page, + serviceName: mockContent.searchLocation.serviceName, + searchParams: { + label: { + text: mockContent.searchLocation.searchParams.label.text, + classes: 'govuk-label--l govuk-!-margin-bottom-6', + isPageHeading: true + }, + hint: { + text: mockContent.searchLocation.searchParams.hint.text2 + }, + id: 'location', + name: 'location' + }, + locations: mockContent.searchLocation.searchParams.locations, + button: mockContent.searchLocation.button, + footerTxt: mockContent.footerTxt, + phaseBanner: mockContent.phaseBanner, + backlink: mockContent.backlink, + cookieBanner: mockContent.cookieBanner, + lang: 'en' + }) + }) + + it('should redirect to search location index page with error', () => { + mockRequest.query.lang = 'en' + const errors = { titleText: 'There is a problem' } + const errorMessage = { text: 'Select where you want to check' } + const mrequest = { + yar: { + get: jest.fn((key) => { + if (key === 'errors') { + return { errors: { titleText: 'There is a problem' } } + } else if (key === 'errorMessage') { + return { errorMessage: { text: 'Select where you want to check' } } + } else { + return null + } + }), + set: jest.fn() + }, + query: { lang: 'en' } + } + const result = searchLocationController.handler(mrequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('search-location/index', { + pageTitle: `Error: ${mockContent.searchLocation.pageTitle}`, + heading: mockContent.searchLocation.heading, + page: mockContent.searchLocation.page, + serviceName: mockContent.searchLocation.serviceName, + searchParams: { + label: { + text: mockContent.searchLocation.searchParams.label.text, + classes: 'govuk-label--l govuk-!-margin-bottom-6', + isPageHeading: true + }, + hint: { + text: mockContent.searchLocation.searchParams.hint.text1 + }, + id: 'location', + name: 'location' + }, + locations: mockContent.searchLocation.searchParams.locations, + button: mockContent.searchLocation.button, + locationType: null, + errors: errors, + errorMessage: errorMessage, + errorMessageRadio: errorMessage, + footerTxt: mockContent.footerTxt, + phaseBanner: mockContent.phaseBanner, + backlink: mockContent.backlink, + cookieBanner: mockContent.cookieBanner, + lang: mockRequest.query.lang + }) + }) +}) diff --git a/src/server/search-location/cy/controller.test.js b/src/server/search-location/cy/controller.test.js new file mode 100644 index 00000000..6abc4f8b --- /dev/null +++ b/src/server/search-location/cy/controller.test.js @@ -0,0 +1,146 @@ +/* eslint-disable */ +import { welsh } from '../../data/cy/cy.js' +import { searchLocationController } from './controller.js' + +describe('searchLocationController - welsh', () => { + let mockRequest + let mockH + const mockContent = welsh + + beforeEach(() => { + mockRequest = { + query: {}, + path: '', + yar: { + set: jest.fn(), + get: jest.fn() + } + } + mockH = { + redirect: jest.fn().mockReturnValue('redirected'), + view: jest.fn().mockReturnValue('view rendered') + } + }) + + it('should redirect to the Welsh version if the language is "en"', () => { + mockRequest.query.lang = 'en' + const result = searchLocationController.handler(mockRequest, mockH) + expect(result).toBe('redirected') + expect(mockH.redirect).toHaveBeenCalledWith('/search-location?lang=en') + }) + + it('should redirect by default to search location index page with welsh version if lang is not cy/en', () => { + mockRequest.query.lang = 'fr' + mockRequest.path = '/chwilio-lleoliad/cy' + const result = searchLocationController.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('search-location/index', { + pageTitle: mockContent.searchLocation.pageTitle, + heading: mockContent.searchLocation.heading, + page: mockContent.searchLocation.page, + serviceName: mockContent.searchLocation.serviceName, + searchParams: { + label: { + text: mockContent.searchLocation.searchParams.label.text, + classes: 'govuk-label--l govuk-!-margin-bottom-6', + isPageHeading: true + }, + hint: { + text: mockContent.searchLocation.searchParams.hint.text2 + }, + id: 'location', + name: 'location' + }, + locations: mockContent.searchLocation.searchParams.locations, + button: mockContent.searchLocation.button, + footerTxt: mockContent.footerTxt, + phaseBanner: mockContent.phaseBanner, + backlink: mockContent.backlink, + cookieBanner: mockContent.cookieBanner, + lang: 'cy' + }) + }) + + it('should redirect to search location index page', () => { + mockRequest.query.lang = 'cy' + const result = searchLocationController.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('search-location/index', { + pageTitle: mockContent.searchLocation.pageTitle, + heading: mockContent.searchLocation.heading, + page: mockContent.searchLocation.page, + serviceName: mockContent.searchLocation.serviceName, + searchParams: { + label: { + text: mockContent.searchLocation.searchParams.label.text, + classes: 'govuk-label--l govuk-!-margin-bottom-6', + isPageHeading: true + }, + hint: { + text: mockContent.searchLocation.searchParams.hint.text2 + }, + id: 'location', + name: 'location' + }, + locations: mockContent.searchLocation.searchParams.locations, + button: mockContent.searchLocation.button, + footerTxt: mockContent.footerTxt, + phaseBanner: mockContent.phaseBanner, + backlink: mockContent.backlink, + cookieBanner: mockContent.cookieBanner, + lang: mockRequest.query.lang + }) + }) + + it.skip('should redirect to search location index page with error', () => { + mockRequest.query.lang = 'cy' + const errors = { titleText: 'There is a problem' } + const errorMessage = { text: 'Select where you want to check' } + const mrequest = { + yar: { + get: jest.fn((key) => { + if (key === 'errors') { + return { errors: errors } + } else if (key === 'errorMessage') { + return { errorMessage: { errorMessage } } + } else { + return null + } + }), + set: jest.fn() + }, + query: { lang: 'en' } + } + const result = searchLocationController.handler(mrequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('search-location/index', { + pageTitle: `Gwall: ${mockContent.searchLocation.pageTitle}`, + heading: mockContent.searchLocation.heading, + page: mockContent.searchLocation.page, + serviceName: mockContent.searchLocation.serviceName, + searchParams: { + label: { + text: mockContent.searchLocation.searchParams.label.text, + classes: 'govuk-label--l govuk-!-margin-bottom-6', + isPageHeading: true + }, + hint: { + text: mockContent.searchLocation.searchParams.hint.text1 + }, + id: 'location', + name: 'location' + }, + locations: mockContent.searchLocation.searchParams.locations, + button: mockContent.searchLocation.button, + locationType: null, + errors: errors, + errorMessage: errorMessage, + errorMessageRadio: errorMessage, + footerTxt: mockContent.footerTxt, + phaseBanner: mockContent.phaseBanner, + backlink: mockContent.backlink, + cookieBanner: mockContent.cookieBanner, + lang: mockRequest.query.lang + }) + }) +}) diff --git a/src/server/search-location/cy/index.test.js b/src/server/search-location/cy/index.test.js new file mode 100644 index 00000000..ed3e095a --- /dev/null +++ b/src/server/search-location/cy/index.test.js @@ -0,0 +1,33 @@ +import { searchLocationController } from './controller' +import { searchLocationCy } from './index.js' +import Hapi from '@hapi/hapi' + +describe('search location index plugin - cy', () => { + let server + + beforeAll(async () => { + server = Hapi.server() + await searchLocationCy.plugin.register(server) + }) + + beforeEach(() => { + jest.mock('./controller', () => ({ + searchLocationController: { + handler: jest.fn(), + options: {} + } + })) + }) + + test('should register search location route', () => { + const routes = server.table() + const searchLocationRoute = routes.find( + (routes) => + routes.path === '/chwilio-lleoliad/cy' && routes.method === 'get' + ) + expect(searchLocationRoute).toBeDefined() + expect(searchLocationRoute.settings.handler).toBe( + searchLocationController.handler + ) + }) +}) diff --git a/src/server/search-location/index.test.js b/src/server/search-location/index.test.js new file mode 100644 index 00000000..1dc5b62d --- /dev/null +++ b/src/server/search-location/index.test.js @@ -0,0 +1,32 @@ +import { searchLocationController } from './controller' +import { searchLocation } from './index.js' +import Hapi from '@hapi/hapi' + +describe('search location index plugin - en', () => { + let server + + beforeAll(async () => { + server = Hapi.server() + await searchLocation.plugin.register(server) + }) + + beforeEach(() => { + jest.mock('./controller', () => ({ + searchLocationController: { + handler: jest.fn(), + options: {} + } + })) + }) + + test('should register search location route', () => { + const routes = server.table() + const searchLocationRoute = routes.find( + (routes) => routes.path === '/search-location' && routes.method === 'get' + ) + expect(searchLocationRoute).toBeDefined() + expect(searchLocationRoute.settings.handler).toBe( + searchLocationController.handler + ) + }) +}) diff --git a/src/server/sulphur-dioxide/cy/controller.test.js b/src/server/sulphur-dioxide/cy/controller.test.js index 20daf00c..a19fffec 100644 --- a/src/server/sulphur-dioxide/cy/controller.test.js +++ b/src/server/sulphur-dioxide/cy/controller.test.js @@ -8,7 +8,8 @@ describe('sulphurDioxide Controller - Welsh', () => { const { sulphurDioxide } = welsh.pollutants beforeEach(() => { mockRequest = { - query: {} + query: {}, + path: '' } mockH = { redirect: jest.fn().mockReturnValue('redirected'), @@ -41,4 +42,22 @@ describe('sulphurDioxide Controller - Welsh', () => { lang: mockRequest.query.lang }) }) + + it('should render by default to sulphurDioxide welsh page if lang is not cy or en', () => { + mockRequest.query.lang = 'test' + mockRequest.path = '/llygryddion/sylffwr-deuocsid/cy' + const result = sulphurDioxideController.handler(mockRequest, mockH) + expect(result).toBe('view rendered') + expect(mockH.view).toHaveBeenCalledWith('sulphur-dioxide/index', { + pageTitle: mockContent.pollutants.sulphurDioxide.pageTitle, + sulphurDioxide, + page: 'Sulphur dioxide (SO₂)', + displayBacklink: false, + phaseBanner: mockContent.phaseBanner, + footerTxt: mockContent.footerTxt, + cookieBanner: mockContent.cookieBanner, + serviceName: mockContent.multipleLocations.serviceName, + lang: 'cy' + }) + }) })