Repository: mozilla-services/react-jsonschema-form
Pull request #1306 (2019-06-03 00:49:18)

Add test to concat required dependencies
### Reasons for making this change

Add a test to demonstrate the use of concatArrays in #998.


Patch:
diff --git a/package.json b/package.json
index 7c9667d3a..27df3da34 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "react-jsonschema-form",
-  "version": "1.5.0",
+  "version": "1.6.0",
   "description": "A simple React component capable of building HTML forms out of a JSON schema.",
   "scripts": {
     "build:lib": "rimraf lib && cross-env NODE_ENV=production babel -d lib/ src/",
diff --git a/src/components/fields/ArrayField.js b/src/components/fields/ArrayField.js
index 4f0d5781a..a232ef2ab 100644
--- a/src/components/fields/ArrayField.js
+++ b/src/components/fields/ArrayField.js
@@ -422,6 +422,8 @@ class ArrayField extends Component {
       disabled,
       readonly,
       required,
+      label,
+      placeholder,
       autofocus,
       onBlur,
       onFocus,
@@ -446,10 +448,13 @@ class ArrayField extends Component {
         onFocus={onFocus}
         options={options}
         schema={schema}
+        registry={registry}
         value={items}
         disabled={disabled}
         readonly={readonly}
         required={required}
+        label={label}
+        placeholder={placeholder}
         formContext={formContext}
         autofocus={autofocus}
         rawErrors={rawErrors}
diff --git a/src/components/fields/SchemaField.js b/src/components/fields/SchemaField.js
index 3fc14f582..0b7038afc 100644
--- a/src/components/fields/SchemaField.js
+++ b/src/components/fields/SchemaField.js
@@ -373,6 +373,7 @@ function SchemaFieldRender(props) {
           baseType={schema.type}
           registry={registry}
           safeRenderCompletion={props.safeRenderCompletion}
+          schema={schema}
           uiSchema={uiSchema}
         />
       )}
@@ -391,6 +392,7 @@ function SchemaFieldRender(props) {
           baseType={schema.type}
           registry={registry}
           safeRenderCompletion={props.safeRenderCompletion}
+          schema={schema}
           uiSchema={uiSchema}
         />
       )}
diff --git a/src/utils.js b/src/utils.js
index 6ae4851dd..82fa1bbe0 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -212,7 +212,7 @@ function computeDefaults(schema, parentDefaults, definitions, formData) {
             return defaultEntries.concat(fillerEntries);
           }
         } else {
-          return [];
+          return defaults ? defaults : [];
         }
       }
   }


Test patch:
diff --git a/test/utils_test.js b/test/utils_test.js
index 7308a83fd..73960dfb2 100644
--- a/test/utils_test.js
+++ b/test/utils_test.js
@@ -316,6 +316,27 @@ describe("utils", () => {
           array: ["foo"],
         });
       });
+
+      it("defaults passed along for multiselect arrays when minItems is present", () => {
+        const schema = {
+          type: "object",
+          properties: {
+            array: {
+              type: "array",
+              minItems: 1,
+              uniqueItems: true,
+              default: ["foo", "qux"],
+              items: {
+                type: "string",
+                enum: ["foo", "bar", "fuzz", "qux"],
+              },
+            },
+          },
+        };
+        expect(getDefaultFormState(schema, {})).eql({
+          array: ["foo", "qux"],
+        });
+      });
     });
 
     describe("defaults with oneOf", () => {
@@ -1045,6 +1066,34 @@ describe("utils", () => {
               },
             });
           });
+          it("should concat required properties", () => {
+            const schema = {
+              type: "object",
+              properties: {
+                a: { type: "string" },
+                b: { type: "integer" },
+              },
+              required: ["a"],
+              dependencies: {
+                a: {
+                  properties: {
+                    a: { type: "string" },
+                  },
+                  required: ["b"],
+                },
+              },
+            };
+            const definitions = {};
+            const formData = { a: "1" };
+            expect(retrieveSchema(schema, definitions, formData)).eql({
+              type: "object",
+              properties: {
+                a: { type: "string" },
+                b: { type: "integer" },
+              },
+              required: ["a", "b"],
+            });
+          });
         });
 
         describe("with $ref in dependency", () => {