Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/forms/page-events.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pages:
next: []
id: da0fbdb4-a2de-4650-be16-9ba552af135f
- id: 449a45f6-4541-4a46-91bd-8b8931b07b50
title: Summary
title: ''
path: '/summary'
controller: SummaryPageController
events:
Expand Down
79 changes: 76 additions & 3 deletions src/server/plugins/engine/models/SummaryViewModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type FormContextRequest,
type FormState
} from '~/src/server/plugins/engine/types.js'
import v2Definition from '~/test/form/definitions/conditions-relative-dates-v2.js'
import definition from '~/test/form/definitions/repeat-mixed.js'
const basePath = `${FORM_PREFIX}/test`

Expand Down Expand Up @@ -326,17 +327,89 @@ describe('SummaryPageController', () => {
expect(viewModel).toHaveProperty('allowSaveAndExit', true)
})

it('should display correct page title', () => {
it('should display correct page title for v1 form', () => {
const state: FormState = {
$$__referenceNumber: 'foobar',
orderType: 'collection',
pizza: []
}

const context = model.getFormContext(request, state)
const viewModel = controller.getViewModel(request, context)
const viewModel = controller.getSummaryViewModel(request, context)

expect(viewModel.pageTitle).toBe(
'Check your answers before sending your form'
)
})

it('should display default page title for v2 form when title not supplied', () => {
const state: FormState = {
$$__referenceNumber: 'foobar',
orderType: 'collection',
pizza: []
}

const titleModel = new FormModel(v2Definition, {
basePath: `${FORM_PREFIX}/test`
})

controller = new SummaryPageController(titleModel, v2Definition.pages[5])

request = {
method: 'get',
url: new URL('http://example.com/repeat/pizza-order/summary'),
path: '/test/summary',
params: {
path: 'summary',
slug: 'test'
},
query: {},
app: { model: titleModel },
server: serverWithSaveAndExit
}

const context = titleModel.getFormContext(request, state)
const viewModel = controller.getSummaryViewModel(request, context)

expect(viewModel.pageTitle).toBe(
'Check your answers before sending your form'
)
})

it('should display override page title for v2 form when title supplied', () => {
const state: FormState = {
$$__referenceNumber: 'foobar',
orderType: 'collection',
pizza: []
}

const v2DefinitionWithSummaryTitle = structuredClone(v2Definition)
const summaryPage = v2DefinitionWithSummaryTitle.pages[5]
summaryPage.title = 'Override summary title'

const titleModel = new FormModel(v2DefinitionWithSummaryTitle, {
basePath: `${FORM_PREFIX}/test`
})

controller = new SummaryPageController(titleModel, summaryPage)

request = {
method: 'get',
url: new URL('http://example.com/repeat/pizza-order/summary'),
path: '/test/summary',
params: {
path: 'summary',
slug: 'test'
},
query: {},
app: { model: titleModel },
server: serverWithSaveAndExit
}

const context = titleModel.getFormContext(request, state)
const viewModel = controller.getSummaryViewModel(request, context)

expect(viewModel.pageTitle).toBe('Check your answers')
expect(viewModel.pageTitle).toBe('Override summary title')
})
})
})
6 changes: 5 additions & 1 deletion src/server/plugins/engine/models/SummaryViewModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Section } from '@defra/forms-model'
import { SchemaVersion, type Section } from '@defra/forms-model'

import {
getAnswer,
Expand Down Expand Up @@ -64,6 +64,10 @@ export class SummaryViewModel {

this.page = page
this.pageTitle = page.title
if (def.schema === SchemaVersion.V2 && !page.title) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not neccessary to do a check specifically on V2 to be honest, I don't think it'd ever occur as a scenario. All good anyway.

this.pageTitle = 'Check your answers before sending your form'
}

this.serviceUrl = `/${basePath}`
this.name = def.name
this.declaration = def.declaration
Expand Down
2 changes: 1 addition & 1 deletion test/form/definitions/conditions-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const V2 = /** @satisfies {FormDefinition} */ ({
next: []
},
{
title: 'Summary',
title: '',
path: ControllerPath.Summary,
controller: ControllerType.Summary
}
Expand Down
2 changes: 1 addition & 1 deletion test/form/definitions/conditions-relative-dates-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default /** @satisfies {FormDefinition} */ ({
condition: '581e72cc-8ee3-4bf1-80d2-b9a905724210'
},
{
title: 'Summary',
title: '',
path: '/summary',
controller: ControllerType.Summary,
components: [],
Expand Down
2 changes: 1 addition & 1 deletion test/form/definitions/demo-cph-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ export default /** @satisfies {FormDefinition} */ ({
{
path: ControllerPath.Summary,
controller: ControllerType.Summary,
title: 'Check your answers before submitting your form'
title: 'Check your answers before sending your form'
},
{
path: '/whats-your-business-address',
Expand Down
2 changes: 1 addition & 1 deletion test/form/definitions/joined-conditions-complex-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default /** @satisfies {FormDefinition} */ ({
},
{
id: '449a45f6-4541-4a46-91bd-8b8931b07b50',
title: 'Summary',
title: '',
path: '/summary',
controller: ControllerType.Summary
}
Expand Down
2 changes: 1 addition & 1 deletion test/form/definitions/joined-conditions-simple-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default /** @satisfies {FormDefinition} */ ({
},
{
id: '449a45f6-4541-4a46-91bd-8b8931b07b50',
title: 'Summary',
title: '',
path: '/summary',
controller: ControllerType.Summary
}
Expand Down
2 changes: 1 addition & 1 deletion test/form/definitions/plugin-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default /** @satisfies {FormDefinition} */ ({
{
path: ControllerPath.Summary,
controller: ControllerType.Summary,
title: 'Summary'
title: ''
}
]),
sections: [
Expand Down
2 changes: 1 addition & 1 deletion test/form/definitions/postcode-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default /** @satisfies {FormDefinition} */ ({
id: 'c7ab16e8-819a-43bd-83fa-14c479d23961'
},
{
title: 'Summary',
title: '',
path: '/summary',
controller: ControllerType.Summary,
components: [],
Expand Down
2 changes: 1 addition & 1 deletion test/form/definitions/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default /** @satisfies {FormDefinition} */ ({
{
path: ControllerPath.Summary,
controller: ControllerType.Summary,
title: 'Check your answers'
title: 'Check your answers before sending your form'
}
]),
sections: [
Expand Down
2 changes: 1 addition & 1 deletion test/form/definitions/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default /** @satisfies {FormDefinition} */ ({
{
path: '/summary',
controller: ControllerType.Summary,
title: 'Check your answers before submitting your form'
title: 'Check your answers before sending your form'
}
],
lists: [
Expand Down
Loading