diff --git a/packages/kbn-config-schema/src/types/array_type.test.ts b/packages/kbn-config-schema/src/types/array_type.test.ts
index 73661ef849cf4..66b72096a593d 100644
--- a/packages/kbn-config-schema/src/types/array_type.test.ts
+++ b/packages/kbn-config-schema/src/types/array_type.test.ts
@@ -85,14 +85,29 @@ test('fails if mixed types of content in array', () => {
);
});
-test('returns empty array if input is empty but type has default value', () => {
- const type = schema.arrayOf(schema.string({ defaultValue: 'test' }));
+test('fails if sparse content in array', () => {
+ const type = schema.arrayOf(schema.string());
expect(type.validate([])).toEqual([]);
+ expect(() => type.validate([undefined])).toThrowErrorMatchingInlineSnapshot(
+ `"[0]: sparse array are not allowed"`
+ );
});
-test('returns empty array if input is empty even if type is required', () => {
- const type = schema.arrayOf(schema.string());
+test('fails if sparse content in array if optional', () => {
+ const type = schema.arrayOf(schema.maybe(schema.string()));
+ expect(type.validate([])).toEqual([]);
+ expect(() => type.validate([undefined])).toThrowErrorMatchingInlineSnapshot(
+ `"[0]: sparse array are not allowed"`
+ );
+});
+
+test('fails if sparse content in array if nullable', () => {
+ const type = schema.arrayOf(schema.nullable(schema.string()));
expect(type.validate([])).toEqual([]);
+ expect(type.validate([null])).toEqual([null]);
+ expect(() => type.validate([undefined])).toThrowErrorMatchingInlineSnapshot(
+ `"[0]: sparse array are not allowed"`
+ );
});
test('fails for null values if optional', () => {
@@ -102,9 +117,19 @@ test('fails for null values if optional', () => {
);
});
+test('returns empty array if input is empty but type has default value', () => {
+ const type = schema.arrayOf(schema.string({ defaultValue: 'test' }));
+ expect(type.validate([])).toEqual([]);
+});
+
+test('returns empty array if input is empty even if type is required', () => {
+ const type = schema.arrayOf(schema.string());
+ expect(type.validate([])).toEqual([]);
+});
+
test('handles default values for undefined values', () => {
- const type = schema.arrayOf(schema.string({ defaultValue: 'foo' }));
- expect(type.validate([undefined])).toEqual(['foo']);
+ const type = schema.arrayOf(schema.string(), { defaultValue: ['foo'] });
+ expect(type.validate(undefined)).toEqual(['foo']);
});
test('array within array', () => {
diff --git a/packages/kbn-config-schema/src/types/array_type.ts b/packages/kbn-config-schema/src/types/array_type.ts
index ad74f375588ad..a0353e8348ddd 100644
--- a/packages/kbn-config-schema/src/types/array_type.ts
+++ b/packages/kbn-config-schema/src/types/array_type.ts
@@ -31,7 +31,7 @@ export class ArrayType
-
+ Array test setting
+
+
+ }
>
-
- Array test setting
-
-
- }
- >
-
- Array test setting
-
-
- }
- >
-
+ Array test setting
+
+
+ }
+>
+
+ Array test setting
+
+ }
>
-
- Array test setting
-
- }
- >
-
+ Array test setting
+
+
+ }
>
-
- Array test setting
-
-
- }
- >
-
+ Array test setting
+
+ }
+>
+
+ Setting is currently not saved. +
+
-
-
-
-
-
-
-
+ {unsavedChanges.error + ? unsavedChanges.error + : i18n.translate('advancedSettings.field.settingIsUnsaved', { + defaultMessage: 'Setting is currently not saved.', + })} +
+{this.renderCountOfUnsaved()}
+