Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-8731: Add test case to check that validation is not touching hidden fields #124

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/process/__tests__/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import skipValidForConditionallyHiddenComp from './skipValidForConditionallyHiddenComp.json';
import data1a from './data1a.json';
import form1 from './form1.json';
import subs from './subs.json';

export { skipValidForConditionallyHiddenComp, data1a, form1, subs };
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"form": {
"title": "req",
"name": "req",
"path": "req",
"type": "form",
"display": "form",
"tags": [],
"components": [
{
"label": "hello there",
"applyMaskOn": "change",
"tableView": true,
"validateWhenHidden": false,
"key": "helloThere",
"type": "textfield",
"input": true
},
{
"label": "Checkbox",
"tableView": false,
"validateWhenHidden": false,
"key": "checkbox",
"type": "checkbox",
"input": true
},
{
"collapsible": false,
"key": "panel",
"conditional": {
"show": false,
"conjunction": "any",
"conditions": [
{
"component": "checkbox",
"operator": "isEqual",
"value": true
}
]
},
"type": "panel",
"label": "Panel",
"input": false,
"tableView": false,
"components": [
{
"label": "Text Field",
"applyMaskOn": "change",
"tableView": true,
"validate": {
"required": true
},
"validateWhenHidden": false,
"key": "textField",
"type": "textfield",
"input": true
}
]
},
{
"type": "button",
"label": "Submit",
"key": "submit",
"disableOnInvalid": true,
"input": true,
"tableView": false
}
],
"created": "2024-07-29T13:38:39.681Z",
"modified": "2024-07-29T13:39:19.804Z"
},
"submission": {
"data": {
"helloThere": "",
"checkbox": true,
"submit": true
}
}
}
51 changes: 35 additions & 16 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { expect } from 'chai';
import { processSync, ProcessTargets } from '../index';
import { ValidationScope } from 'types';
import { skipValidForConditionallyHiddenComp } from './fixtures';
const assert = require('assert');
const form1 = require('./fixtures/form1.json');
const data1a = require('./fixtures/data1a.json');
const subs = require('./fixtures/subs.json');
/*
describe('Process Tests', () => {
it('Should perform the processes using the processReduced method.', async () => {
Expand Down Expand Up @@ -831,7 +829,7 @@ describe('Process Tests', () => {
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
pathName: '/',
onLine: true,

},
data: {
number: 23,
Expand Down Expand Up @@ -947,7 +945,7 @@ describe('Process Tests', () => {
},
owner: '65ea3601c3792e416cabcb2a',
access: [],

_vnote: '',
state: 'submitted',
form: '65ea368b705068f84a93c87a',
Expand All @@ -970,7 +968,7 @@ describe('Process Tests', () => {
context.processors = ProcessTargets.evaluator;
processSync(context);
console.log(context.scope.errors);

assert.equal(context.scope.errors.length, 0);
});
it('should remove submission data not in a nested form definition', async function () {
Expand Down Expand Up @@ -2897,7 +2895,7 @@ describe('Process Tests', () => {
"label": "Appointees",
"hideLabel": true,
"tableView": false,

"addAnother": "__add_appointee",
"modal": true,
"saveRow": "Close",
Expand Down Expand Up @@ -3016,7 +3014,7 @@ describe('Process Tests', () => {
"state": "draft"
}
],

};
const submission = {
"data": {
Expand Down Expand Up @@ -3056,10 +3054,11 @@ describe('Process Tests', () => {
submit: true

});

})

it('Should not return fields from conditionally hidden containers, clearOnHide = false', async () => {

const TestForm45588WithClearOnHideFalse = {
display: 'form',
"components": [
Expand All @@ -3077,7 +3076,7 @@ describe('Process Tests', () => {
"label": "Appointees",
"hideLabel": true,
"tableView": false,

"addAnother": "__add_appointee",
"modal": true,
"saveRow": "Close",
Expand Down Expand Up @@ -3196,9 +3195,9 @@ describe('Process Tests', () => {
"state": "draft"
}
],

};

const submission = {
"data": {
"candidates": [
Expand Down Expand Up @@ -3281,7 +3280,7 @@ describe('Process Tests', () => {
textField: 'test',
invalidField: 'bad',
},

},
},
{
Expand All @@ -3306,7 +3305,7 @@ describe('Process Tests', () => {
context.processors = ProcessTargets.evaluator;
processSync(context);
console.log(JSON.stringify(context.data, null, 2));

expect((context.scope as ValidationScope).errors).to.have.length(0);
expect(context.data).to.deep.equal({
editGrid: [{ form: { data: { textField: 'test' } } }],
Expand Down Expand Up @@ -3343,7 +3342,27 @@ describe('Process Tests', () => {
processSync(context);
expect((context.scope as ValidationScope).errors).to.have.length(1);
});


it('Should not validate component if it is hidden', async () => {
const { form, submission } = skipValidForConditionallyHiddenComp;
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(0);
});

});
});
/*
Expand Down
Loading