diff --git a/src/server/plugins/engine/helpers.test.ts b/src/server/plugins/engine/helpers.test.ts index 6d8abc603..dd9b765c3 100644 --- a/src/server/plugins/engine/helpers.test.ts +++ b/src/server/plugins/engine/helpers.test.ts @@ -1,3 +1,8 @@ +import { + ComponentType, + type FormDefinition, + type PageQuestion +} from '@defra/forms-model' import Boom from '@hapi/boom' import { type ResponseObject, type ResponseToolkit } from '@hapi/hapi' import { StatusCodes } from 'http-status-codes' @@ -14,6 +19,7 @@ import { getPageHref, proceed, safeGenerateCrumb, + setPageTitles, type GlobalScope } from '~/src/server/plugins/engine/helpers.js' import { handleLegacyRedirect } from '~/src/server/plugins/engine/helpers.js' @@ -51,6 +57,7 @@ describe('Helpers', () => { let h: FormResponseToolkit beforeEach(() => { + jest.clearAllMocks() const model = new FormModel(definition, { basePath: 'test' }) @@ -843,4 +850,53 @@ describe('Helpers', () => { expect(response).toBe(mockRedirectResponse) }) }) + + describe('setPageTitles', () => { + const definition: FormDefinition = { + name: 'Test Form', + startPage: '/page1', + pages: [ + { + path: '/page1', + title: '', + next: [], + components: [ + { + type: ComponentType.TextField, + name: 'textfield1', + title: 'What is your name?', + options: {}, + schema: {} + }, + { + type: ComponentType.TextField, + name: 'textfield2', + title: 'What is your favourite food?', + options: {}, + schema: {} + } + ] + } satisfies PageQuestion + ], + lists: [], + sections: [], + conditions: [] + } + + beforeEach(() => { + jest.clearAllMocks() + }) + it('should set title if missing', () => { + const def = structuredClone(definition) + setPageTitles(def) + expect(def.pages[0].title).toBe('What is your name?') + }) + + it('should keep title if supplied', () => { + const def = structuredClone(definition) + def.pages[0].title = 'Page 1 title' + setPageTitles(def) + expect(def.pages[0].title).toBe('Page 1 title') + }) + }) }) diff --git a/src/server/plugins/engine/helpers.ts b/src/server/plugins/engine/helpers.ts index 43a934562..8cfaa21da 100644 --- a/src/server/plugins/engine/helpers.ts +++ b/src/server/plugins/engine/helpers.ts @@ -413,14 +413,6 @@ export function setPageTitles(def: FormDefinition) { page.title = firstFormComponent?.title ?? '' } - - if (!page.title) { - const formNameMsg = def.name ? ` in form '${def.name}'` : '' - - logger.info( - `[pageTitleMissing] Page '${page.path}' has no title${formNameMsg}` - ) - } } }) }