-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VAGOV-TEAM-89918: Create Form Config object from normalized input #31296
Merged
ryguyk
merged 10 commits into
main
from
89918-pull-in-normalized-output-and-create-form-config-object
Aug 15, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
389f996
Create initial createFormConfig function
derekhouck 0cdd626
Format chapters
derekhouck 56b90d4
Add normalized form to mockFetchFormConfigByFormId
derekhouck ab0161a
Merge branch 'main' into 89918-pull-in-normalized-output-and-create-f…
derekhouck 8394fab
Remove redundant eslint-disable
derekhouck ce894e9
Merge branch 'main' into 89918-pull-in-normalized-output-and-create-f…
derekhouck 34dc680
Merge branch 'main' into 89918-pull-in-normalized-output-and-create-f…
derekhouck d5c51de
Update id to cmsID
derekhouck 58254ed
Refactor formatChapters to use reduce
derekhouck c90d2cf
Add comment explaining why we're using chapter IDs within pages
derekhouck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
65 changes: 65 additions & 0 deletions
65
src/applications/form-renderer/tests/unit/utils/formConfig.unit.spec.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,65 @@ | ||
/* eslint-disable prefer-destructuring */ | ||
|
||
import { expect } from 'chai'; | ||
import { normalizedForm } from '../../../_config/formConfig'; | ||
import { createFormConfig } from '../../../utils/formConfig'; | ||
import manifest from '../../../manifest.json'; | ||
|
||
describe('createFormConfig', () => { | ||
let formConfig; | ||
|
||
beforeEach(() => { | ||
formConfig = createFormConfig(normalizedForm); | ||
}); | ||
|
||
it('returns a properly formatted Form Config object', () => { | ||
expect(formConfig.rootUrl).to.eq(`${manifest.rootUrl}/2121212`); | ||
expect(formConfig.urlPrefix).to.eq(`/2121212/`); | ||
expect(formConfig.trackingPrefix).to.eq('2121212-'); | ||
expect(formConfig.title).to.eq('Form with Two Steps'); | ||
expect(formConfig.formId).to.eq('2121212'); | ||
expect(formConfig.subTitle).to.eq('VA Form 2121212'); | ||
expect(Object.keys(formConfig.chapters).length).to.eq(2); | ||
}); | ||
|
||
it('properly formats each chapter', () => { | ||
const testChapter = formConfig.chapters[158253]; | ||
const page = testChapter.pages[158253]; | ||
|
||
expect(testChapter.title).to.eq('First Step'); | ||
expect(Object.keys(testChapter.pages).length).to.eq(1); | ||
expect(page.path).to.eq('158253'); | ||
expect(page.title).to.eq('Name and Date of Birth'); | ||
expect(page.schema).not.to.eq(undefined); | ||
expect(page.uiSchema['ui:title']).not.to.eq(undefined); | ||
}); | ||
|
||
context('with Name and Date of Birth pattern', () => { | ||
let dobIncluded; | ||
let nameOnly; | ||
|
||
beforeEach(() => { | ||
dobIncluded = formConfig.chapters[158253].pages[158253]; | ||
nameOnly = formConfig.chapters[158254].pages[158254]; | ||
}); | ||
|
||
it('contains fullName', () => { | ||
expect(dobIncluded.schema.properties.fullName).to.not.eq(undefined); | ||
expect(dobIncluded.uiSchema.fullName).to.not.eq(undefined); | ||
}); | ||
|
||
context('when includeDateOfBirth is true', () => { | ||
it('contains dateOfBirth', () => { | ||
expect(dobIncluded.schema.properties.dateOfBirth).to.not.eq(undefined); | ||
expect(dobIncluded.uiSchema.dateOfBirth).to.not.eq(undefined); | ||
}); | ||
}); | ||
|
||
context('when includeDateOfBirth is false', () => { | ||
it('does not contain dateOfBirth', () => { | ||
expect(nameOnly.schema.properties.dateOfBirth).to.eq(undefined); | ||
expect(nameOnly.uiSchema.dateOfBirth).to.eq(undefined); | ||
}); | ||
}); | ||
}); | ||
}); |
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,80 @@ | ||
import { | ||
dateOfBirthSchema, | ||
dateOfBirthUI, | ||
fullNameSchema, | ||
fullNameUI, | ||
titleUI, | ||
} from 'platform/forms-system/src/js/web-component-patterns'; | ||
import manifest from '../manifest.json'; | ||
import IntroductionPage from '../containers/IntroductionPage'; | ||
import ConfirmationPage from '../containers/ConfirmationPage'; | ||
|
||
const selectSchemas = ({ pageTitle, additionalFields }) => { | ||
const schemas = { | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
fullName: fullNameSchema, | ||
}, | ||
}, | ||
uiSchema: { | ||
...titleUI(pageTitle), | ||
fullName: fullNameUI(), | ||
}, | ||
}; | ||
|
||
if (additionalFields.includeDateOfBirth) { | ||
schemas.schema.properties.dateOfBirth = dateOfBirthSchema; | ||
schemas.uiSchema.dateOfBirth = dateOfBirthUI(); | ||
} | ||
|
||
return schemas; | ||
}; | ||
|
||
const formatChapters = chapters => | ||
chapters.reduce((formattedChapters, chapter) => { | ||
const pages = { | ||
// For now, all chapters contain only one page, and there are no | ||
// separate IDs for pages. This will probably change at some point. | ||
[chapter.id]: { | ||
path: chapter.id.toString(), | ||
title: chapter.pageTitle, | ||
...selectSchemas(chapter), | ||
}, | ||
}; | ||
|
||
const formattedChapter = { | ||
[chapter.id]: { | ||
title: chapter.chapterTitle, | ||
pages, | ||
}, | ||
}; | ||
|
||
return { ...formattedChapters, ...formattedChapter }; | ||
}, {}); | ||
|
||
export const createFormConfig = ({ chapters, formId, title }) => { | ||
const subTitle = `VA Form ${formId}`; | ||
|
||
return { | ||
rootUrl: `${manifest.rootUrl}/${formId}`, | ||
urlPrefix: `/${formId}/`, | ||
trackingPrefix: `${formId}-`, | ||
// eslint-disable-next-line no-console | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ESLint disabled here |
||
submit: () => console.log(`Submitted ${subTitle}`), | ||
introduction: IntroductionPage, | ||
confirmation: ConfirmationPage, | ||
formId, | ||
saveInProgress: {}, | ||
version: 0, | ||
prefillEnabled: true, | ||
savedFormMessages: { | ||
notFound: `${subTitle} NOT FOUND`, | ||
noAuth: `Please sign in again to continue ${subTitle}.`, | ||
}, | ||
title, | ||
defaultDefinitions: {}, | ||
subTitle, | ||
chapters: formatChapters(chapters), | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESLint disabled here