From 20a0e98ef99b211ee44b551b7854b134259dba36 Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Fri, 10 May 2024 10:03:12 -0700 Subject: [PATCH] Add nested arrays parseAsJSON test case the getPreviousStringType also helps cover this use case, but it seems worth having a little extra coverage --- packages/parsing/src/parse-as-json.test.ts | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/parsing/src/parse-as-json.test.ts b/packages/parsing/src/parse-as-json.test.ts index a6b10ca0..d8f3f19d 100644 --- a/packages/parsing/src/parse-as-json.test.ts +++ b/packages/parsing/src/parse-as-json.test.ts @@ -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); }); }); @@ -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', + }); +}