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
4 changes: 4 additions & 0 deletions test/fields/collections/Array/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const ArrayFields: CollectionConfig = {
type: 'text',
localized: true,
},
{
name: 'richTextField',
type: 'richText',
},
{
name: 'subArray',
fields: [
Expand Down
42 changes: 42 additions & 0 deletions test/fields/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,48 @@ describe('Fields', () => {
expect(res.totalDocs).toBe(1)
expect(res.docs[0].id).toBe(withoutCollapsed.id)
})

it('should properly handle richText inside array', async () => {
const richTextValue = {
root: {
type: 'root',
children: [
{
type: 'paragraph',
children: [{ type: 'text', text: 'Hello from array', format: 1 }],
},
],
},
}

const doc = await payload.create({
collection,
data: {
items: [
{
text: 'required',
richTextField: richTextValue,
},
],
localized: [{ text: 'req' }],
},
})

// Verify richText is returned as an object, not a string
expect(doc.items[0].richTextField).toBeDefined()
expect(typeof doc.items[0].richTextField).toBe('object')
expect(doc.items[0].richTextField).toEqual(richTextValue)

// Also verify on read
const found = await payload.findByID({
collection,
id: doc.id,
})

expect(found.items[0].richTextField).toBeDefined()
expect(typeof found.items[0].richTextField).toBe('object')
expect(found.items[0].richTextField).toEqual(richTextValue)
})
})

describe('group', () => {
Expand Down