Skip to content

Commit d189960

Browse files
feature/DF-810 repeater titles (#301)
* Remove pluralisations in repeater content * Fix repeater controller tests * Fix summary view model (repeater) tests * Remove pluralisations in repeater content * Fix repeater controller tests * Fix summary view model (repeater) tests * Update min/max repeater error message content and tests
1 parent d563579 commit d189960

7 files changed

Lines changed: 33 additions & 31 deletions

File tree

src/server/plugins/engine/models/SummaryViewModel.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ describe('SummaryViewModel', () => {
6767
} satisfies FormState,
6868
keys: [
6969
'How would you like to receive your pizza?',
70-
'Pizzas',
70+
'Pizza',
7171
'How you would like to receive your pizza',
72-
'Pizzas',
72+
'Pizza',
7373
'Pizza'
7474
],
7575
values: ['Collection', 'Not provided'],
@@ -91,13 +91,13 @@ describe('SummaryViewModel', () => {
9191
} satisfies FormState,
9292
keys: [
9393
'How would you like to receive your pizza?',
94-
'Pizza added',
94+
'Pizza',
9595
'How you would like to receive your pizza',
96-
'Pizzas',
96+
'Pizza',
9797
'Pizza'
9898
],
99-
values: ['Delivery', 'You added 1 Pizza'],
100-
answers: ['Delivery', 'You added 1 Pizza'],
99+
values: ['Delivery', 'You have added 1 answer'],
100+
answers: ['Delivery', 'You have added 1 answer'],
101101
names: ['orderType', 'pizza']
102102
},
103103
{
@@ -120,13 +120,13 @@ describe('SummaryViewModel', () => {
120120
} satisfies FormState,
121121
keys: [
122122
'How would you like to receive your pizza?',
123-
'Pizzas added',
123+
'Pizza',
124124
'How you would like to receive your pizza',
125-
'Pizzas',
125+
'Pizza',
126126
'Pizza'
127127
],
128-
values: ['Delivery', 'You added 2 Pizzas'],
129-
answers: ['Delivery', 'You added 2 Pizzas'],
128+
values: ['Delivery', 'You have added 2 answers'],
129+
answers: ['Delivery', 'You have added 2 answers'],
130130
names: ['orderType', 'pizza']
131131
}
132132
])(
@@ -326,7 +326,7 @@ describe('SummaryViewModel', () => {
326326
expect(details1.items[0]).toMatchObject({
327327
name: 'pizza',
328328
value: '',
329-
title: 'Pizzas',
329+
title: 'Pizza',
330330
label: 'Pizza'
331331
})
332332

src/server/plugins/engine/models/SummaryViewModel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ function ItemRepeat(
186186
const { name, title } = repeat.options
187187

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

191191
return {
192192
name,
193193
label: title,
194-
title: values.length ? `${unit} added` : unit,
195-
value: values.length ? `You added ${values.length} ${unit}` : '',
194+
title,
195+
value: values.length ? `You have added ${values.length} ${unit}` : '',
196196
href: getPageHref(page, options.path, {
197197
returnUrl: getPageHref(page, page.getSummaryPath())
198198
}),

src/server/plugins/engine/models/__snapshots__/SummaryViewModel.test.ts.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`SummaryViewModel Check answers (0 items) should use correct summary lab
55
{
66
"label": "Pizza",
77
"name": "pizza",
8-
"title": "Pizzas",
8+
"title": "Pizza",
99
"value": "",
1010
},
1111
{
@@ -22,8 +22,8 @@ exports[`SummaryViewModel Check answers (1 item) should use correct summary labe
2222
{
2323
"label": "Pizza",
2424
"name": "pizza",
25-
"title": "Pizza added",
26-
"value": "You added 1 Pizza",
25+
"title": "Pizza",
26+
"value": "You have added 1 answer",
2727
},
2828
{
2929
"label": "How would you like to receive your pizza?",
@@ -39,8 +39,8 @@ exports[`SummaryViewModel Check answers (2 items) should use correct summary lab
3939
{
4040
"label": "Pizza",
4141
"name": "pizza",
42-
"title": "Pizzas added",
43-
"value": "You added 2 Pizzas",
42+
"title": "Pizza",
43+
"value": "You have added 2 answers",
4444
},
4545
{
4646
"label": "How would you like to receive your pizza?",

src/server/plugins/engine/pageControllers/RepeatPageController.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('RepeatPageController', () => {
149149
description: 'No items',
150150
list: [] satisfies RepeatListState,
151151
viewModel: {
152-
pageTitle: 'You have added 0 Pizzas',
152+
pageTitle: 'You have added 0 answers',
153153
showTitle: true,
154154
sectionTitle: 'Food'
155155
}
@@ -164,7 +164,7 @@ describe('RepeatPageController', () => {
164164
}
165165
] satisfies RepeatListState,
166166
viewModel: {
167-
pageTitle: 'You have added 1 Pizza',
167+
pageTitle: 'You have added 1 answer',
168168
showTitle: true,
169169
sectionTitle: 'Food'
170170
}
@@ -184,7 +184,7 @@ describe('RepeatPageController', () => {
184184
}
185185
] satisfies RepeatListState,
186186
viewModel: {
187-
pageTitle: 'You have added 2 Pizzas',
187+
pageTitle: 'You have added 2 answers',
188188
showTitle: true,
189189
sectionTitle: 'Food'
190190
}

src/server/plugins/engine/pageControllers/RepeatPageController.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class RepeatPageController extends QuestionPageController {
207207
) => {
208208
const { path, repeat } = this
209209
const { query } = request
210-
const { schema, options } = repeat
210+
const { schema } = repeat
211211
const { state } = context
212212

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

237237
context.errors = [
238238
{
@@ -295,9 +295,9 @@ export class RepeatPageController extends QuestionPageController {
295295
...viewModel,
296296
context,
297297
backLink: this.getBackLink(request, context),
298-
pageTitle: `Are you sure you want to remove this ${title}?`,
298+
pageTitle: 'Are you sure you want to remove this answer?',
299299
itemTitle: `${title} ${list.indexOf(item) + 1}`,
300-
buttonConfirm: { text: `Remove ${title}` },
300+
buttonConfirm: { text: 'Remove' },
301301
buttonCancel: { text: 'Cancel' }
302302
} satisfies ItemDeletePageViewModel)
303303
}
@@ -431,11 +431,13 @@ export class RepeatPageController extends QuestionPageController {
431431
})
432432
}
433433

434+
const unit = count === 1 ? 'answer' : 'answers'
435+
434436
return {
435437
...this.viewModel,
436438
backLink: this.getBackLink(request, context),
437439
repeatTitle: title,
438-
pageTitle: `You have added ${count} ${title}${count === 1 ? '' : 's'}`,
440+
pageTitle: `You have added ${count} ${unit}`,
439441
showTitle: true,
440442
context,
441443
errors,

src/server/plugins/engine/views/repeat-list-summary.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}) }}
3737

3838
{{ govukButton({
39-
text: "Add another " + repeatTitle,
39+
text: "Add another",
4040
name: "action",
4141
value: "add-another",
4242
classes: "govuk-button--secondary",

test/form/repeat.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ describe('Repeat POST tests', () => {
522522
})
523523

524524
expect($heading).toBeInTheDocument()
525-
expect($errorItems[0]).toHaveTextContent('You can only add up to 3 Pizzas')
525+
expect($errorItems[0]).toHaveTextContent('You can only add up to 3 answers')
526526
})
527527

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

550550
expect($heading).toBeInTheDocument()
551-
expect($errorItems[0]).toHaveTextContent('You must add at least 2 Pizzas')
551+
expect($errorItems[0]).toHaveTextContent('You must add at least 2 answers')
552552
})
553553

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

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

586586
// POST the summary page
587587
await server.inject({

0 commit comments

Comments
 (0)