Skip to content

Commit c3a4d12

Browse files
committed
fix(surveys): keep a typed hosted intro description editable
Typing a description into an intro whose content type was unset left the type unset, which renders as HTML, so the canvas swapped the field for the read-only HTML view. Canvas edits are plain text, so they now pin the type to text. Tested: jest src/scenes/surveys/hosted-canvas passes; the new two-edit test fails without the fix.
1 parent 8eda198 commit c3a4d12

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.test.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,41 @@ describe('HostedSurveyCanvas', () => {
8686
}
8787
)
8888

89+
it('keeps a typed intro description editable when the content type was unset', () => {
90+
const survey: Survey = {
91+
...baseSurvey,
92+
appearance: {
93+
...baseSurvey.appearance,
94+
introScreenDescription: '',
95+
introScreenDescriptionContentType: undefined,
96+
},
97+
}
98+
const logic = surveyLogic({ id: survey.id })
99+
logic.mount()
100+
logic.actions.loadSurveySuccess(survey)
101+
const renderCanvas = (): JSX.Element => (
102+
<BindLogic logic={surveyLogic} props={{ id: survey.id }}>
103+
<HostedSurveyCanvas
104+
survey={logic.values.survey as Survey}
105+
activePageIndex={-1}
106+
pageKind="intro"
107+
viewport="desktop"
108+
/>
109+
</BindLogic>
110+
)
111+
const { rerender } = render(renderCanvas())
112+
113+
for (const text of ['First draft', 'Second draft']) {
114+
fireEvent.click(screen.getByLabelText('Intro description'))
115+
fireEvent.change(screen.getByLabelText('Intro description'), { target: { value: text } })
116+
fireEvent.blur(screen.getByLabelText('Intro description'))
117+
rerender(renderCanvas())
118+
}
119+
120+
expect(logic.values.survey.appearance?.introScreenDescription).toBe('Second draft')
121+
expect(logic.values.survey.appearance?.introScreenDescriptionContentType).toBe('text')
122+
})
123+
89124
it.each([
90125
['an unset content type', undefined, true],
91126
['an html content type', 'html', true],

‎frontend/src/scenes/surveys/hosted-canvas/IntroCanvas.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ export function IntroCanvas({ survey }: { survey: Survey | NewSurvey }): JSX.Ele
3939
as="p"
4040
className="intro-screen-body"
4141
value={appearance.introScreenDescription || ''}
42-
onChange={(value) => updateAppearance({ introScreenDescription: value })}
42+
onChange={(value) =>
43+
updateAppearance({
44+
introScreenDescription: value,
45+
introScreenDescriptionContentType: 'text',
46+
})
47+
}
4348
placeholder="Add an opening message (optional)"
4449
ariaLabel="Intro description"
4550
multiline

0 commit comments

Comments
 (0)