chore: fixes test suites that use clearAndSeedEverything (#4080)

This commit is contained in:
Jarrod Flesch
2023-11-09 12:30:19 -05:00
committed by GitHub
parent cef4cbb0ee
commit dbc4ce71e6
40 changed files with 897 additions and 623 deletions

View File

@@ -128,32 +128,4 @@ const ArrayFields: CollectionConfig = {
],
}
export const arrayDoc = {
items: [
{
text: 'first row',
},
{
text: 'second row',
},
{
text: 'third row',
},
{
text: 'fourth row',
},
{
text: 'fifth row',
},
{
text: 'sixth row',
},
],
collapsedArray: [
{
text: 'initialize collapsed',
},
],
}
export default ArrayFields

View File

@@ -0,0 +1,37 @@
import type { ArrayField } from '../../payload-types'
export const arrayDoc: Partial<ArrayField> = {
items: [
{
text: 'first row',
},
{
text: 'second row',
},
{
text: 'third row',
},
{
text: 'fourth row',
},
{
text: 'fifth row',
},
{
text: 'sixth row',
},
],
collapsedArray: [
{
text: 'initialize collapsed',
},
],
arrayWithMinRows: [
{
text: 'first row',
},
{
text: 'second row',
},
],
}

View File

@@ -3,45 +3,7 @@ import type { BlockField } from '../../../../packages/payload/src/fields/config/
import { blockFieldsSlug } from '../../slugs'
import { AddCustomBlocks } from './components/AddCustomBlocks'
export const getBlocksFieldSeedData = (prefix?: string): any => [
{
blockName: 'First block',
blockType: prefix ? `${prefix}Content` : 'content',
text: 'first block',
richText: [
{
children: [{ text: '' }],
},
],
},
{
blockName: 'Second block',
blockType: prefix ? `${prefix}Number` : 'number',
number: 342,
},
{
blockName: 'Sub-block demonstration',
blockType: prefix ? `${prefix}SubBlocks` : 'subBlocks',
subBlocks: [
{
blockName: 'First sub block',
blockType: 'number',
number: 123,
},
{
blockName: 'Second sub block',
blockType: 'text',
text: 'second sub block',
},
],
},
{
blockName: 'I18n Block',
blockType: 'i18n-text',
text: 'first block',
},
]
import { getBlocksFieldSeedData } from './shared'
export const getBlocksField = (prefix?: string): BlockField => ({
name: 'blocks',
@@ -282,9 +244,4 @@ const BlockFields: CollectionConfig = {
],
}
export const blocksDoc = {
blocks: getBlocksFieldSeedData(),
localizedBlocks: getBlocksFieldSeedData('localized'),
}
export default BlockFields

View File

@@ -0,0 +1,55 @@
import type { BlockField } from '../../payload-types'
export const getBlocksFieldSeedData = (prefix?: string): any => [
{
blockName: 'First block',
blockType: prefix ? `${prefix}Content` : 'content',
text: 'first block',
richText: [
{
children: [{ text: '' }],
},
],
},
{
blockName: 'Second block',
blockType: prefix ? `${prefix}Number` : 'number',
number: 342,
},
{
blockName: 'Sub-block demonstration',
blockType: prefix ? `${prefix}SubBlocks` : 'subBlocks',
subBlocks: [
{
blockName: 'First sub block',
blockType: 'number',
number: 123,
},
{
blockName: 'Second sub block',
blockType: 'text',
text: 'second sub block',
},
],
},
{
blockName: 'I18n Block',
blockType: 'i18n-text',
text: 'first block',
},
]
export const blocksDoc: Partial<BlockField> = {
blocks: getBlocksFieldSeedData(),
localizedBlocks: getBlocksFieldSeedData('localized'),
blocksWithMinRows: [
{
blockTitle: 'first row',
blockType: 'block',
},
{
blockTitle: 'second row',
blockType: 'block',
},
],
}

View File

@@ -1,5 +1,4 @@
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
import type { CodeField } from '../../payload-types'
import { codeFieldsSlug } from '../../slugs'
@@ -44,85 +43,4 @@ const Code: CollectionConfig = {
slug: codeFieldsSlug,
}
export const codeDoc: Partial<CodeField> = {
css: `@import url(https://fonts.googleapis.com/css?family=Questrial);
@import url(https://fonts.googleapis.com/css?family=Arvo);
@font-face {
src: url(https://lea.verou.me/logo.otf);
font-family: 'LeaVerou';
}
/*
Shared styles
*/
section h1,
#features li strong,
header h2,
footer p {
font: 100% Rockwell, Arvo, serif;
}
/*
Styles
*/
* {
margin: 0;
padding: 0;
}
body {
font: 100%/1.5 Questrial, sans-serif;
tab-size: 4;
hyphens: auto;
}
a {
color: inherit;
}
section h1 {
font-size: 250%;
}`,
html: `<!DOCTYPE html>
<html lang="en">
<head>
<script>
// Just a lil script to show off that inline JS gets highlighted
window.console && console.log('foo');
</script>
<meta charset="utf-8" />
<link rel="icon" href="assets/favicon.png" />
<title>Prism</title>
<link rel="stylesheet" href="assets/style.css" />
<link rel="stylesheet" href="themes/prism.css" data-noprefix />
<script src="assets/vendor/prefixfree.min.js"></script>
<script>var _gaq = [['_setAccount', 'UA-11111111-1'], ['_trackPageview']];</script>
<script src="https://www.google-analytics.com/ga.js" async></script>
</head>
<body>`,
javascript: "console.log('Hello');",
json: JSON.stringify({ arr: ['val1', 'val2', 'val3'], property: 'value' }, null, 2),
typescript: `class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
let greeter = new Greeter("world");`,
}
export default Code

View File

@@ -0,0 +1,82 @@
import type { CodeField } from '../../payload-types'
export const codeDoc: Partial<CodeField> = {
css: `@import url(https://fonts.googleapis.com/css?family=Questrial);
@import url(https://fonts.googleapis.com/css?family=Arvo);
@font-face {
src: url(https://lea.verou.me/logo.otf);
font-family: 'LeaVerou';
}
/*
Shared styles
*/
section h1,
#features li strong,
header h2,
footer p {
font: 100% Rockwell, Arvo, serif;
}
/*
Styles
*/
* {
margin: 0;
padding: 0;
}
body {
font: 100%/1.5 Questrial, sans-serif;
tab-size: 4;
hyphens: auto;
}
a {
color: inherit;
}
section h1 {
font-size: 250%;
}`,
html: `<!DOCTYPE html>
<html lang="en">
<head>
<script>
// Just a lil script to show off that inline JS gets highlighted
window.console && console.log('foo');
</script>
<meta charset="utf-8" />
<link rel="icon" href="assets/favicon.png" />
<title>Prism</title>
<link rel="stylesheet" href="assets/style.css" />
<link rel="stylesheet" href="themes/prism.css" data-noprefix />
<script src="assets/vendor/prefixfree.min.js"></script>
<script>var _gaq = [['_setAccount', 'UA-11111111-1'], ['_trackPageview']];</script>
<script src="https://www.google-analytics.com/ga.js" async></script>
</head>
<body>`,
javascript: "console.log('Hello');",
json: JSON.stringify({ arr: ['val1', 'val2', 'val3'], property: 'value' }, null, 2),
typescript: `class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
let greeter = new Greeter("world");`,
}

View File

@@ -133,19 +133,4 @@ const CollapsibleFields: CollectionConfig = {
],
}
export const collapsibleDoc = {
text: 'Seeded collapsible doc',
group: {
textWithinGroup: 'some text within a group',
subGroup: {
textWithinSubGroup: 'hello, get out',
},
},
arrayWithCollapsibles: [
{
innerCollapsible: '',
},
],
}
export default CollapsibleFields

View File

@@ -0,0 +1,16 @@
import type { CollapsibleField } from '../../payload-types'
export const collapsibleDoc: Partial<CollapsibleField> = {
text: 'Seeded collapsible doc',
group: {
textWithinGroup: 'some text within a group',
subGroup: {
textWithinSubGroup: 'hello, get out',
},
},
arrayWithCollapsibles: [
{
innerCollapsible: '',
},
],
}

View File

@@ -95,10 +95,4 @@ const ConditionalLogic: CollectionConfig = {
],
}
export const conditionalLogicDoc = {
text: 'Seeded conditional logic document',
toggleField: true,
fieldToToggle: 'spiderman',
}
export default ConditionalLogic

View File

@@ -0,0 +1,7 @@
import type { ConditionalLogic } from '../../payload-types'
export const conditionalLogicDoc: Partial<ConditionalLogic> = {
text: 'Seeded conditional logic document',
toggleField: true,
fieldToToggle: 'spiderman',
}

View File

@@ -64,13 +64,4 @@ const DateFields: CollectionConfig = {
],
}
export const dateDoc = {
default: '2022-08-12T10:00:00.000+00:00',
timeOnly: '2022-08-12T10:00:00.157+00:00',
timeOnlyWithCustomFormat: '2022-08-12T10:00:00.157+00:00',
dayOnly: '2022-08-11T22:00:00.000+00:00',
dayAndTime: '2022-08-12T10:00:00.052+00:00',
monthOnly: '2022-07-31T22:00:00.000+00:00',
}
export default DateFields

View File

@@ -0,0 +1,10 @@
import type { DateField } from '../../payload-types'
export const dateDoc: Partial<DateField> = {
default: '2022-08-12T10:00:00.000+00:00',
timeOnly: '2022-08-12T10:00:00.157+00:00',
timeOnlyWithCustomFormat: '2022-08-12T10:00:00.157+00:00',
dayOnly: '2022-08-11T22:00:00.000+00:00',
dayAndTime: '2022-08-12T10:00:00.052+00:00',
monthOnly: '2022-07-31T22:00:00.000+00:00',
}

View File

@@ -169,18 +169,4 @@ const GroupFields: CollectionConfig = {
],
}
export const groupDoc = {
group: {
text: 'some text within a group',
subGroup: {
textWithinGroup: 'please',
arrayWithinGroup: [
{
textWithinArray: 'text in a group and array',
},
],
},
},
}
export default GroupFields

View File

@@ -0,0 +1,15 @@
import type { GroupField } from '../../payload-types'
export const groupDoc: Partial<GroupField> = {
group: {
text: 'some text within a group',
subGroup: {
textWithinGroup: 'please',
arrayWithinGroup: [
{
textWithinArray: 'text in a group and array',
},
],
},
},
}

View File

@@ -17,8 +17,6 @@ const beforeDuplicate: BeforeDuplicate<IndexedField> = ({ data }) => {
...(data.group || {}),
localizedUnique: data.group?.localizedUnique ? `${data.group?.localizedUnique}-copy` : '',
},
partOne: data.partOne ? `${data.partOne}-copy` : '',
partTwo: data.partTwo ? `${data.partTwo}-copy` : '',
uniqueText: data.uniqueText ? `${data.uniqueText}-copy` : '',
}
}

View File

@@ -25,14 +25,4 @@ const JSON: CollectionConfig = {
},
}
export const jsonDoc: Partial<JSONField> = {
json: {
arr: ['val1', 'val2', 'val3'],
nested: {
value: 'nested value',
},
property: 'value',
},
}
export default JSON

View File

@@ -0,0 +1,11 @@
import type { JsonField } from '../../payload-types'
export const jsonDoc: Partial<JsonField> = {
json: {
arr: ['val1', 'val2', 'val3'],
nested: {
value: 'nested value',
},
property: 'value',
},
}

View File

@@ -8,7 +8,6 @@ import {
lexicalEditor,
} from '../../../../packages/richtext-lexical/src'
import { lexicalMigrateFieldsSlug } from '../../slugs'
import { payloadPluginLexicalData } from './generatePayloadPluginLexicalData'
export const LexicalMigrateFields: CollectionConfig = {
slug: lexicalMigrateFieldsSlug,
@@ -66,8 +65,3 @@ export const LexicalMigrateFields: CollectionConfig = {
},
],
}
export const LexicalRichTextDoc = {
title: 'Rich Text',
lexicalWithLexicalPluginData: payloadPluginLexicalData,
}

View File

@@ -0,0 +1,6 @@
import { payloadPluginLexicalData } from './generatePayloadPluginLexicalData'
export const LexicalRichTextDoc = {
title: 'Rich Text',
richTextLexicalWithLexicalPluginData: payloadPluginLexicalData,
}

View File

@@ -76,17 +76,4 @@ const NumberFields: CollectionConfig = {
],
}
export const numberDoc = {
number: 5,
min: 15,
max: 5,
positiveNumber: 5,
negativeNumber: -5,
decimalMin: 1.25,
decimalMax: 0.25,
hasMany: [5, 10, 15],
validatesHasMany: [5],
localizedHasMany: [10],
}
export default NumberFields

View File

@@ -0,0 +1,15 @@
import type { NumberField } from '../../payload-types'
export const numberDoc: Partial<NumberField> = {
number: 5,
min: 15,
max: 5,
positiveNumber: 5,
negativeNumber: -5,
decimalMin: 1.25,
decimalMax: 0.25,
hasMany: [5, 10, 15],
validatesHasMany: [5],
localizedHasMany: [10],
withMinRows: [5, 10],
}

View File

@@ -35,10 +35,4 @@ const PointFields: CollectionConfig = {
],
}
export const pointDoc = {
point: [7, -7],
localized: [15, -12],
group: { point: [1, 9] },
}
export default PointFields

View File

@@ -0,0 +1,7 @@
import type { PointField } from '../../payload-types'
export const pointDoc: Partial<PointField> = {
point: [7, -7],
localized: [15, -12],
group: { point: [1, 9] },
}

View File

@@ -30,8 +30,4 @@ const RadioFields: CollectionConfig = {
],
}
export const radiosDoc = {
radio: 'one',
}
export default RadioFields

View File

@@ -0,0 +1,5 @@
import type { RadioField } from '../../payload-types'
export const radiosDoc: Partial<RadioField> = {
radio: 'one',
}

View File

@@ -142,12 +142,4 @@ const SelectFields: CollectionConfig = {
],
}
export const selectsDoc = {
select: 'one',
selectHasMany: ['two', 'four'],
settings: {
category: ['a'],
},
}
export default SelectFields

View File

@@ -0,0 +1,9 @@
import type { SelectField } from '../../payload-types'
export const selectsDoc: Partial<SelectField> = {
select: 'one',
selectHasMany: ['two', 'four'],
settings: {
category: ['a'],
},
}

View File

@@ -2,9 +2,9 @@
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
import { tabsFieldsSlug } from '../../slugs'
import { getBlocksField, getBlocksFieldSeedData } from '../Blocks'
import { getBlocksField } from '../Blocks'
import { UIField } from './UIField'
import { localizedTextValue, namedTabDefaultValue, namedTabText } from './constants'
import { namedTabDefaultValue } from './constants'
const TabsFields: CollectionConfig = {
slug: tabsFieldsSlug,
@@ -276,56 +276,4 @@ const TabsFields: CollectionConfig = {
],
}
export const tabsDoc = {
array: [
{
text: "Hello, I'm the first row",
},
{
text: 'Second row here',
},
{
text: 'Here is some data for the third row',
},
],
blocks: getBlocksFieldSeedData(),
group: {
number: 12,
},
nestedTab: {
text: 'Some text in a nested, named tab',
},
tab: {
array: [
{
text: "Hello, I'm the first row, in a named tab",
},
{
text: 'Second row here, in a named tab',
},
{
text: 'Here is some data for the third row, in a named tab',
},
],
text: namedTabText,
},
text: 'localized',
localizedTab: {
text: localizedTextValue,
},
accessControlTab: {
text: 'cannot be read',
},
hooksTab: {
beforeValidate: false,
beforeChange: false,
afterChange: false,
afterRead: false,
},
textarea: 'Here is some text that goes in a textarea',
anotherText: 'Super tired of writing this text',
textInRow: 'hello',
numberInRow: 235,
}
export default TabsFields

View File

@@ -0,0 +1,55 @@
import type { TabsField } from '../../payload-types'
import { getBlocksFieldSeedData } from '../Blocks/shared'
import { localizedTextValue, namedTabText } from './constants'
export const tabsDoc: Partial<TabsField> = {
array: [
{
text: "Hello, I'm the first row",
},
{
text: 'Second row here',
},
{
text: 'Here is some data for the third row',
},
],
blocks: getBlocksFieldSeedData(),
group: {
number: 12,
},
nestedTab: {
text: 'Some text in a nested, named tab',
},
tab: {
array: [
{
text: "Hello, I'm the first row, in a named tab",
},
{
text: 'Second row here, in a named tab',
},
{
text: 'Here is some data for the third row, in a named tab',
},
],
text: namedTabText,
},
localizedTab: {
text: localizedTextValue,
},
accessControlTab: {
text: 'cannot be read',
},
hooksTab: {
beforeValidate: false,
beforeChange: false,
afterChange: false,
afterRead: false,
},
textarea: 'Here is some text that goes in a textarea',
anotherText: 'Super tired of writing this text',
textInRow: 'hello',
numberInRow: 235,
}

View File

@@ -1,6 +1,9 @@
import type { TextField } from '../../payload-types'
export const defaultText = 'default-text'
export const textFieldsSlug = 'text-fields'
export const textDoc = {
export const textDoc: Partial<TextField> = {
text: 'Seeded text document',
localizedText: 'Localized text',
}

View File

@@ -31,8 +31,4 @@ const Uploads: CollectionConfig = {
],
}
export const uploadsDoc = {
text: 'An upload here',
}
export default Uploads

View File

@@ -0,0 +1,5 @@
import type { Upload } from '../../payload-types'
export const uploadsDoc: Partial<Upload> = {
text: 'An upload here',
}

View File

@@ -26,8 +26,4 @@ const Uploads2: CollectionConfig = {
],
}
export const uploadsDoc = {
text: 'An upload here',
}
export default Uploads2

View File

@@ -0,0 +1,5 @@
import type { Uploads2 } from '../../payload-types'
export const uploadsDoc: Partial<Uploads2> = {
text: 'An upload here',
}

View File

@@ -29,8 +29,4 @@ const Uploads3: CollectionConfig = {
],
}
export const uploadsDoc = {
text: 'An upload here',
}
export default Uploads3

View File

@@ -10,8 +10,8 @@ import { exactText, saveDocAndAssert, saveDocHotkeyAndAssert } from '../helpers'
import { AdminUrlUtil } from '../helpers/adminUrlUtil'
import { initPayloadE2E } from '../helpers/configHelpers'
import { RESTClient } from '../helpers/rest'
import { jsonDoc } from './collections/JSON'
import { numberDoc } from './collections/Number'
import { jsonDoc } from './collections/JSON/shared'
import { numberDoc } from './collections/Number/shared'
import { textDoc } from './collections/Text/shared'
import { clearAndSeedEverything } from './seed'
import {

View File

@@ -13,17 +13,19 @@ import { isMongoose } from '../helpers/isMongoose'
import { RESTClient } from '../helpers/rest'
import configPromise from '../uploads/config'
import { arrayDefaultValue } from './collections/Array'
import { blocksDoc } from './collections/Blocks'
import { dateDoc } from './collections/Date'
import { groupDefaultChild, groupDefaultValue, groupDoc } from './collections/Group'
import { defaultNumber, numberDoc } from './collections/Number'
import { pointDoc } from './collections/Point'
import { tabsDoc } from './collections/Tabs'
import { blocksDoc } from './collections/Blocks/shared'
import { dateDoc } from './collections/Date/shared'
import { groupDefaultChild, groupDefaultValue } from './collections/Group'
import { groupDoc } from './collections/Group/shared'
import { defaultNumber } from './collections/Number'
import { numberDoc } from './collections/Number/shared'
import { pointDoc } from './collections/Point/shared'
import {
localizedTextValue,
namedTabDefaultValue,
namedTabText,
} from './collections/Tabs/constants'
import { tabsDoc } from './collections/Tabs/shared'
import { defaultText } from './collections/Text/shared'
import { clearAndSeedEverything } from './seed'
import { arrayFieldsSlug, groupFieldsSlug, relationshipFieldsSlug, tabsFieldsSlug } from './slugs'

View File

@@ -16,7 +16,7 @@ import payload from '../../packages/payload/src'
import { initPayloadTest } from '../helpers/configHelpers'
import { RESTClient } from '../helpers/rest'
import configPromise from '../uploads/config'
import { arrayDoc } from './collections/Array'
import { arrayDoc } from './collections/Array/shared'
import { lexicalDocData } from './collections/Lexical/data'
import { richTextDocData } from './collections/RichText/data'
import { generateLexicalRichText } from './collections/RichText/generateLexicalRichText'

File diff suppressed because it is too large Load Diff

View File

@@ -4,24 +4,24 @@ import { type Payload } from '../../packages/payload/src'
import getFileByPath from '../../packages/payload/src/uploads/getFileByPath'
import { devUser } from '../credentials'
import { seedDB } from '../helpers/seed'
import { arrayDoc } from './collections/Array'
import { blocksDoc } from './collections/Blocks'
import { codeDoc } from './collections/Code'
import { collapsibleDoc } from './collections/Collapsible'
import { conditionalLogicDoc } from './collections/ConditionalLogic'
import { dateDoc } from './collections/Date'
import { groupDoc } from './collections/Group'
import { jsonDoc } from './collections/JSON'
import { arrayDoc } from './collections/Array/shared'
import { blocksDoc } from './collections/Blocks/shared'
import { codeDoc } from './collections/Code/shared'
import { collapsibleDoc } from './collections/Collapsible/shared'
import { conditionalLogicDoc } from './collections/ConditionalLogic/shared'
import { dateDoc } from './collections/Date/shared'
import { groupDoc } from './collections/Group/shared'
import { jsonDoc } from './collections/JSON/shared'
import { lexicalDocData } from './collections/Lexical/data'
import { lexicalMigrateDocData } from './collections/LexicalMigrate/data'
import { numberDoc } from './collections/Number'
import { pointDoc } from './collections/Point'
import { radiosDoc } from './collections/Radio'
import { numberDoc } from './collections/Number/shared'
import { pointDoc } from './collections/Point/shared'
import { radiosDoc } from './collections/Radio/shared'
import { richTextBulletsDocData, richTextDocData } from './collections/RichText/data'
import { selectsDoc } from './collections/Select'
import { tabsDoc } from './collections/Tabs'
import { selectsDoc } from './collections/Select/shared'
import { tabsDoc } from './collections/Tabs/shared'
import { textDoc } from './collections/Text/shared'
import { uploadsDoc } from './collections/Upload'
import { uploadsDoc } from './collections/Upload/shared'
import {
arrayFieldsSlug,
blockFieldsSlug,
@@ -95,7 +95,9 @@ export async function clearAndSeedEverything(_payload: Payload) {
const richTextDocWithRelationship = { ...richTextDocWithRelId }
const blocksDocWithRichText = { ...blocksDoc }
const blocksDocWithRichText = {
...(blocksDoc as any),
}
blocksDocWithRichText.blocks[0].richText = richTextDocWithRelationship.richText
blocksDocWithRichText.localizedBlocks[0].richText = richTextDocWithRelationship.richText