Skip to content

Commit

Permalink
FIO-8731: Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekotikov committed Aug 2, 2024
1 parent bd6d08b commit e642308
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/process/__tests__/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import clearOnHideWithCustomCondition from './clearOnHideWithCustomCondition.json';
import clearOnHideWithHiddenParent from './clearOnHideWithHiddenParent.json';
import skipValidForConditionallyHiddenComp from './skipValidForConditionallyHiddenComp.json';
import skipValidForLogicallyHiddenComp from './skipValidForLogicallyHiddenComp.json';
import skipValidWithHiddenParentComp from './skipValidWithHiddenParentComp.json';
import data1a from './data1a.json';
import form1 from './form1.json';
import subs from './subs.json';

export { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, data1a, form1, subs };
export { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, skipValidForLogicallyHiddenComp, skipValidForConditionallyHiddenComp, skipValidWithHiddenParentComp, data1a, form1, subs };
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"form": {
"name": "conditional",
"path": "conditional",
"type": "form",
"display": "form",
"components": [
{
"label": "Checkbox",
"tableView": false,
"validateWhenHidden": false,
"key": "checkbox",
"type": "checkbox",
"input": true
},
{
"collapsible": false,
"key": "panel",
"conditional": {
"show": false,
"conjunction": "all",
"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-08-02T10:28:35.696Z",
"modified": "2024-08-02T10:28:35.704Z"
},
"submission": {
"data": {
"checkbox": true,
"submit": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"form": {
"type": "form",
"display": "form",
"components": [
{
"label": "Checkbox",
"tableView": false,
"validateWhenHidden": false,
"key": "checkbox",
"type": "checkbox",
"input": true
},
{
"collapsible": false,
"key": "panel",
"logic": [
{
"name": "1",
"trigger": {
"type": "simple",
"simple": {
"show": true,
"conjunction": "all",
"conditions": [
{
"component": "checkbox",
"operator": "isEqual",
"value": true
}
]
}
},
"actions": [
{
"name": "12",
"type": "property",
"property": {
"label": "Hidden",
"value": "hidden",
"type": "boolean"
},
"state": 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-08-02T10:28:35.696Z",
"modified": "2024-08-02T10:28:35.704Z"
},
"submission": {
"data": {
"checkbox": true,
"submit": true
}
}
}

55 changes: 55 additions & 0 deletions src/process/__tests__/fixtures/skipValidWithHiddenParentComp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"form": {
"type": "form",
"display": "form",
"components": [
{
"label": "Checkbox",
"tableView": false,
"validateWhenHidden": false,
"key": "checkbox",
"type": "checkbox",
"input": true
},
{
"collapsible": false,
"hidden": true,
"key": "panel",
"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-08-02T11:13:50.020Z",
"modified": "2024-08-02T11:14:14.155Z"
},
"submission": {
"data": {
"checkbox": true,
"submit": true
}
}
}
64 changes: 62 additions & 2 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { expect } from 'chai';
import assert from 'node:assert'
import type { ContainerComponent, ValidationScope } from 'types';
import { getComponent } from 'utils/formUtil';
import { processSync, ProcessTargets } from '../index';
import { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, } from './fixtures'
import { process, processSync, ProcessTargets } from '../index';
import { clearOnHideWithCustomCondition, clearOnHideWithHiddenParent, skipValidForConditionallyHiddenComp, skipValidForLogicallyHiddenComp, skipValidWithHiddenParentComp } from './fixtures'
/*
describe('Process Tests', () => {
it('Should perform the processes using the processReduced method.', async () => {
Expand Down Expand Up @@ -2904,6 +2904,66 @@ describe('Process Tests', () => {
});
});

it('Should skip child validation with conditional', 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);
});

it('Should skip child validation with hidden parent component', async () => {
const { form, submission } = skipValidWithHiddenParentComp;
const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true,
},
};

await process(context);
context.processors = ProcessTargets.evaluator;
await process(context);
expect((context.scope as ValidationScope).errors).to.have.length(0);
});

it('Should skip child validation with logic', async () => {
const { form, submission } = skipValidForLogicallyHiddenComp;
const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true,
},
};

processSync(context as any);
context.processors = ProcessTargets.evaluator;
processSync(context as any);
expect((context.scope as ValidationScope).errors).to.have.length(0);
});

it('Should not return fields from conditionally hidden containers, clearOnHide = false', async () => {
const { form, submission } = clearOnHideWithCustomCondition;
const containerComponent = getComponent(form.components, 'section6') as ContainerComponent;
Expand Down

0 comments on commit e642308

Please sign in to comment.