Skip to content

Commit

Permalink
fix: properly build out parent context chain
Browse files Browse the repository at this point in the history
Closes #1191
  • Loading branch information
Skaiir committed Jun 3, 2024
1 parent 64586ec commit d537d5d
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ const RepetitionScaffold = (props) => {
() => ({
data: parentExpressionContextInfo.data,
this: itemValue,
parent: buildExpressionContext(parentExpressionContextInfo),
parent: buildExpressionContext({ ...parentExpressionContextInfo, data: parentExpressionContextInfo.this }),
i: [...parentExpressionContextInfo.i, itemIndex + 1],
}),
[itemIndex, parentExpressionContextInfo, itemValue],
Expand Down
40 changes: 40 additions & 0 deletions packages/form-js-viewer/test/spec/Form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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 nestedComplexContextSchema from './nested-complex-context.json';
import cyclicalExpressionsSchema from './cyclical-expressions.json';
import chainExpressionsSchema from './chain-expressions.json';
import hiddenFieldsConditionalSchema from './hidden-fields-conditional.json';
Expand Down Expand Up @@ -1782,6 +1783,45 @@ describe('Form', function () {
]);
});
});

describe('integration - context', function () {
it('should properly pass down context and parent accessors', async function () {
// given
const data = {
a: 'testA',
list: [
{
b: 'testB',
},
],
};

// when
await bootstrapForm({
container,
data,
schema: nestedComplexContextSchema,
});

// then
expect(form).to.exist;

// Select all fjs-form-field-text elements
const textFields = container.querySelectorAll('.fjs-form-field-text');

// Check the contents of the first fjs-form-field-text element
expect(textFields[0]).to.exist;
expect(textFields[0].textContent).to.include('Flat: testA');
expect(textFields[0].textContent).to.include('Parent: testA');

// Check the contents of the second fjs-form-field-text element
expect(textFields[1]).to.exist;
expect(textFields[1].textContent).to.include('ParentThis: testB');
expect(textFields[1].textContent).to.include('Parent: testB');
expect(textFields[1].textContent).to.include('GrandParent: testA');
expect(textFields[1].textContent).to.include('GrandParentThis: testA');
});
});
});

// helpers //////////
Expand Down
80 changes: 80 additions & 0 deletions packages/form-js-viewer/test/spec/nested-complex-context.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"components": [
{
"label": "Test",
"type": "textfield",
"layout": {
"row": "Row_06pau7i",
"columns": null
},
"id": "Field_0naxgdd",
"key": "a"
},
{
"components": [
{
"text": "Flat: {{a}}\nParent: {{parent.a}}",
"label": "Text view",
"type": "text",
"layout": {
"row": "Row_0e00xn8",
"columns": null
},
"id": "Field_03g3bvj"
},
{
"label": "Test",
"type": "textfield",
"layout": {
"row": "Row_0nqe5bi",
"columns": null
},
"id": "Field_0oofqh4",
"key": "b"
},
{
"components": [
{
"text": "ParentThis: {{parent.this.b}}\nParent: {{parent.b}}\nGrandParent: {{parent.parent.a}}\nGrandParentThis: {{parent.parent.this.a}}",
"label": "Text view",
"type": "text",
"layout": {
"row": "Row_17ftgn9",
"columns": null
},
"id": "Field_1bjzda6"
}
],
"showOutline": true,
"isRepeating": true,
"allowAddRemove": true,
"defaultRepetitions": 1,
"label": "Dynamic list",
"type": "dynamiclist",
"layout": {
"row": "Row_0kn6m8y",
"columns": null
},
"id": "Field_033ey1v",
"path": "dynamiclist_lkkpkli"
}
],
"showOutline": true,
"isRepeating": true,
"allowAddRemove": true,
"defaultRepetitions": 1,
"label": "Dynamic list",
"type": "dynamiclist",
"layout": {
"row": "Row_1d2g3ok",
"columns": null
},
"id": "Field_1d4j6bh",
"path": "list"
}
],
"$schema": "../../../form-json-schema/resources/schema.json",
"type": "default",
"id": "Form_1roxfho",
"schemaVersion": 16
}

0 comments on commit d537d5d

Please sign in to comment.