From 8409b2c19f7bf6eed1176dbd7a28f0c5c83d9f0d Mon Sep 17 00:00:00 2001 From: Alexey Nikipelau Date: Fri, 19 Apr 2024 16:47:05 +0300 Subject: [PATCH] add tests --- src/process/__tests__/process.test.ts | 167 ++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) diff --git a/src/process/__tests__/process.test.ts b/src/process/__tests__/process.test.ts index 2bd382e4..cbdf2186 100644 --- a/src/process/__tests__/process.test.ts +++ b/src/process/__tests__/process.test.ts @@ -1,5 +1,7 @@ import { expect } from "chai"; import { processSync, ProcessTargets } from "../index"; +import { validate } from 'fast-json-patch'; +import { ValidationScope } from 'types'; const assert = require('assert'); const form1 = require('./fixtures/form1.json'); const data1a = require('./fixtures/data1a.json'); @@ -2767,6 +2769,171 @@ describe('Process Tests', () => { ] }); }); + + describe('Required component validation in nested form in DataGrid/EditGrid', () => { + const nestedForm = [ + { + key: 'form', + type: 'form', + input: true, + components: [ + { + key: 'textField', + type: 'textfield', + validate: { + required: true + }, + input: true + } + ] + }, + ] + + describe('For DataGrid:', () => { + const components = [ + { + key: 'dataGrid', + type: 'datagrid', + input: true, + components: nestedForm, + } + ]; + it('Should validate required component when it is filled out', async () => { + const submission = { + data: { + dataGrid: [ + { + form: { + data: { + textField: 'test' + } + } + } + ] + } + }; + + const context = { + form: { components }, + submission, + data: submission.data, + 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(0); + }); + it('Should not validate required component when it is not filled out', async () => { + const submission = { + data: { + dataGrid: [ + { + form: { + data: { + textField: '' + } + } + } + ] + } + }; + + const context = { + form: { components }, + submission, + data: submission.data, + 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 = [ + { + key: 'editGrid', + type: 'editgrid', + input: true, + components: nestedForm, + } + ]; + it('Should validate required component when it is filled out', async () => { + const submission = { + data: { + editGrid: [ + { + form: { + data: { + textField: 'test' + } + } + } + ] + } + }; + + const context = { + form: { components }, + submission, + data: submission.data, + 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(0); + }); + it('Should not validate required component when it is not filled out', async () => { + const submission = { + data: { + editGrid: [ + { + form: { + data: { + textField: '' + } + } + } + ] + } + }; + + const context = { + form: { components }, + submission, + data: submission.data, + 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); + }); + }); + }) /* it('Should not clearOnHide when set to false', async () => { var components = [