diff --git a/src/layouts/schema.json b/src/layouts/schema.json index 0adc1c3b..c6bd3332 100644 --- a/src/layouts/schema.json +++ b/src/layouts/schema.json @@ -4,98 +4,95 @@ "description": "JSON Schema of the dynamic form definition with visibility rules, validation criteria, etc", "type": "array", "items": { - "type": "object", - "properties": { - "rules": { - "type": "array", - "items": { - "type": "object", - "properties": { - "field": { - "type": "string" - }, - "op": { - "type": "string", - "enum": [ - "eq", "gt", "gte", "lt", "lte", "in", "contains" - ] - }, - "value": { - "type": ["string", "number", "boolean"] - } - }, - "required": ["field", "op", "value"] + "$ref": "#/definitions/WelcomeElement" + }, + "definitions": { + "WelcomeElement": { + "type": "object", + "additionalProperties": false, + "properties": { + "rules": { + "type": "array", + "items": { + "$ref": "#/definitions/Rule" + } + }, + "fields": { + "type": "array", + "items": { + "$ref": "#/definitions/Field" + } } }, - "fields": { - "type": "array", - "items": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "label": { - "type": "string" - }, - "description": { - "type": "string" - }, - "type": { - "type": "string", - "enum": [ - "choice", "text", "password", "numeric", "date", "datetime", "checkbox", "radio", "file", "textarea", "multichoice" - ] - }, - "default_value": { - "type": ["string", "number", "object", "boolean"] - }, - "validation": { - "type": "array", - "items": { - "type": "string" - }, - "uniqueItems": true - } - }, - "required": [ - "name", "label", "type" - ], - "if": { - "properties": { - "type": { - "enum": [ - "choice", "checkbox", "radio", "multichoice" - ] - } - } - }, - "then": { - "properties": { - "options": { - "type": "array", - "items": { - "$ref": "#/definitions/optionItem" - }, - "minItems": 1 - } - }, - "required": ["options"] + "required": [ + "fields" + ], + "title": "WelcomeElement" + }, + "Field": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "label": { + "type": "string" + }, + "type": { + "type": "string" + }, + "dataSource": { + "$ref": "#/definitions/DataSource" + }, + "defaultValue": { + "$ref": "#/definitions/DefaultValue" + }, + "options": { + "type": "array", + "items": { + "$ref": "#/definitions/Option" } }, - "minItems": 1 - } - } - }, - "required": [ - "fields" - ], - "definitions": { - "optionItem": { + "description": { + "type": "string" + }, + "validation": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "label", + "name", + "type" + ], + "title": "Field" + }, + "DataSource": { "type": "object", + "additionalProperties": false, + "properties": { + "getOptions": { + "type": "array", + "items": { + "$ref": "#/definitions/GetOption" + } + } + }, + "required": [ + "getOptions" + ], + "title": "DataSource" + }, + "GetOption": { + "type": "object", + "additionalProperties": false, "properties": { "value": { - "type": ["string", "number"] + "type": "integer" }, "label": { "type": "string" @@ -103,11 +100,90 @@ "children": { "type": "array", "items": { - "$ref": "#/definitions/optionItem" + "$ref": "#/definitions/Child" } } }, - "required": ["value", "label"] + "required": [ + "label", + "value" + ], + "title": "GetOption" + }, + "Child": { + "type": "object", + "additionalProperties": false, + "properties": { + "value": { + "type": "integer" + }, + "label": { + "type": "string" + }, + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/Option" + } + } + }, + "required": [ + "label", + "value" + ], + "title": "Child" + }, + "Option": { + "type": "object", + "additionalProperties": false, + "properties": { + "value": { + "type": "integer" + }, + "label": { + "type": "string" + } + }, + "required": [ + "label", + "value" + ], + "title": "Option" + }, + "Rule": { + "type": "object", + "additionalProperties": false, + "properties": { + "field": { + "type": "string" + }, + "op": { + "type": "string" + }, + "value": { + "type": "integer" + } + }, + "required": [ + "field", + "op", + "value" + ], + "title": "Rule" + }, + "DefaultValue": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "integer" + } + }, + { + "type": "string" + } + ], + "title": "DefaultValue" } } -} \ No newline at end of file +} diff --git a/tests/jest/Components/Choices/__snapshots__/testDropDown.jsx.snap b/tests/jest/Components/Choices/__snapshots__/testDropDown.jsx.snap index c6ee6368..8fa0101b 100644 --- a/tests/jest/Components/Choices/__snapshots__/testDropDown.jsx.snap +++ b/tests/jest/Components/Choices/__snapshots__/testDropDown.jsx.snap @@ -9,119 +9,134 @@ exports[`>>> DropDown --- Snapshot +++capturing Snapshot of DropDown 1`] = ` className="dp-pc_field" >
-
-
- - First - + First
-
- + +
+ +
-
- +
+ - - - + onTouchEnd={[Function]} + > + +
+
+ >> DropDown --- Snapshot', () => { ]; const App = () => (
- + ); const FormikApp = withFormik({ diff --git a/tests/jest/Layouts/layout.js b/tests/jest/Layouts/layout.js index 9974fee9..73c5696f 100644 --- a/tests/jest/Layouts/layout.js +++ b/tests/jest/Layouts/layout.js @@ -1,6 +1,6 @@ import Ajv from 'ajv'; -import ticketFormLayout from '../../../src/layouts/ticketFormLayout'; +import ticketFormLayout from '../../DemoState/ticketFormLayout'; import layoutSchema from '../../../src/layouts/schema.json'; import { LayoutConfig, LayoutField } from '../../../src/layouts/Layout'; @@ -33,7 +33,7 @@ describe('>>> Layout helper class', () => { it('should get property of the field by path', () => { const match = layouts.getMatchingLayout({ department: 7 }); - expect(match.fields[1].get('options[0].label')).toEqual('Support'); + expect(match.fields[1].get('dataSource.getOptions[0].label')).toEqual('Support'); }); });