Skip to content

Commit 8ee8d79

Browse files
authored
Merge pull request #276 from DEFRA/feat/DF-702-no-log
Feat/df 702 - dont log for summary page with missing title
2 parents eef1b13 + 685c514 commit 8ee8d79

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

src/server/plugins/engine/helpers.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
ComponentType,
3+
type FormDefinition,
4+
type PageQuestion
5+
} from '@defra/forms-model'
16
import Boom from '@hapi/boom'
27
import { type ResponseObject, type ResponseToolkit } from '@hapi/hapi'
38
import { StatusCodes } from 'http-status-codes'
@@ -14,6 +19,7 @@ import {
1419
getPageHref,
1520
proceed,
1621
safeGenerateCrumb,
22+
setPageTitles,
1723
type GlobalScope
1824
} from '~/src/server/plugins/engine/helpers.js'
1925
import { handleLegacyRedirect } from '~/src/server/plugins/engine/helpers.js'
@@ -51,6 +57,7 @@ describe('Helpers', () => {
5157
let h: FormResponseToolkit
5258

5359
beforeEach(() => {
60+
jest.clearAllMocks()
5461
const model = new FormModel(definition, {
5562
basePath: 'test'
5663
})
@@ -843,4 +850,53 @@ describe('Helpers', () => {
843850
expect(response).toBe(mockRedirectResponse)
844851
})
845852
})
853+
854+
describe('setPageTitles', () => {
855+
const definition: FormDefinition = {
856+
name: 'Test Form',
857+
startPage: '/page1',
858+
pages: [
859+
{
860+
path: '/page1',
861+
title: '',
862+
next: [],
863+
components: [
864+
{
865+
type: ComponentType.TextField,
866+
name: 'textfield1',
867+
title: 'What is your name?',
868+
options: {},
869+
schema: {}
870+
},
871+
{
872+
type: ComponentType.TextField,
873+
name: 'textfield2',
874+
title: 'What is your favourite food?',
875+
options: {},
876+
schema: {}
877+
}
878+
]
879+
} satisfies PageQuestion
880+
],
881+
lists: [],
882+
sections: [],
883+
conditions: []
884+
}
885+
886+
beforeEach(() => {
887+
jest.clearAllMocks()
888+
})
889+
it('should set title if missing', () => {
890+
const def = structuredClone(definition)
891+
setPageTitles(def)
892+
expect(def.pages[0].title).toBe('What is your name?')
893+
})
894+
895+
it('should keep title if supplied', () => {
896+
const def = structuredClone(definition)
897+
def.pages[0].title = 'Page 1 title'
898+
setPageTitles(def)
899+
expect(def.pages[0].title).toBe('Page 1 title')
900+
})
901+
})
846902
})

src/server/plugins/engine/helpers.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,6 @@ export function setPageTitles(def: FormDefinition) {
413413

414414
page.title = firstFormComponent?.title ?? ''
415415
}
416-
417-
if (!page.title) {
418-
const formNameMsg = def.name ? ` in form '${def.name}'` : ''
419-
420-
logger.info(
421-
`[pageTitleMissing] Page '${page.path}' has no title${formNameMsg}`
422-
)
423-
}
424416
}
425417
})
426418
}

0 commit comments

Comments
 (0)