Skip to content

Commit bdc4e91

Browse files
committed
fix(create): respect extendedInfo flag when mapping form to election
- When extendedInfo is disabled, don't include metadata (description/image) for choices - This fixes issue #1621 where cloned processes retained extended info even when disabled - Updated existing test to explicitly set extendedInfo: true - Added new test to verify empty meta object when extendedInfo is false
1 parent 42716b4 commit bdc4e91

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

src/components/Process/Create/index.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ describe('useFormToElectionMapper', () => {
651651

652652
const form: Process = {
653653
...mockForm,
654+
extendedInfo: true,
654655
questions: [
655656
{
656657
title: 'Question',
@@ -671,6 +672,33 @@ describe('useFormToElectionMapper', () => {
671672
expect(choice.meta?.description).toBe('Option description')
672673
expect(choice.meta?.image).toEqual({ default: 'https://example.com/image.png' })
673674
})
675+
676+
it('should NOT include metadata when extendedInfo is false', () => {
677+
const { result } = renderHook(() => useFormToElectionMapper())
678+
const mapper = result.current
679+
680+
const form: Process = {
681+
...mockForm,
682+
extendedInfo: false,
683+
questions: [
684+
{
685+
title: 'Question',
686+
description: 'Description',
687+
options: [
688+
{
689+
option: 'Option without metadata',
690+
description: 'This should be ignored',
691+
image: 'https://example.com/image.png',
692+
},
693+
],
694+
},
695+
],
696+
}
697+
698+
const election = mapper(form, mockCensus)
699+
const choice = election.questions[0].choices[0]
700+
expect(choice.meta).toBeUndefined()
701+
})
674702
})
675703

676704
describe('metadata mapping', () => {

src/components/Process/Create/index.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,22 @@ export const useFormToElectionMapper = () => {
539539
({
540540
title: { default: question.title },
541541
description: { default: question.description },
542-
choices: question.options.map((q: Option, i: number) => ({
543-
title: { default: q.option },
544-
value: i,
545-
meta: {
546-
description: q.description,
547-
image: { default: q.image },
548-
},
549-
})),
542+
choices: question.options.map((q: Option, i: number) => {
543+
const choice: IQuestion['choices'][number] = {
544+
title: { default: q.option },
545+
value: i,
546+
}
547+
548+
// Only include meta when extendedInfo is enabled
549+
if (form.extendedInfo) {
550+
choice.meta = {
551+
description: q.description,
552+
image: { default: q.image },
553+
}
554+
}
555+
556+
return choice
557+
}),
550558
}) as IQuestion
551559
),
552560
startDate,

0 commit comments

Comments
 (0)