fix: RichText link custom fields (#2756)

Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
This commit is contained in:
Alessio Gravili
2023-06-02 19:55:46 +02:00
committed by GitHub
parent f978299868
commit 23be263dd2
5 changed files with 99 additions and 62 deletions

View File

@@ -114,21 +114,16 @@ const RichTextFields: CollectionConfig = {
'upload',
],
link: {
fields: () => [
{
required: false,
name: 'rel',
label: 'Rel Attribute',
type: 'select',
hasMany: true,
options: [
'noopener', 'noreferrer', 'nofollow',
],
admin: {
description: 'The rel attribute defines the relationship between a linked resource and the current document. This is a custom link field.',
fields: ({ defaultFields }) => {
return [
...defaultFields,
{
label: 'Custom',
name: 'customLinkField',
type: 'text',
},
},
],
];
},
},
upload: {
collections: {

View File

@@ -563,16 +563,41 @@ describe('fields', () => {
});
test('should respect customizing the default fields', async () => {
const linkText = 'link';
const value = 'test value';
await navigateToRichTextFields();
const field = page.locator('.rich-text', { has: page.locator('#field-richTextCustomFields') });
// open link drawer
const button = await field.locator('button.rich-text__button.link');
await button.click();
// fill link fields
const linkDrawer = await page.locator('[id^=drawer_1_rich-text-link-]');
await expect(linkDrawer).toBeVisible();
const fieldCount = await linkDrawer.locator('.render-fields > .field-type').count();
await expect(fieldCount).toEqual(1);
const fields = await linkDrawer.locator('.render-fields > .field-type');
await fields.locator('#field-text').fill(linkText);
await fields.locator('#field-url').fill('https://payloadcms.com');
const input = await fields.locator('#field-fields__customLinkField');
await input.fill(value);
// submit link closing drawer
await linkDrawer.locator('button[type="submit"]').click();
const linkInEditor = field.locator(`.rich-text-link >> text="${linkText}"`);
await saveDocAndAssert(page);
// open modal again
await linkInEditor.click();
const popup = page.locator('.popup--active .rich-text-link__popup');
await expect(popup).toBeVisible();
await popup.locator('.rich-text-link__link-edit').click();
const linkDrawer2 = await page.locator('[id^=drawer_1_rich-text-link-]');
const fields2 = await linkDrawer2.locator('.render-fields > .field-type');
const input2 = await fields2.locator('#field-fields__customLinkField');
await expect(input2).toHaveValue(value);
});
});