From 879d25198c19c7463fd548e098cd20149e05e8d9 Mon Sep 17 00:00:00 2001 From: "J. Quak" Date: Mon, 18 Nov 2024 10:50:53 +0100 Subject: [PATCH] feat: add createActionInputVariable (#475) * feat: add createActionInputVariable * fix: add value key * fix: make name optional * fix: make value optional --------- Co-authored-by: Jordy Quak --- __tests__/validations/component.test.tsx | 32 +++++++++++++++++++++++ src/validations/prefab/componentOption.ts | 11 ++++++++ 2 files changed, 43 insertions(+) diff --git a/__tests__/validations/component.test.tsx b/__tests__/validations/component.test.tsx index 1a19b208..0afafdfc 100644 --- a/__tests__/validations/component.test.tsx +++ b/__tests__/validations/component.test.tsx @@ -1175,3 +1175,35 @@ test('Success when value is an array with empty string in variable option', (t: t.notThrows(() => validatePrefabs(prefabs, {})); }); + +test('Success when adding createActionInputVariable in the option configuration of an ACTION_JS_INPUT', (t: Context): void => { + const prefabs: Prefab[] = [ + { + name: 'Component Name', + icon: 'TitleIcon', + category: 'CONTENT', + structure: [ + { + name: 'something', + options: [ + { + value: [''], + label: 'something', + key: 'something', + type: 'ACTION_JS_VARIABLE', + configuration: { + createActionInputVariable: { + name: 'Test Name', + type: 'STRING', + }, + }, + }, + ], + descendants: [], + }, + ], + }, + ]; + + t.notThrows(() => validatePrefabs(prefabs, {})); +}); diff --git a/src/validations/prefab/componentOption.ts b/src/validations/prefab/componentOption.ts index db15589b..5f3c806a 100644 --- a/src/validations/prefab/componentOption.ts +++ b/src/validations/prefab/componentOption.ts @@ -90,6 +90,17 @@ const optionConfigurationSchema = Joi.when('type', { }), otherwise: Joi.object(optionConfigurationSchemaBase), }) + .when('type', { + is: 'ACTION_JS_VARIABLE', + then: Joi.object({ + ...optionConfigurationSchemaBase, + createActionInputVariable: Joi.object({ + name: Joi.string().optional(), + type: Joi.string().required(), + value: Joi.string().allow('').optional(), + }), + }), + }) .when('type', { is: 'VARIABLE', then: Joi.object({