From 4e1f9c72800246885cba64aa87792e2e4a635a11 Mon Sep 17 00:00:00 2001 From: Elliot DeNolf Date: Thu, 18 Aug 2022 14:44:10 -0400 Subject: [PATCH] test: add code fields to test config --- test/fields/collections/Code/index.tsx | 126 +++++++++++++++++++++++++ test/fields/config.ts | 3 + test/fields/payload-types.ts | 14 +++ 3 files changed, 143 insertions(+) create mode 100644 test/fields/collections/Code/index.tsx diff --git a/test/fields/collections/Code/index.tsx b/test/fields/collections/Code/index.tsx new file mode 100644 index 0000000000..837f5385cc --- /dev/null +++ b/test/fields/collections/Code/index.tsx @@ -0,0 +1,126 @@ +import type { CollectionConfig } from '../../../../src/collections/config/types'; +import { CodeField } from '../../payload-types'; + +const Code: CollectionConfig = { + slug: 'code-fields', + fields: [ + { + name: 'javascript', + type: 'code', + admin: { + language: 'js', + }, + }, + { + name: 'typescript', + type: 'code', + admin: { + language: 'ts', + }, + }, + { + name: 'json', + type: 'code', + admin: { + language: 'json', + }, + }, + { + name: 'html', + type: 'code', + admin: { + language: 'html', + }, + }, + { + name: 'css', + type: 'code', + admin: { + language: 'css', + }, + }, + ], +}; + +export const codeDoc: Partial = { + javascript: "console.log('Hello');", + typescript: `class Greeter { + greeting: string; + + constructor(message: string) { + this.greeting = message; + } + + greet() { + return "Hello, " + this.greeting; + } +} + +let greeter = new Greeter("world");`, + + html: ` + + + + + + +Prism + + + + + + + +`, + + 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%; +}`, + + json: JSON.stringify({ property: 'value', arr: ['val1', 'val2', 'val3'] }, null, 2), +}; + +export default Code; diff --git a/test/fields/config.ts b/test/fields/config.ts index 098efbba1c..910e11e83a 100644 --- a/test/fields/config.ts +++ b/test/fields/config.ts @@ -18,6 +18,7 @@ import getFileByPath from '../../src/uploads/getFileByPath'; import Uploads, { uploadsDoc } from './collections/Upload'; import IndexedFields from './collections/Indexed'; import NumberFields, { numberDoc } from './collections/Number'; +import CodeFields, { codeDoc } from './collections/Code'; export default buildConfig({ admin: { @@ -35,6 +36,7 @@ export default buildConfig({ collections: [ ArrayFields, BlockFields, + CodeFields, CollapsibleFields, ConditionalLogic, GroupFields, @@ -69,6 +71,7 @@ export default buildConfig({ await payload.create({ collection: 'tabs-fields', data: tabsDoc }); await payload.create({ collection: 'point-fields', data: pointDoc }); await payload.create({ collection: 'date-fields', data: dateDoc }); + await payload.create({ collection: 'code-fields', data: codeDoc }); const createdTextDoc = await payload.create({ collection: 'text-fields', data: textDoc }); diff --git a/test/fields/payload-types.ts b/test/fields/payload-types.ts index be91c47f53..fbb64ed0f3 100644 --- a/test/fields/payload-types.ts +++ b/test/fields/payload-types.ts @@ -112,6 +112,20 @@ export interface BlockField { createdAt: string; updatedAt: string; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "code-fields". + */ +export interface CodeField { + id: string; + javascript?: string; + typescript?: string; + json?: string; + html?: string; + css?: string; + createdAt: string; + updatedAt: string; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "collapsible-fields".