Skip to content

Commit

Permalink
chore: add expression field test coverage
Browse files Browse the repository at this point in the history
Related to #1151
  • Loading branch information
Skaiir committed Apr 16, 2024
1 parent 7565fc3 commit 4bebb52
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
41 changes: 40 additions & 1 deletion packages/form-js-viewer/test/spec/Form.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, fireEvent, screen } from '@testing-library/preact/pure';
import { act, fireEvent, screen, waitFor } from '@testing-library/preact/pure';

import { createForm, Form, schemaVersion } from '../../src';

Expand All @@ -12,6 +12,8 @@ import conditionErrorsDynamicListSchema from './condition-errors-dynamic-list.js
import dynamicListVariablesSchema from './dynamic-list-variables.json';
import dynamicListTableFilterInteractionSchema from './dynamic-list-table-filter-interaction.json';
import complexExpressionsSchema from './complex-expressions.json';
import cyclicalExpressionsSchema from './cyclical-expressions.json';
import chainExpressionsSchema from './chain-expressions.json';
import hiddenFieldsConditionalSchema from './hidden-fields-conditional.json';
import hiddenFieldsExpressionSchema from './hidden-fields-expression.json';
import disabledSchema from './disabled.json';
Expand Down Expand Up @@ -1541,6 +1543,43 @@ describe('Form', function () {
// then
expect(container.querySelectorAll('.fjs-layout-row')).to.have.length(5);
});

it('should render cyclical expressions', async function () {
const initialData = {
exprA: 2,
exprB: 3,
};

// given
await bootstrapForm({
initialData,
container,
schema: cyclicalExpressionsSchema,
});

// then
expect(container.querySelectorAll('.fjs-layout-row')).to.have.length(2);
});

it('should render chain expressions', async function () {
// given
await bootstrapForm({
container,
schema: chainExpressionsSchema,
});

// then
expect(container.querySelectorAll('.fjs-layout-row')).to.have.length(4);

await waitFor(() => {
expect(form._getState().data).to.eql({
staticValue: 10,
exprA: 20,
exprB: 40,
exprC: 50,
});
});
});
});

describe('integration - hidden fields', function () {
Expand Down
41 changes: 41 additions & 0 deletions packages/form-js-viewer/test/spec/chain-expressions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"components": [
{
"computeOn": "change",
"type": "expression",
"id": "Field_staticValue",
"key": "staticValue",
"expression": "=10"
},
{
"computeOn": "change",
"type": "expression",
"id": "Field_exprA",
"key": "exprA",
"expression": "=staticValue + 10"
},
{
"computeOn": "change",
"type": "expression",
"id": "Field_exprB",
"key": "exprB",
"expression": "=exprA * 2"
},
{
"computeOn": "change",
"type": "expression",
"id": "Field_exprC",
"key": "exprC",
"expression": "=exprB + 10"
}
],
"type": "default",
"id": "Form_non_cyclic_example",
"executionPlatform": "Camunda Cloud",
"executionPlatformVersion": "8.5.0",
"exporter": {
"name": "Camunda Modeler",
"version": "5.22.0"
},
"schemaVersion": 16
}
27 changes: 27 additions & 0 deletions packages/form-js-viewer/test/spec/cyclical-expressions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"components": [
{
"computeOn": "change",
"type": "expression",
"id": "Field_exprA",
"key": "exprA",
"expression": "=exprB + 10"
},
{
"computeOn": "change",
"type": "expression",
"id": "Field_exprB",
"key": "exprB",
"expression": "=exprA * 2"
}
],
"type": "default",
"id": "Form_cyclic_example",
"executionPlatform": "Camunda Cloud",
"executionPlatformVersion": "8.5.0",
"exporter": {
"name": "Camunda Modeler",
"version": "5.22.0"
},
"schemaVersion": 16
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Injector } from 'didi';
import { MarkdownRenderer, FeelersTemplating, FormFields, RepeatRenderManager } from '../../../../../../src';
import {
MarkdownRenderer,
FeelersTemplating,
FormFields,
RepeatRenderManager,
ExpressionLoopPreventer,
} from '../../../../../../src';

export function createMockInjector(services = {}, options = {}) {
const injector = new Injector([_createMockModule(services, options)]);
Expand Down Expand Up @@ -29,6 +35,9 @@ function _createMockModule(services, options) {
// using actual implementations in testing
formFields: services.formFields ? ['value', services.formFields] : ['type', FormFields],
templating: services.templating ? ['value', services.templating] : ['type', FeelersTemplating],
expressionLoopPreventer: services.expressionLoopPreventer
? ['value', services.expressionLoopPreventer]
: ['type', ExpressionLoopPreventer],
repeatRenderManager: services.repeatRenderManager
? ['value', services.repeatRenderManager]
: ['type', RepeatRenderManager],
Expand Down

0 comments on commit 4bebb52

Please sign in to comment.