Skip to content

Commit b2f274b

Browse files
committed
Prevent ID being set on list-based components temporarily
1 parent e74061f commit b2f274b

4 files changed

Lines changed: 6 additions & 10 deletions

File tree

src/server/plugins/engine/components/List.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,18 @@ describe('List', () => {
5252
it('returns list items', () => {
5353
expect(guidance).toHaveProperty('items', [
5454
{
55-
id: '52fc51fc-c75a-4b08-9c9e-6bd99b9bc49b',
5655
text: '1 day',
5756
value: 1,
5857
description:
5958
'Valid for 24 hours from the start time that you select'
6059
},
6160
{
62-
id: '56b7b34f-23b3-4446-ac8e-b2443d18588e',
6361
text: '8 day',
6462
value: 8,
6563
description:
6664
'Valid for 8 consecutive days from the start time that you select'
6765
},
6866
{
69-
id: '1af54fbc-eec2-4e1e-bd53-2415abf62677',
7067
text: '12 months',
7168
value: 365,
7269
description:

src/server/plugins/engine/components/ListFormComponent.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ export class ListFormComponent extends FormComponent {
4848
listType: List['type'] = 'string'
4949

5050
get items(): Item[] {
51-
return this.list?.items ?? []
51+
return (
52+
this.list?.items.map((item) => {
53+
delete item.id // temporary workaround to prevent an ID being set, which invalidates #componentName fragments in the links
54+
return item
55+
}) ?? []
56+
)
5257
}
5358

5459
get values(): Item['value'][] {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,13 @@ describe('QuestionPageController', () => {
443443
expect(filtered[1].model.label?.text).toBe('Select from the list')
444444
expect(filtered[1].model.items).toEqual([
445445
{
446-
id: expect.any(String),
447446
checked: false,
448447
condition: 'isBarnOwl',
449448
selected: false,
450449
text: 'Option 1',
451450
value: '1'
452451
},
453452
{
454-
id: expect.any(String),
455453
checked: false,
456454
condition: 'isBarnOwl',
457455
selected: false,
@@ -501,15 +499,13 @@ describe('QuestionPageController', () => {
501499
expect(filtered[1].model.label?.text).toBe('Select from the list')
502500
expect(filtered[1].model.items).toEqual([
503501
{
504-
id: expect.any(String),
505502
checked: false,
506503
condition: 'notBarnOwl',
507504
selected: false,
508505
text: 'Option 3',
509506
value: '3'
510507
},
511508
{
512-
id: expect.any(String),
513509
checked: false,
514510
condition: 'notBarnOwl',
515511
selected: false,

test/form/factory.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
export function createListItemFactory(partialListItem) {
77
return {
8-
id: '52fc51fc-c75a-4b08-9c9e-6bd99b9bc49b',
98
text: 'text',
109
value: 1,
1110
description: 'Valid for 24 hours from the start time that you select',
@@ -20,7 +19,6 @@ export function createListItemFactory(partialListItem) {
2019
*/
2120
export function createListFromFactory(partialList) {
2221
return {
23-
id: '4ebe4ef5-bd3c-499b-a179-7e7e86b0dc6f',
2422
name: 'licenceLengthDays',
2523
title: 'Licence length (days)',
2624
type: 'number',

0 commit comments

Comments
 (0)