fix: custom overrides of breadcrumb and parent fields
This commit is contained in:
38
test/plugin-nested-docs/collections/Categories.ts
Normal file
38
test/plugin-nested-docs/collections/Categories.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { CollectionConfig } from '../../../packages/payload/src/collections/config/types'
|
||||
|
||||
import { createBreadcrumbsField } from '../../../packages/plugin-nested-docs/src/fields/breadcrumbs'
|
||||
import createParentField from '../../../packages/plugin-nested-docs/src/fields/parent'
|
||||
|
||||
export const Categories: CollectionConfig = {
|
||||
access: {
|
||||
read: () => true,
|
||||
},
|
||||
admin: {
|
||||
useAsTitle: 'name',
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'name',
|
||||
required: true,
|
||||
type: 'text',
|
||||
},
|
||||
createBreadcrumbsField('categories', {
|
||||
name: 'categorization',
|
||||
admin: {
|
||||
description: 'custom',
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'test',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
}),
|
||||
createParentField('categories', {
|
||||
admin: {
|
||||
description: 'custom',
|
||||
},
|
||||
}),
|
||||
],
|
||||
slug: 'categories',
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
import nestedDocs from '../../packages/plugin-nested-docs/src'
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||
import { devUser } from '../credentials'
|
||||
import { Categories } from './collections/Categories'
|
||||
import { Pages } from './collections/Pages'
|
||||
import { Users } from './collections/Users'
|
||||
import { seed } from './seed'
|
||||
|
||||
export default buildConfigWithDefaults({
|
||||
collections: [Pages, Users],
|
||||
collections: [Pages, Categories, Users],
|
||||
localization: {
|
||||
defaultLocale: 'en',
|
||||
fallback: true,
|
||||
@@ -29,5 +30,11 @@ export default buildConfigWithDefaults({
|
||||
generateLabel: (_, doc) => doc.title as string,
|
||||
generateURL: (docs) => docs.reduce((url, doc) => `${url}/${doc.slug}`, ''),
|
||||
}),
|
||||
nestedDocs({
|
||||
breadcrumbsFieldSlug: 'categorization',
|
||||
collections: ['categories'],
|
||||
generateLabel: (_, doc) => doc.name as string,
|
||||
generateURL: (docs) => docs.reduce((url, doc) => `${url}/${doc.name}`, ''),
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { ArrayField, RelationshipField } from '../../packages/payload/src/fields/config/types'
|
||||
|
||||
import payload from '../../packages/payload/src'
|
||||
import { initPayloadTest } from '../helpers/configHelpers'
|
||||
|
||||
@@ -38,4 +40,33 @@ describe('Nested Docs', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('overrides', () => {
|
||||
let collection
|
||||
beforeAll(() => {
|
||||
collection = payload.config.collections.find(({ slug }) => slug === 'categories')
|
||||
})
|
||||
|
||||
it('should allow overriding breadcrumbs field', () => {
|
||||
const breadcrumbField = collection.fields.find(
|
||||
(field) => field.type === 'array' && field.name === 'categorization',
|
||||
) as ArrayField
|
||||
const customField = breadcrumbField.fields.find(
|
||||
(field) => field.type === 'text' && field.name === 'test',
|
||||
) as ArrayField
|
||||
|
||||
expect(breadcrumbField.admin.description).toStrictEqual('custom')
|
||||
expect(customField).toBeDefined()
|
||||
expect(breadcrumbField.admin.readOnly).toStrictEqual(true)
|
||||
expect(breadcrumbField.admin.readOnly).toStrictEqual(true)
|
||||
})
|
||||
|
||||
it('should allow overriding parent field', () => {
|
||||
const parentField = collection.fields.find(
|
||||
(field) => field.type === 'relationship' && field.name === 'parent',
|
||||
) as RelationshipField
|
||||
|
||||
expect(parentField.admin.description).toStrictEqual('custom')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user