From 4970dd0806351b5ab1041f473dda1a5266fc3c8f Mon Sep 17 00:00:00 2001 From: HannaKurban <96909212+HannaKurban@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:19:33 +0300 Subject: [PATCH] FIO-9143 fixed getValidationFormat error (#164) --- src/process/__tests__/process.test.ts | 103 +++++++++++++++++++++++++ src/utils/operators/DateGreaterThan.js | 6 +- 2 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/process/__tests__/process.test.ts b/src/process/__tests__/process.test.ts index 5e773860..8fa78c30 100644 --- a/src/process/__tests__/process.test.ts +++ b/src/process/__tests__/process.test.ts @@ -3509,6 +3509,109 @@ describe('Process Tests', () => { assert.equal(context.scope.errors.length, 0); }); + it('Should not return error for the form with conditionals based on the Day component', () => { + const form = { + _id: '66ffe59b598a729e707869bf', + title: '9143 condition day', + name: '9143ConditionDay', + path: '9143conditionday', + type: 'form', + display: 'form', + components: [ + { + label: 'Day', + hideInputLabels: false, + inputsLabelPosition: 'top', + useLocaleSettings: false, + tableView: false, + fields: { + day: { + hide: false + }, + month: { + hide: false + }, + year: { + hide: false + } + }, + validateWhenHidden: false, + key: 'day', + type: 'day', + input: true + }, + { + label: 'Text Field', + applyMaskOn: 'change', + tableView: true, + validateWhenHidden: false, + key: 'textField', + conditional: { + show: true, + conjunction: 'all', + conditions: [ + { + component: 'day', + operator: 'isDateEqual', + value: '09/26/2024' + } + ] + }, + type: 'textfield', + input: true + }, + { + type: 'button', + label: 'Submit', + key: 'submit', + disableOnInvalid: true, + input: true, + tableView: false + } + ], + project: '63cead09be0090345b109e22', + created: '2024-10-04T12:54:51.161Z', + modified: '2024-10-07T07:47:25.189Z', + machineName: 'idwqwhclwioyqbw:9143ConditionDay' + }; + + const submission = { + form: '66ffe59b598a729e707869bf', + owner: '63ceaccebe0090345b109da7', + data: { + day: '09/26/2024', + submit: true, + textField: 'test' + }, + _id: '6703a011275ca049014f7fab', + project: '63cead09be0090345b109e22', + state: 'submitted' + }; + + const errors: any = []; + const conditionals: any = []; + const context = { + form, + submission, + data: submission.data, + components: form.components, + processors: ProcessTargets.submission, + scope: { errors, conditionals }, + config: { + server: true, + }, + }; + + processSync(context); + submission.data = context.data; + context.processors = ProcessTargets.evaluator; + processSync(context); + expect(context.scope.conditionals).to.have.length(1); + expect(context.scope.conditionals?.[0].conditionallyHidden).to.be.false; + assert.equal(context.scope.errors.length, 0); + }) + + describe('Required component validation in nested form in DataGrid/EditGrid', () => { const nestedForm = { key: 'form', diff --git a/src/utils/operators/DateGreaterThan.js b/src/utils/operators/DateGreaterThan.js index cc545cf3..db0d82b9 100644 --- a/src/utils/operators/DateGreaterThan.js +++ b/src/utils/operators/DateGreaterThan.js @@ -11,9 +11,9 @@ export default class DateGeaterThan extends ConditionOperator { } getFormattedDates({ value, comparedValue, conditionTriggerComponent }) { - const hasValidationFormat = conditionTriggerComponent && conditionTriggerComponent.component.type === 'day' ? getDateValidationFormat(conditionTriggerComponent.component) : null; - const date = hasValidationFormat ? moment(value, conditionTriggerComponent.getValidationFormat()) : moment(value); - const comparedDate = hasValidationFormat ? moment(comparedValue, conditionTriggerComponent.getValidationFormat()) : moment(comparedValue); + const validationFormat = conditionTriggerComponent && conditionTriggerComponent.component.type === 'day' ? getDateValidationFormat(conditionTriggerComponent.component) : null; + const date = validationFormat ? moment(value, validationFormat) : moment(value); + const comparedDate = validationFormat ? moment(comparedValue, validationFormat) : moment(comparedValue); return { date, comparedDate }; }