add documentation and tests for form builder functionality DEV-2268#7155
add documentation and tests for form builder functionality DEV-2268#7155jamesrkiger wants to merge 1 commit into
Conversation
|
|
|
||
| /** | ||
| * `required` behaves differently on question rows vs group rows. | ||
| * See SERIALIZATION_QUIRKS.md for context. |
There was a problem hiding this comment.
Dangling reference to non-existent file
The comment references SERIALIZATION_QUIRKS.md, but that file does not exist anywhere in the repository — only DESIGN_REFERENCE.md was added in this PR. Any developer following the cross-reference will hit a dead end. Either the file needs to be created, or the comment should point to the relevant section of DESIGN_REFERENCE.md instead.
| import clonedeep from 'lodash.clonedeep' | ||
| import dkobo_xlform from '../../../xlform/src/_xlform.init' | ||
| import { surveyToValidJson, unnullifyTranslations } from '#/components/formBuilder/formBuilderUtils' | ||
| import type { AssetContent } from '#/dataInterface' | ||
|
|
||
| export function createSurvey() { | ||
| return dkobo_xlform.model.Survey.create() | ||
| } | ||
|
|
||
| export function loadSurvey(content: AssetContent) { | ||
| return dkobo_xlform.model.Survey.loadDict(clonedeep(content)) | ||
| } | ||
|
|
||
| export function serialize(survey: any): Record<string, any> { | ||
| let json = surveyToValidJson(survey) | ||
| if (survey._initialParams?.translations_0) { | ||
| json = unnullifyTranslations(json, survey._initialParams) | ||
| } | ||
| return JSON.parse(json) | ||
| } | ||
|
|
||
| export function addRow(survey: any, attrs: Record<string, any>) { | ||
| survey.addRow(attrs) | ||
| return survey.rows.last() | ||
| } | ||
|
|
||
| export function surveyRow(survey: any, type: string) { | ||
| return serialize(survey).survey.find((r: any) => r.type === type) | ||
| } | ||
|
|
||
| // Find a row in the live survey model by its $autoname (as loaded from a fixture) | ||
| export function findRowByAutoname(survey: any, autoname: string): any { | ||
| let found: any = null | ||
| survey.forEachRow((row: any) => { | ||
| const detail = row.get?.('$autoname') | ||
| if (detail?.get?.('value') === autoname) found = row | ||
| }, { includeGroups: true }) | ||
| return found | ||
| } | ||
|
|
||
| // Set a label on a live row | ||
| export function setLabel(row: any, value: string) { | ||
| row.get('label').set('value', value) | ||
| } |
There was a problem hiding this comment.
Test helpers duplicate
XlformAdapter logic, leaving the adapter uncovered
helpers.ts re-implements loadSurvey and serialize independently of XlformAdapter. Most tests (editing, skip-logic, translations, constraint, and all question-type tests) import from helpers, so they exercise this copy-pasted path rather than the actual XlformAdapter.serialize() in adapter.ts. If the adapter's serialization logic diverges in a future change, all those tests will continue to pass while the real adapter silently breaks. Only nesting.tests.ts and required.tests.ts use XlformAdapter directly. Consider having the helpers delegate to XlformAdapter to keep a single source of truth.
| @@ -0,0 +1,716 @@ | |||
| # Form Builder — Design Reference | |||
There was a problem hiding this comment.
PR description and title do not follow the repository template
Every section of the PR description (📣 Summary, 📖 Description, 👷 Description for instance maintainers, 💭 Notes, 👀 Preview steps) still contains the placeholder "TODO", the checklist has no items checked, and the PR title (add documentation and tests for form builder functionality DEV-2268) does not follow the required <type>(<scope>): <title> DEV-XXXX format. Please fill in or delete each section before merging, as required by the team's template.
Rule Used: What: PR descriptions must follow the repository's... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
🗒️ Checklist
#Support Docs Updates, if any<type>(<scope>)<!>: <title> DEV-1234Front endand/orBack endorworkflow📣 Summary
TODO
📖 Description
TODO
👷 Description for instance maintainers
TODO
💭 Notes
TODO
👀 Preview steps