diff --git a/src/process/__tests__/fixtures/forDataGridRequired.json b/src/process/__tests__/fixtures/forDataGridRequired.json new file mode 100644 index 00000000..30aec20e --- /dev/null +++ b/src/process/__tests__/fixtures/forDataGridRequired.json @@ -0,0 +1,91 @@ +{ + "form": { + "name": "dsf", + "path": "dsf", + "type": "form", + "display": "form", + "components": [ + { + "label": "Data Grid", + "reorder": false, + "addAnotherPosition": "bottom", + "layoutFixed": false, + "enableRowGroups": false, + "initEmpty": false, + "tableView": false, + "defaultValue": [ + {} + ], + "validate": { + "required": true + }, + "validateWhenHidden": false, + "key": "dataGrid", + "type": "datagrid", + "input": true, + "components": [ + { + "label": "Columns", + "columns": [ + { + "components": [ + { + "label": "Text Field", + "applyMaskOn": "change", + "tableView": true, + "validateWhenHidden": false, + "key": "textField", + "type": "textfield", + "input": true + } + ], + "width": 6, + "offset": 0, + "push": 0, + "pull": 0, + "size": "md", + "currentWidth": 6 + }, + { + "components": [], + "width": 6, + "offset": 0, + "push": 0, + "pull": 0, + "size": "md", + "currentWidth": 6 + } + ], + "key": "columns", + "type": "columns", + "input": false, + "tableView": false + } + ] + }, + { + "type": "button", + "label": "Submit", + "key": "submit", + "disableOnInvalid": true, + "input": true, + "tableView": false + } + ], + "created": "2024-08-07T08:41:53.926Z", + "modified": "2024-08-07T08:41:53.932Z", + "machineName": "tbtzzegecytgzpi:dsf" + }, + "submission": { + "data": { + + "dataGrid": [ + { + "textField": "" + } + ], + "submit": true + } + + } +} \ No newline at end of file diff --git a/src/process/__tests__/fixtures/index.ts b/src/process/__tests__/fixtures/index.ts index 05ef6349..b9aaf101 100644 --- a/src/process/__tests__/fixtures/index.ts +++ b/src/process/__tests__/fixtures/index.ts @@ -3,8 +3,9 @@ import clearOnHideWithHiddenParent from './clearOnHideWithHiddenParent.json'; import skipValidForConditionallyHiddenComp from './skipValidForConditionallyHiddenComp.json'; import skipValidForLogicallyHiddenComp from './skipValidForLogicallyHiddenComp.json'; import skipValidWithHiddenParentComp from './skipValidWithHiddenParentComp.json'; +import forDataGridRequired from './forDataGridRequired.json'; import data1a from './data1a.json'; import form1 from './form1.json'; import subs from './subs.json'; -export { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, skipValidForLogicallyHiddenComp, skipValidForConditionallyHiddenComp, skipValidWithHiddenParentComp, data1a, form1, subs }; +export { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, skipValidForLogicallyHiddenComp, skipValidForConditionallyHiddenComp, skipValidWithHiddenParentComp, forDataGridRequired, data1a, form1, subs }; diff --git a/src/process/__tests__/process.test.ts b/src/process/__tests__/process.test.ts index 40bc0d7a..1300d94c 100644 --- a/src/process/__tests__/process.test.ts +++ b/src/process/__tests__/process.test.ts @@ -3,7 +3,7 @@ import assert from 'node:assert' import type { ContainerComponent, ValidationScope } from 'types'; import { getComponent } from 'utils/formUtil'; import { process, processSync, ProcessTargets } from '../index'; -import { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, skipValidForConditionallyHiddenComp, skipValidForLogicallyHiddenComp, skipValidWithHiddenParentComp } from './fixtures' +import { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, forDataGridRequired, skipValidForConditionallyHiddenComp, skipValidForLogicallyHiddenComp, skipValidWithHiddenParentComp } from './fixtures' /* describe('Process Tests', () => { it('Should perform the processes using the processReduced method.', async () => { @@ -3040,6 +3040,27 @@ describe('Process Tests', () => { }); }); + it('Should validate when all child components are empty in required Data Grid', async () => { + const { form, submission } = forDataGridRequired; + const context = { + form, + submission, + data: submission.data, + components: form.components, + processors: ProcessTargets.submission, + scope: {}, + config: { + server: true, + }, + }; + + processSync(context); + context.processors = ProcessTargets.evaluator; + processSync(context); + + expect((context.scope as ValidationScope).errors).to.have.length(1); + }); + describe('For EditGrid:', () => { const components = [ {