fix: nested richtext bug and test (#2966)

* fix: nested richtext bug and test

* chore: fix accidentally deleted character
This commit is contained in:
Jessica Chowdhury
2023-07-05 14:06:02 +01:00
committed by GitHub
parent a8e47088bb
commit 801f60939b
3 changed files with 64 additions and 1 deletions

View File

@@ -247,7 +247,7 @@ const RichText: React.FC<Props> = (props) => {
const parsedJSON = JSON.parse(valueToRender);
valueToRender = parsedJSON;
} catch (err) {
// do nothing
valueToRender = null;
}
}

View File

@@ -188,6 +188,30 @@ const RichTextFields: CollectionConfig = {
},
},
},
{
name: 'blocks',
type: 'blocks',
blocks: [
{
slug: 'textBlock',
fields: [
{
name: 'text',
type: 'text',
},
],
},
{
slug: 'richTextBlock',
fields: [
{
name: 'text',
type: 'richText',
},
],
},
],
},
],
};
@@ -440,12 +464,32 @@ export const richTextBulletsDoc = {
],
};
export const richTextBlocks = [
{
blockType: 'textBlock',
text: 'Regular text',
},
{
blockType: 'richTextBlock',
text: [
{
children: [
{
text: 'Rich text',
},
],
type: 'h1',
},
],
},
];
export const richTextDoc = {
title: 'Rich Text',
selectHasMany: ['one', 'five'],
richText: generateRichText(),
richTextReadOnly: generateRichText(),
richTextCustomFields: generateRichText(),
blocks: richTextBlocks,
};
export default RichTextFields;

View File

@@ -736,6 +736,25 @@ describe('fields', () => {
const textField = await editLinkModal.locator('#field-text');
await expect(textField).toHaveValue('Hello, I\'m a rich text field.');
});
test('should not take value from previous block', async () => {
await navigateToRichTextFields();
// check first block value
const textField = await page.locator('#field-blocks__0__text');
await expect(textField).toHaveValue('Regular text');
// remove the first block
const editBlock = await page.locator('#blocks-row-0 .popup-button');
await editBlock.click();
const removeButton = await page.locator('#blocks-row-0').getByRole('button', { name: 'Remove' });
await expect(removeButton).toBeVisible();
await removeButton.click();
// check new first block value
const richTextField = await page.locator('#field-blocks__0__text');
const richTextValue = await richTextField.innerText();
await expect(richTextValue).toContain('Rich text');
});
});
});