diff --git a/__tests__/validations/component.test.tsx b/__tests__/validations/component.test.tsx index 40f2576a..1a19b208 100644 --- a/__tests__/validations/component.test.tsx +++ b/__tests__/validations/component.test.tsx @@ -1069,6 +1069,32 @@ test('Success when the optionRefs of the prefabs are valid', (t: Context): void t.notThrows(() => validatePrefabs(prefabs, {})); }); +test('Throws error when value is an empty string in variable option', (t: Context): void => { + const prefabs: Prefab[] = [ + { + name: 'Test Component', + icon: 'PencilIcon', + category: 'LAYOUT', + structure: [ + { + name: 'option', + options: [ + { + value: '', + label: 'label', + key: 'key', + type: 'VARIABLE', + }, + ], + descendants: [], + }, + ], + }, + ]; + + t.throws(() => validatePrefabs(prefabs, {})); +}); + test('Does not throw when wrapper option has a optionRef', (t: Context): void => { const prefabs = [ { @@ -1123,3 +1149,29 @@ test('Does not throw when wrapper option has a optionRef', (t: Context): void => t.notThrows(() => validatePrefabs(prefabs, {})); }); + +test('Success when value is an array with empty string in variable option', (t: Context): void => { + const prefabs: Prefab[] = [ + { + name: 'Component Name', + icon: 'TitleIcon', + category: 'CONTENT', + structure: [ + { + name: 'something', + options: [ + { + value: [''], + label: 'something', + key: 'something', + type: 'VARIABLE', + }, + ], + descendants: [], + }, + ], + }, + ]; + + t.notThrows(() => validatePrefabs(prefabs, {})); +}); diff --git a/src/types.ts b/src/types.ts index 1417e2b6..5c77f269 100644 --- a/src/types.ts +++ b/src/types.ts @@ -275,7 +275,7 @@ export interface PrefabComponentOptionBase { } export interface ValueDefault { - value: string | ValueConfig; + value: string | string[] | ValueConfig; ref?: { id?: string }; } diff --git a/src/validations/prefab/componentOption.ts b/src/validations/prefab/componentOption.ts index d10ca41e..db15589b 100644 --- a/src/validations/prefab/componentOption.ts +++ b/src/validations/prefab/componentOption.ts @@ -138,6 +138,16 @@ const OptionRefInheritObject = Joi.object({ useKey: Joi.string(), }); +const optionValueSchema = Joi.when('ref', { + is: Joi.object({ value: Joi.exist() }).exist(), + then: Joi.forbidden(), + otherwise: Joi.any(), +}).when('type', { + is: 'VARIABLE', + then: Joi.array().items(Joi.string().allow('')).required(), + otherwise: Joi.any(), +}); + export const optionSchema = Joi.object({ label: Joi.string().required(), key: Joi.string().required(), @@ -145,11 +155,7 @@ export const optionSchema = Joi.object({ .valid(...OPTIONS) .required(), configuration: optionConfigurationSchema, - value: Joi.when('ref', { - is: Joi.object({ value: Joi.exist() }).exist(), - then: Joi.forbidden(), - otherwise: Joi.any(), - }), + value: optionValueSchema, showInAddChild: Joi.boolean(), showInReconfigure: Joi.boolean(), ref: refSchema,