Skip to content

Commit fbc4725

Browse files
committed
Propagate mods to Section components (#9)
1 parent 246dfe3 commit fbc4725

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

src/formBuilder/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ export function getCardParameterInputComponentForType(
823823
category: string,
824824
allFormInputs: { [string]: FormInput },
825825
) {
826-
return allFormInputs[category].modalBody;
826+
return allFormInputs[category].modalBody || (() => null);
827827
}
828828

829829
// takes in an array of Card Objects and updates both schemas
@@ -1452,6 +1452,7 @@ export function generateElementComponentsFromSchemas(parameters: {
14521452
}
14531453
allFormInputs={allFormInputs}
14541454
categoryHash={categoryHash}
1455+
mods={mods}
14551456
/>
14561457
);
14571458
} else {

src/formBuilder/utils.test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
import Card from './Card';
4+
import Section from './Section';
15
import {
26
parse,
37
stringify,
@@ -7,6 +11,7 @@ import {
711
generateSchemaFromElementProps,
812
generateUiSchemaFromElementProps,
913
generateCategoryHash,
14+
generateElementComponentsFromSchemas,
1015
} from './utils';
1116
import DEFAULT_FORM_INPUTS from './defaults/defaultFormInputs';
1217

@@ -380,3 +385,84 @@ describe('generateUiSchemaFromElementProps', () => {
380385
});
381386
});
382387
});
388+
389+
describe('generateElementComponentsFromSchemas', () => {
390+
it('propagates mods to Section component', () => {
391+
const MockComponent = jest.fn(() => <div />);
392+
const mods = {
393+
customFormInputs: {
394+
test: {
395+
displayName: 'Test',
396+
matchIf: [
397+
{
398+
types: ['number'],
399+
widget: 'test',
400+
},
401+
],
402+
defaultDataSchema: {},
403+
defaultUiSchema: { 'ui:widget': 'test' },
404+
type: 'number',
405+
cardBody: MockComponent,
406+
},
407+
},
408+
};
409+
const allFormInputs = {
410+
...DEFAULT_FORM_INPUTS,
411+
...mods.customFormInputs,
412+
};
413+
const categoryHash = generateCategoryHash(allFormInputs);
414+
415+
const TestComponent = () => (
416+
<React.Fragment>
417+
{generateElementComponentsFromSchemas({
418+
schemaData: {
419+
type: 'object',
420+
properties: {
421+
section1: {
422+
title: 'Section 1',
423+
type: 'object',
424+
properties: {
425+
newInput1: {
426+
items: {
427+
type: 'number',
428+
},
429+
title: 'New Input 1',
430+
type: 'array',
431+
},
432+
},
433+
dependencies: {},
434+
required: [],
435+
},
436+
},
437+
dependencies: {},
438+
required: [],
439+
},
440+
uiSchemaData: {
441+
section1: {
442+
newInput1: {
443+
items: {
444+
'ui:widget': 'test',
445+
},
446+
},
447+
'ui:order': ['newInput1'],
448+
},
449+
'ui:order': ['section1'],
450+
},
451+
onChange: () => {},
452+
path: '',
453+
cardOpenArray: [true],
454+
setCardOpenArray: () => {},
455+
allFormInputs,
456+
mods,
457+
categoryHash,
458+
Card,
459+
Section,
460+
})}
461+
</React.Fragment>
462+
);
463+
const div = document.createElement('div');
464+
document.body.appendChild(div);
465+
mount(<TestComponent />, { attachTo: div });
466+
expect(MockComponent.mock.calls[0][0].mods).toEqual(mods);
467+
});
468+
});

0 commit comments

Comments
 (0)