Skip to content

Commit 694c76d

Browse files
authored
test: cleans up fields-relationship test suite (#11003)
The `fields-relationship` test suite is disorganized to the point of being unusable. This makes it very difficult to digest at a high level and add new tests. This PR cleans it up in the following ways: - Moves collection configs to their own standalone files - Moves the seed function to its own file - Consolidates collection slugs in their own file - Uses generated types instead of defining them statically - Wraps the `filterOptions` e2e tests within a describe block Related, there are three distinct test suites where we manage relationships: `relationships`, `fields-relationship`, and `fields > relationships`. In the future we ought to consolidate at least two of these. IMO the `fields > relationship` suite should remain in place for general _component level_ UI tests for the field itself, whereas the other suite could run the integration tests and test the more complex UI patterns that exist outside of the field component.
1 parent 09721d4 commit 694c76d

File tree

26 files changed

+812
-651
lines changed

26 files changed

+812
-651
lines changed

test/fields-relationship/PrePopulateFieldUI/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { useField } from '@payloadcms/ui'
33
import * as React from 'react'
44

5-
import { collection1Slug } from '../collectionSlugs.js'
5+
import { collection1Slug } from '../slugs.js'
66

77
export const PrePopulateFieldUI: React.FC<{
88
hasMany?: boolean
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
export const baseRelationshipFields: CollectionConfig['fields'] = [
4+
{
5+
name: 'name',
6+
type: 'text',
7+
},
8+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import { collection1Slug } from '../../slugs.js'
4+
5+
export const Collection1: CollectionConfig = {
6+
fields: [
7+
{
8+
name: 'name',
9+
type: 'text',
10+
},
11+
],
12+
slug: collection1Slug,
13+
admin: {
14+
useAsTitle: 'name',
15+
},
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import { collection2Slug } from '../../slugs.js'
4+
5+
export const Collection2: CollectionConfig = {
6+
fields: [
7+
{
8+
name: 'name',
9+
type: 'text',
10+
},
11+
],
12+
slug: collection2Slug,
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import { baseRelationshipFields } from '../../baseFields.js'
4+
import { relationFalseFilterOptionSlug } from '../../slugs.js'
5+
6+
export const RelationshipFilterFalse: CollectionConfig = {
7+
admin: {
8+
useAsTitle: 'name',
9+
},
10+
fields: baseRelationshipFields,
11+
slug: relationFalseFilterOptionSlug,
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import { baseRelationshipFields } from '../../baseFields.js'
4+
import { relationTrueFilterOptionSlug } from '../../slugs.js'
5+
6+
export const RelationshipFilterTrue: CollectionConfig = {
7+
admin: {
8+
useAsTitle: 'name',
9+
},
10+
fields: baseRelationshipFields,
11+
slug: relationTrueFilterOptionSlug,
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import {
4+
mixedMediaCollectionSlug,
5+
podcastCollectionSlug,
6+
videoCollectionSlug,
7+
} from '../../slugs.js'
8+
9+
export const MixedMedia: CollectionConfig = {
10+
slug: mixedMediaCollectionSlug,
11+
fields: [
12+
{
13+
type: 'relationship',
14+
name: 'relatedMedia',
15+
relationTo: [videoCollectionSlug, podcastCollectionSlug],
16+
hasMany: true,
17+
},
18+
],
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import { podcastCollectionSlug } from '../../slugs.js'
4+
5+
export const Podcast: CollectionConfig = {
6+
slug: podcastCollectionSlug,
7+
admin: {
8+
useAsTitle: 'title',
9+
},
10+
fields: [
11+
{
12+
name: 'id',
13+
type: 'number',
14+
required: true,
15+
},
16+
{
17+
name: 'title',
18+
type: 'text',
19+
},
20+
],
21+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import { baseRelationshipFields } from '../../baseFields.js'
4+
import { relationOneSlug } from '../../slugs.js'
5+
6+
export const Relation1: CollectionConfig = {
7+
fields: baseRelationshipFields,
8+
slug: relationOneSlug,
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import { baseRelationshipFields } from '../../baseFields.js'
4+
import { relationTwoSlug } from '../../slugs.js'
5+
6+
export const Relation2: CollectionConfig = {
7+
fields: baseRelationshipFields,
8+
slug: relationTwoSlug,
9+
}

0 commit comments

Comments
 (0)