Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 55 additions & 22 deletions packages/core/test/Form.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ describeRepeated('Form common', (createFormComponent) => {

expect(node.querySelector(protocolInputID).value).to.equal('1');
});
it('Should modify oneOf radio button when the defaults are set.', () => {
describe('Should modify oneOf radio button when the defaults are set.', () => {
const schema = {
type: 'object',
properties: {
Expand Down Expand Up @@ -1594,35 +1594,68 @@ describeRepeated('Form common', (createFormComponent) => {
'ui:label': false,
},
};

const { node, onChange } = createFormComponent({
schema,
uiSchema,
});

const notApplicableInputID = '#root_a-1';
const NoInputID = '#root_a-0';
expect(node.querySelector(notApplicableInputID).checked).to.equal(true);

act(() => {
fireEvent.click(node.querySelector(NoInputID));
});
it('Test with default constAsDefaults', () => {
const { node, onChange } = createFormComponent({
schema,
uiSchema,
});

sinon.assert.calledWithMatch(
onChange.lastCall,
{
formData: {
a: false,
expect(node.querySelector(notApplicableInputID).checked).to.equal(true);

act(() => {
fireEvent.click(node.querySelector(NoInputID));
});

sinon.assert.calledWithMatch(
onChange.lastCall,
{
formData: {
a: false,
},
schema,
uiSchema,
},
'root_a',
);

expect(node.querySelector(NoInputID).checked).to.equal(true);
expect(node.querySelector(notApplicableInputID).checked).to.equal(false);
expect(node.querySelector('#root_b')).to.exist;
});
it('Test with constAsDefaults set to "never"', () => {
const { node, onChange } = createFormComponent({
schema,
uiSchema,
},
'root_a',
);
experimental_defaultFormStateBehavior: {
constAsDefaults: 'never',
},
});

expect(node.querySelector(notApplicableInputID).checked).to.equal(true);

act(() => {
fireEvent.click(node.querySelector(NoInputID));
});

sinon.assert.calledWithMatch(
onChange.lastCall,
{
formData: {
a: false,
},
schema,
uiSchema,
},
'root_a',
);

expect(node.querySelector(NoInputID).checked).to.equal(true);
expect(node.querySelector(notApplicableInputID).checked).to.equal(false);
expect(node.querySelector('#root_b')).to.exist;
expect(node.querySelector(NoInputID).checked).to.equal(true);
expect(node.querySelector(notApplicableInputID).checked).to.equal(false);
expect(node.querySelector('#root_b')).to.exist;
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/schema/getDefaultFormState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
experimental_customMergeAllOf,
parentDefaults: defaults as T | undefined,
rawFormData: formData as T,
rawFormData: (rawFormData ?? formData) as T,
required,
shouldMergeDefaultsIntoFormData,
});
Expand Down