Skip to content

Commit

Permalink
Add nested arrays parseAsJSON test case
Browse files Browse the repository at this point in the history
the getPreviousStringType also helps cover this use case, but it seems worth having a little extra coverage
  • Loading branch information
acusti committed May 10, 2024
1 parent 9519502 commit 20a0e98
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/parsing/src/parse-as-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('@acusti/parsing', () => {
'detects an object key with a missing value and fills it in',
missingValuesTestCase,
);
it('handles nested arrays without issue', nestedArraysTestCase);
});
});

Expand Down Expand Up @@ -779,3 +780,32 @@ function missingValuesTestCase() {
],
});
}

function nestedArraysTestCase() {
const response = `{"heading": "Registration Form", "items": [{"heading": "Personal Information", "fields": [{"label": "Name", "name": "name", "type": "text", "placeholder": "Enter your name"}, {"label": "Gender", "name": "gender", "type": "select", "options": ["Male", "Female", "Other"], "placeholder": "Select your gender"}]}], "button": "Next: Security Details"}]}<|im_end|>`;

expect(parseAsJSON(response)).toEqual({
heading: 'Registration Form',
items: [
{
heading: 'Personal Information',
fields: [
{
label: 'Name',
name: 'name',
placeholder: 'Enter your name',
type: 'text',
},
{
label: 'Gender',
name: 'gender',
type: 'select',
options: ['Male', 'Female', 'Other'],
placeholder: 'Select your gender',
},
],
},
],
button: 'Next: Security Details',
});
}

0 comments on commit 20a0e98

Please sign in to comment.