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
22 changes: 11 additions & 11 deletions src/server/plugins/engine/models/SummaryViewModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ describe('SummaryViewModel', () => {
} satisfies FormState,
keys: [
'How would you like to receive your pizza?',
'Pizzas',
'Pizza',
'How you would like to receive your pizza',
'Pizzas',
'Pizza',
'Pizza'
],
values: ['Collection', 'Not provided'],
Expand All @@ -91,13 +91,13 @@ describe('SummaryViewModel', () => {
} satisfies FormState,
keys: [
'How would you like to receive your pizza?',
'Pizza added',
'Pizza',
'How you would like to receive your pizza',
'Pizzas',
'Pizza',
'Pizza'
],
values: ['Delivery', 'You added 1 Pizza'],
answers: ['Delivery', 'You added 1 Pizza'],
values: ['Delivery', 'You have added 1 answer'],
answers: ['Delivery', 'You have added 1 answer'],
names: ['orderType', 'pizza']
},
{
Expand All @@ -120,13 +120,13 @@ describe('SummaryViewModel', () => {
} satisfies FormState,
keys: [
'How would you like to receive your pizza?',
'Pizzas added',
'Pizza',
'How you would like to receive your pizza',
'Pizzas',
'Pizza',
'Pizza'
],
values: ['Delivery', 'You added 2 Pizzas'],
answers: ['Delivery', 'You added 2 Pizzas'],
values: ['Delivery', 'You have added 2 answers'],
answers: ['Delivery', 'You have added 2 answers'],
names: ['orderType', 'pizza']
}
])(
Expand Down Expand Up @@ -326,7 +326,7 @@ describe('SummaryViewModel', () => {
expect(details1.items[0]).toMatchObject({
name: 'pizza',
value: '',
title: 'Pizzas',
title: 'Pizza',
label: 'Pizza'
})

Expand Down
6 changes: 3 additions & 3 deletions src/server/plugins/engine/models/SummaryViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ function ItemRepeat(
const { name, title } = repeat.options

const values = page.getListFromState(state)
const unit = values.length === 1 ? title : `${title}s`
const unit = values.length === 1 ? 'answer' : 'answers'

return {
name,
label: title,
title: values.length ? `${unit} added` : unit,
value: values.length ? `You added ${values.length} ${unit}` : '',
title,
value: values.length ? `You have added ${values.length} ${unit}` : '',
href: getPageHref(page, options.path, {
returnUrl: getPageHref(page, page.getSummaryPath())
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`SummaryViewModel Check answers (0 items) should use correct summary lab
{
"label": "Pizza",
"name": "pizza",
"title": "Pizzas",
"title": "Pizza",
"value": "",
},
{
Expand All @@ -22,8 +22,8 @@ exports[`SummaryViewModel Check answers (1 item) should use correct summary labe
{
"label": "Pizza",
"name": "pizza",
"title": "Pizza added",
"value": "You added 1 Pizza",
"title": "Pizza",
"value": "You have added 1 answer",
},
{
"label": "How would you like to receive your pizza?",
Expand All @@ -39,8 +39,8 @@ exports[`SummaryViewModel Check answers (2 items) should use correct summary lab
{
"label": "Pizza",
"name": "pizza",
"title": "Pizzas added",
"value": "You added 2 Pizzas",
"title": "Pizza",
"value": "You have added 2 answers",
},
{
"label": "How would you like to receive your pizza?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('RepeatPageController', () => {
description: 'No items',
list: [] satisfies RepeatListState,
viewModel: {
pageTitle: 'You have added 0 Pizzas',
pageTitle: 'You have added 0 answers',
showTitle: true,
sectionTitle: 'Food'
}
Expand All @@ -164,7 +164,7 @@ describe('RepeatPageController', () => {
}
] satisfies RepeatListState,
viewModel: {
pageTitle: 'You have added 1 Pizza',
pageTitle: 'You have added 1 answer',
showTitle: true,
sectionTitle: 'Food'
}
Expand All @@ -184,7 +184,7 @@ describe('RepeatPageController', () => {
}
] satisfies RepeatListState,
viewModel: {
pageTitle: 'You have added 2 Pizzas',
pageTitle: 'You have added 2 answers',
showTitle: true,
sectionTitle: 'Food'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class RepeatPageController extends QuestionPageController {
) => {
const { path, repeat } = this
const { query } = request
const { schema, options } = repeat
const { schema } = repeat
const { state } = context

const list = this.getListFromState(state)
Expand All @@ -232,7 +232,7 @@ export class RepeatPageController extends QuestionPageController {
// Show error if repeat limits apply
if (hasErrorMin || hasErrorMax) {
const count = hasErrorMax ? schema.max : schema.min
const itemTitle = `${options.title}${count === 1 ? '' : 's'}`
const itemTitle = `answer${count === 1 ? '' : 's'}`

context.errors = [
{
Expand Down Expand Up @@ -295,9 +295,9 @@ export class RepeatPageController extends QuestionPageController {
...viewModel,
context,
backLink: this.getBackLink(request, context),
pageTitle: `Are you sure you want to remove this ${title}?`,
pageTitle: 'Are you sure you want to remove this answer?',
itemTitle: `${title} ${list.indexOf(item) + 1}`,
buttonConfirm: { text: `Remove ${title}` },
buttonConfirm: { text: 'Remove' },
buttonCancel: { text: 'Cancel' }
} satisfies ItemDeletePageViewModel)
}
Expand Down Expand Up @@ -431,11 +431,13 @@ export class RepeatPageController extends QuestionPageController {
})
}

const unit = count === 1 ? 'answer' : 'answers'

return {
...this.viewModel,
backLink: this.getBackLink(request, context),
repeatTitle: title,
pageTitle: `You have added ${count} ${title}${count === 1 ? '' : 's'}`,
pageTitle: `You have added ${count} ${unit}`,
showTitle: true,
context,
errors,
Expand Down
2 changes: 1 addition & 1 deletion src/server/plugins/engine/views/repeat-list-summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}) }}

{{ govukButton({
text: "Add another " + repeatTitle,
text: "Add another",
name: "action",
value: "add-another",
classes: "govuk-button--secondary",
Expand Down
6 changes: 3 additions & 3 deletions test/form/repeat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ describe('Repeat POST tests', () => {
})

expect($heading).toBeInTheDocument()
expect($errorItems[0]).toHaveTextContent('You can only add up to 3 Pizzas')
expect($errorItems[0]).toHaveTextContent('You can only add up to 3 answers')
})

test('POST /pizza-order/summary CONTINUE with 1 item returns 200 with errors under schema.min', async () => {
Expand All @@ -548,7 +548,7 @@ describe('Repeat POST tests', () => {
})

expect($heading).toBeInTheDocument()
expect($errorItems[0]).toHaveTextContent('You must add at least 2 Pizzas')
expect($errorItems[0]).toHaveTextContent('You must add at least 2 answers')
})

test('POST /pizza-order/summary with 2 items CONTINUE returns 303 to /summary', async () => {
Expand Down Expand Up @@ -581,7 +581,7 @@ describe('Repeat POST tests', () => {
classList.contains('govuk-summary-list__value')
)

expect($values[0]).toHaveTextContent('You added 2 Pizzas')
expect($values[0]).toHaveTextContent('You have added 2 answers')

// POST the summary page
await server.inject({
Expand Down
Loading