Skip to content
Open
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
36 changes: 36 additions & 0 deletions src/server/plugins/engine/components/helpers/components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type EastingNorthingFieldComponent,
type GeospatialFieldComponent,
type LatLongFieldComponent,
type MultilineTextFieldComponent,
type NationalGridFieldNumberFieldComponent,
type OsGridRefFieldComponent
} from '@defra/forms-model'
Expand All @@ -18,6 +19,7 @@ import {
EastingNorthingField,
GeospatialField,
LatLongField,
MultilineTextField,
NationalGridFieldNumberField,
OsGridRefField
} from '~/src/server/plugins/engine/components/index.js'
Expand Down Expand Up @@ -442,3 +444,37 @@ describe('Location field formatting', () => {
})
})
})

describe('MultilineTextField formatting', () => {
let field: MultilineTextField

beforeEach(() => {
const model = new FormModel(definition, {
basePath: 'test'
})

const def: MultilineTextFieldComponent = {
type: ComponentType.MultilineTextField,
name: 'myComponent',
title: 'Your answer',
options: {},
schema: {}
}

field = new MultilineTextField(def, { model })
})

it('escapes block quote markers in the check answers summary', () => {
const state = { myComponent: '> first\r\n>\r\n> second' }

const answer = getAnswer(field, state, translator, { format: 'summary' })
expect(answer).toBe('&gt; first<br>&gt;<br>&gt; second<br>')
})

it('escapes block quote markers in emails', () => {
const state = { myComponent: '> first\r\n>\r\n> second' }

const answer = getAnswer(field, state, translator, { format: 'email' })
expect(answer).toBe('\\> first\n\\>\n\\> second\n')
})
})
1 change: 1 addition & 0 deletions src/server/plugins/engine/components/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function escapeMarkdown(answer: string) {
'(',
')',
'#',
'>',
'+',
'-',
'.',
Expand Down
Loading