diff --git a/lib/manage-prototype-handlers.js b/lib/manage-prototype-handlers.js index 967490d6aa..0e8286c74e 100644 --- a/lib/manage-prototype-handlers.js +++ b/lib/manage-prototype-handlers.js @@ -91,7 +91,7 @@ function getCsrfTokenHandler (req, res) { // Clear all data in session function getClearDataHandler (req, res) { - res.send(nunjucksManagementEnv.render(getManagementView('clear-data.njk'))) + res.send(nunjucksManagementEnv.render(getManagementView('clear-data.njk'), req.app.locals)) } function postClearDataHandler (req, res) { @@ -103,7 +103,7 @@ function postClearDataHandler (req, res) { function getPasswordHandler (req, res) { const returnURL = req.query.returnURL || '/' const error = req.query.error - res.send(nunjucksManagementEnv.render(getManagementView('password.njk'), { returnURL, error })) + res.send(nunjucksManagementEnv.render(getManagementView('password.njk'), { ...req.app.locals, returnURL, error })) } // Check authentication password @@ -133,7 +133,7 @@ function developmentOnlyMiddleware (req, res, next) { if (config.getConfig().isDevelopment || req.url.startsWith('/dependencies/govuk-frontend')) { next() } else { - res.send(nunjucksManagementEnv.render(getManagementView('manage-prototype-not-available.njk'))) + res.send(nunjucksManagementEnv.render(getManagementView('manage-prototype-not-available.njk'), req.app.locals)) } } @@ -181,6 +181,7 @@ async function getHomeHandler (req, res) { const kitPackage = await lookupPackageInfo('govuk-prototype-kit') const viewData = { + ...req.app.locals, currentUrl: req.originalUrl, currentSection: pageName, links: managementLinks, @@ -251,6 +252,7 @@ async function getTemplatesHandler (req, res) { } res.send(nunjucksManagementEnv.render(getManagementView('templates.njk'), { + ...req.app.locals, currentSection: pageName, links: managementLinks, availableTemplates, @@ -303,6 +305,7 @@ function getTemplatesInstallHandler (req, res) { if (templateConfig) { res.send(nunjucksManagementEnv.render(getManagementView('template-install.njk'), { + ...req.app.locals, currentSection: 'Templates', pageName: `Create new ${templateConfig.name}`, currentUrl: req.originalUrl, @@ -392,6 +395,7 @@ function getTemplatesPostInstallHandler (req, res) { const chosenUrl = req.query['chosen-url'] res.send(nunjucksManagementEnv.render(getManagementView('template-post-install.njk'), { + ...req.app.locals, currentSection: 'Templates', pageName, links: managementLinks, @@ -520,6 +524,7 @@ async function getPluginsHandler (req, res) { const foundMessage = found === 1 ? found + ' Plugin found' : found + ' Plugins found' const updatesMessage = updates ? updates === 1 ? updates + ' UPDATE AVAILABLE' : updates + ' UPDATES AVAILABLE' : '' const model = { + ...req.app.locals, currentSection: pageName, links: managementLinks, isInstalledPage, @@ -626,6 +631,7 @@ async function getPluginsModeHandler (req, res) { } res.send(nunjucksManagementEnv.render(getManagementView('plugin-install-or-uninstall.njk'), { + ...req.app.locals, currentSection: 'Plugins', pageName, currentUrl: req.originalUrl, diff --git a/lib/manage-prototype-handlers.test.js b/lib/manage-prototype-handlers.test.js index affaea9646..83325caaa1 100644 --- a/lib/manage-prototype-handlers.test.js +++ b/lib/manage-prototype-handlers.test.js @@ -131,6 +131,11 @@ describe('manage-prototype-handlers', () => { fse.exists.mockResolvedValue(true) fse.readJsonSync.mockReturnValue({}) req = { + app: { + locals: { + serviceName: 'Service name goes here' + } + }, headers: {}, body: {}, query: {}, @@ -154,7 +159,8 @@ describe('manage-prototype-handlers', () => { it('getClearDataHandler', () => { getClearDataHandler(req, res) expect(mockNunjucksRender).toHaveBeenCalledWith( - 'views/manage-prototype/clear-data.njk' + 'views/manage-prototype/clear-data.njk', + req.app.locals ) }) @@ -174,7 +180,11 @@ describe('manage-prototype-handlers', () => { getPasswordHandler(req, res) expect(mockNunjucksRender).toHaveBeenCalledWith( 'views/manage-prototype/password.njk', - { error: undefined, returnURL: '/' } + expect.objectContaining({ + ...req.app.locals, + error: undefined, + returnURL: '/' + }) ) }) @@ -207,7 +217,11 @@ describe('manage-prototype-handlers', () => { await getHomeHandler(req, res) expect(mockNunjucksRender).toHaveBeenCalledWith( 'views/manage-prototype/index.njk', - expect.objectContaining({ currentSection: 'Home', latestAvailableKit: '1.0.0' }) + expect.objectContaining({ + ...req.app.locals, + currentSection: 'Home', + latestAvailableKit: '1.0.0' + }) ) }) @@ -215,7 +229,8 @@ describe('manage-prototype-handlers', () => { it('in production', () => { developmentOnlyMiddleware(req, res, next) expect(mockNunjucksRender).toHaveBeenCalledWith( - 'views/manage-prototype/manage-prototype-not-available.njk' + 'views/manage-prototype/manage-prototype-not-available.njk', + req.app.locals ) }) @@ -253,6 +268,7 @@ describe('manage-prototype-handlers', () => { expect(mockNunjucksRender).toHaveBeenCalledWith( 'views/manage-prototype/templates.njk', expect.objectContaining({ + ...req.app.locals, currentSection: 'Templates', availableTemplates: [{ packageName, @@ -275,6 +291,7 @@ describe('manage-prototype-handlers', () => { expect(mockNunjucksRender).toHaveBeenCalledWith( path.join(packageName, templatePath), expect.objectContaining({ + ...req.app.locals, serviceName: 'Service name goes here' }) ) @@ -300,6 +317,7 @@ describe('manage-prototype-handlers', () => { expect(mockNunjucksRender).toHaveBeenCalledWith( 'views/manage-prototype/template-install.njk', expect.objectContaining({ + ...req.app.locals, currentSection: 'Templates', pageName: 'Create new A page with everything', chosenUrl, @@ -393,6 +411,7 @@ describe('manage-prototype-handlers', () => { expect(mockNunjucksRender).toHaveBeenCalledWith( 'views/manage-prototype/template-post-install.njk', expect.objectContaining({ + ...req.app.locals, currentSection: 'Templates', pageName: 'Page created', filePath: path.join(`app/views${chosenUrl}.html`) @@ -445,6 +464,7 @@ describe('manage-prototype-handlers', () => { expect(mockNunjucksRender).toHaveBeenCalledWith( 'views/manage-prototype/plugins.njk', expect.objectContaining({ + ...req.app.locals, currentSection: 'Plugins', isSearchPage: false, isInstalledPage: true, @@ -460,6 +480,7 @@ describe('manage-prototype-handlers', () => { expect(mockNunjucksRender).toHaveBeenCalledWith( 'views/manage-prototype/plugins.njk', expect.objectContaining({ + ...req.app.locals, currentSection: 'Plugins', isSearchPage: true, isInstalledPage: false, @@ -488,6 +509,7 @@ describe('manage-prototype-handlers', () => { expect(mockNunjucksRender).toHaveBeenCalledWith( 'views/manage-prototype/plugin-install-or-uninstall.njk', expect.objectContaining({ + ...req.app.locals, chosenPlugin: availablePlugin, command: `npm install ${packageName} --save-exact`, currentSection: 'Plugins',