Skip to content

Commit

Permalink
FIO-9143 fixed getValidationFormat error (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
HannaKurban authored Oct 7, 2024
1 parent 9c6493c commit 4970dd0
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 3 deletions.
103 changes: 103 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions src/utils/operators/DateGreaterThan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down

0 comments on commit 4970dd0

Please sign in to comment.