Skip to content

Commit

Permalink
FIO-9465: fix conditionals path for panel component
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria.Golomb committed Jan 7, 2025
1 parent 3006ff3 commit 2049b9a
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 31 deletions.
141 changes: 111 additions & 30 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3242,6 +3242,85 @@ describe('Process Tests', function () {
});
});

it('Should correctly provide conditionals path for wizard panels, which affects the accuracy of validation when nested forms are presented ', async function () {
const form = {
components: [
{
type: 'radio',
label: 'Choose Form',
key: 'chooseForm',
values: [
{ label: 'Show Form A', value: 'a' },
{ label: 'Show Form B', value: 'b' },
],
input: true,
},
{
type: 'form',
key: 'formA',
conditional: {
show: true,
when: 'chooseForm',
eq: 'a',
},
components: [
{
type: 'textfield',
label: 'Field A',
key: 'fieldA',
validate: { required: true },
input: true,
},
],
input: true,
},
{
type: 'form',
key: 'formB',
conditional: {
show: true,
when: 'chooseForm',
eq: 'b',
},
components: [
{
type: 'textfield',
label: 'Field B',
key: 'fieldB',
validate: { required: true },
input: true,
},
],
input: true,
},
],
};

const submission = {
data: {
chooseForm: 'b',
formB: { data: { fieldB: 'Test Value' } },
},
};

const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: { errors: [] },
config: { server: true },
};

processSync(context);
assert.equal(context.scope.errors.length, 0);
expect((context.scope as any).conditionals).to.deep.equal([
{ path: 'formA', conditionallyHidden: true },
{ path: 'formB', conditionallyHidden: false },
]);
});

it('Should include submission data for logically visible fields', async function () {
const form = {
display: 'form',
Expand Down Expand Up @@ -4764,7 +4843,7 @@ describe('Process Tests', function () {
persistent: 'client-only',
trigger: {
init: true,
server: true
server: true,
},
dataSrc: 'url',
fetch: {
Expand All @@ -4773,8 +4852,8 @@ describe('Process Tests', function () {
headers: [
{
key: '',
value: ''
}
value: '',
},
],
mapFunction: '',
forwardHeaders: false,
Expand All @@ -4783,7 +4862,7 @@ describe('Process Tests', function () {
key: 'products',
type: 'datasource',
input: true,
tableView: false
tableView: false,
},
{
label: 'Cart',
Expand All @@ -4803,14 +4882,14 @@ describe('Process Tests', function () {
tableView: true,
dataSrc: 'custom',
data: {
custom: 'values = data.products;'
custom: 'values = data.products;',
},
valueProperty: '_id',
template: '\u003Cspan\u003E{{ item.data.name }}\u003C/span\u003E',
refreshOn: 'products',
key: 'product',
type: 'select',
input: true
input: true,
},
{
label: 'Quantity',
Expand All @@ -4824,7 +4903,7 @@ describe('Process Tests', function () {
key: 'quantity',
type: 'number',
input: true,
defaultValue: 1
defaultValue: 1,
},
{
label: 'Price',
Expand All @@ -4836,13 +4915,14 @@ describe('Process Tests', function () {
inputFormat: 'plain',
truncateMultipleSpaces: false,
redrawOn: 'cart.product',
calculateValue: 'var productId = row.product;\nvalue = 0;\nif (productId && data.products && data.products.length) {\n data.products.forEach(function(product) {\n if (product._id === productId) {\n value = product.data.price * (row.quantity || 1);\n }\n });\n}',
calculateValue:
'var productId = row.product;\nvalue = 0;\nif (productId && data.products && data.products.length) {\n data.products.forEach(function(product) {\n if (product._id === productId) {\n value = product.data.price * (row.quantity || 1);\n }\n });\n}',
calculateServer: true,
key: 'price',
type: 'number',
input: true
}
]
input: true,
},
],
},
{
label: 'Total',
Expand All @@ -4854,25 +4934,26 @@ describe('Process Tests', function () {
inputFormat: 'plain',
truncateMultipleSpaces: false,
redrawOn: 'cart',
calculateValue: 'if (data.cart && data.cart.length) {\n value = data.cart.reduce(function(total, cartItem) {\n return total + cartItem.price;\n }, 0);\n}',
calculateValue:
'if (data.cart && data.cart.length) {\n value = data.cart.reduce(function(total, cartItem) {\n return total + cartItem.price;\n }, 0);\n}',
calculateServer: true,
key: 'total',
type: 'number',
input: true
input: true,
},
{
type: 'button',
label: 'Submit',
key: 'submit',
disableOnInvalid: true,
input: true,
tableView: false
}
tableView: false,
},
],
created: '2024-12-06T07:52:40.891Z',
modified: '2024-12-06T08:33:40.971Z',
config: {
appUrl: 'http://localhost:3000/idwqwhclwioyqbw'
appUrl: 'http://localhost:3000/idwqwhclwioyqbw',
},
};

Expand All @@ -4881,37 +4962,37 @@ describe('Process Tests', function () {
_id: '6752adf3eda1569ebc9ab0cd',
data: {
name: 'Cream',
price: 30
price: 30,
},
},
{
_id: '6752adf4eda1569ebc9ab0df',
data: {
name: 'Perfume',
price: 100
price: 100,
},
},
{
_id: '6752adf4eda1569ebc9ab0f1',
data: {
name: 'Soap',
price: 5
price: 5,
},
},
{
_id: '6752adf4eda1569ebc9ab103',
data: {
name: 'Toothpaste',
price: 10
price: 10,
},
},
{
_id: '6752adf4eda1569ebc9ab115',
data: {
name: 'Shampoo',
price: 20
price: 20,
},
}
},
];

const submission = {
Expand All @@ -4920,23 +5001,23 @@ describe('Process Tests', function () {
{
product: '6752adf4eda1569ebc9ab115',
quantity: 5,
price: 100
price: 100,
},
{
product: '6752adf4eda1569ebc9ab103',
quantity: 3,
price: 30
price: 30,
},
{
product: '6752adf4eda1569ebc9ab0df',
quantity: 2,
price: 200
}
price: 200,
},
],
total: 330,
submit: true
submit: true,
},
state: 'submitted'
state: 'submitted',
};

const context = {
Expand All @@ -4950,8 +5031,8 @@ describe('Process Tests', function () {
return Promise.resolve({
ok: true,
json: () => {
return Promise.resolve(resource);
}
return Promise.resolve(resource);
},
} as Response);
},
config: {
Expand Down
7 changes: 6 additions & 1 deletion src/process/conditions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
isSimpleConditional,
isJSONConditional,
} from 'utils/conditions';
import { getComponentPaths } from '../../utils/formUtil/index';

const hasCustomConditions = (context: ConditionsContext): boolean => {
const { component } = context;
Expand Down Expand Up @@ -93,7 +94,11 @@ export const conditionalProcess = (context: ConditionsContext, isHidden: Conditi
}
let conditionalComp = scope.conditionals.find((cond) => cond.path === path);
if (!conditionalComp) {
conditionalComp = { path, conditionallyHidden: false };
const conditionalPath = path ? path : getComponentPaths(component).fullPath || '';
conditionalComp = {
path: conditionalPath,
conditionallyHidden: false,
};
scope.conditionals.push(conditionalComp);
}

Expand Down

0 comments on commit 2049b9a

Please sign in to comment.