Skip to content

Commit

Permalink
Fix initialValue block setting when the previous block is not an empty
Browse files Browse the repository at this point in the history
block

In this situation, the insertBlock method is called. But it passed the
id of the previous block to the _applyBlockInitialValue method, instead
of the id of the new created block.
  • Loading branch information
wesleybl committed May 6, 2024
1 parent 82a37ee commit 5588d72
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/volto/src/helpers/Blocks/Blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export function insertBlock(

const newBlockId = uuid();
const newFormData = applyBlockInitialValue({
id,
id: newBlockId,
value,
blocksConfig,
formData: {
Expand Down
15 changes: 15 additions & 0 deletions packages/volto/src/helpers/Blocks/Blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,21 @@ describe('Blocks', () => {
});
});

it('initializes data for new block with initialValue in insertBlock', () => {
const [newId, form] = insertBlock(
{
blocks: { a: { value: 1 }, b: { value: 2 } },
blocks_layout: { items: ['a', 'b'] },
},
'b',
{ '@type': 'dummyText' },
);
expect(form.blocks[newId]).toStrictEqual({
'@type': 'dummyText',
marker: true,
});
});

it('initializes data for new block based on schema defaults', () => {
const [newId, form] = addBlock(
{
Expand Down

0 comments on commit 5588d72

Please sign in to comment.