-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #463 from DEFRA/feature/398642-post-submission-gui…
…dance Edit submission guidance
- Loading branch information
Showing
34 changed files
with
556 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { markdownToHtml } from '@defra/forms-model' | ||
export { markdownToHtml as markdown } from '@defra/forms-model' | ||
export { formatCurrency } from '~/src/common/nunjucks/filters/format-currency.js' | ||
export { formatDate } from '~/src/common/nunjucks/filters/format-date.js' | ||
export { formatJSON } from '~/src/common/nunjucks/filters/format-json.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { buildErrorList } from '~/src/common/helpers/build-error-details.js' | ||
import { formOverviewBackLink } from '~/src/models/links.js' | ||
|
||
/** | ||
* @param {FormMetadata} metadata | ||
* @param {ValidationFailure<Pick<FormMetadataInput, 'submissionGuidance'>>} [validation] | ||
*/ | ||
export function submissionGuidanceViewModel(metadata, validation) { | ||
const pageTitle = 'Tell users what happens after they submit their form' | ||
const { formValues, formErrors } = validation ?? {} | ||
|
||
return { | ||
form: metadata, | ||
backLink: formOverviewBackLink(metadata.slug), | ||
pageTitle, | ||
errorList: buildErrorList(formErrors), | ||
formErrors: validation?.formErrors, | ||
formValues: validation?.formValues, | ||
field: { | ||
id: 'submissionGuidance', | ||
name: 'submissionGuidance', | ||
label: { | ||
text: 'What will happen after a user submits a form?' | ||
}, | ||
value: formValues?.submissionGuidance ?? metadata.submissionGuidance | ||
}, | ||
buttonText: 'Save and continue' | ||
} | ||
} | ||
|
||
/** | ||
* @import { FormMetadata, FormMetadataInput } from '@defra/forms-model' | ||
* @import { ValidationFailure } from '~/src/common/helpers/types.js' | ||
*/ |
48 changes: 48 additions & 0 deletions
48
designer/server/src/models/forms/submission-guidance.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { submissionGuidanceViewModel } from '~/src/models/forms/submission-guidance.js' | ||
|
||
describe('edit - model - submission - guidance', () => { | ||
const now = new Date() | ||
const authorId = 'f50ceeed-b7a4-47cf-a498-094efc99f8bc' | ||
const authorDisplayName = 'Enrique Chase' | ||
|
||
/** | ||
* @satisfies {FormMetadataAuthor} | ||
*/ | ||
const author = { | ||
id: authorId, | ||
displayName: authorDisplayName | ||
} | ||
|
||
/** | ||
* @satisfies {FormMetadata} | ||
*/ | ||
const formMetadata = { | ||
id: '661e4ca5039739ef2902b214', | ||
slug: 'my-form-slug', | ||
title: 'Test form', | ||
organisation: 'Defra', | ||
teamName: 'Defra Forms', | ||
teamEmail: '[email protected]', | ||
submissionGuidance: 'We’ll send you an email to let you know the outcome.', | ||
createdAt: now, | ||
createdBy: author, | ||
updatedAt: now, | ||
updatedBy: author | ||
} | ||
|
||
it('should test submission guidance view model', () => { | ||
const result = submissionGuidanceViewModel(formMetadata) | ||
expect(result.pageTitle).toBe( | ||
'Tell users what happens after they submit their form' | ||
) | ||
expect(result.field.id).toBe('submissionGuidance') | ||
expect(result.field.name).toBe('submissionGuidance') | ||
expect(result.field.value).toBe( | ||
'We’ll send you an email to let you know the outcome.' | ||
) | ||
}) | ||
}) | ||
|
||
/** | ||
* @import { FormMetadata, FormMetadataAuthor } from '@defra/forms-model' | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const backToFormOverviewLinkText = 'Back to form overview' | ||
export const backToFormsLibraryLinkText = 'Back to forms library' | ||
export const formsLibraryPath = '/library' | ||
|
||
/** | ||
* Path to the form overview page | ||
* @param {string} slug - the form slug | ||
*/ | ||
export function formOverviewPath(slug) { | ||
return `${formsLibraryPath}/${slug}` | ||
} | ||
|
||
/** | ||
* Back link to the form overview page | ||
* @param {string} slug - the form slug | ||
*/ | ||
export function formOverviewBackLink(slug) { | ||
return { | ||
text: backToFormOverviewLinkText, | ||
href: formOverviewPath(slug) | ||
} | ||
} | ||
|
||
/** | ||
* Back link to the forms library page | ||
*/ | ||
export const formsLibraryBackLink = { | ||
text: backToFormsLibraryLinkText, | ||
href: formsLibraryPath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.