Merge branch 'temp38' of github.com:payloadcms/payload into temp38

This commit is contained in:
James
2024-04-01 15:29:43 -04:00
29 changed files with 810 additions and 511 deletions

View File

@@ -7,12 +7,8 @@ import fs from 'fs'
import path from 'path'
import shelljs from 'shelljs'
import tempy from 'tempy'
import { fileURLToPath } from 'url'
import { promisify } from 'util'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
const readFile = promisify(fs.readFile)
const writeFile = promisify(fs.writeFile)
@@ -29,13 +25,6 @@ describe('create-payload-app', () => {
shelljs.exec('pnpm build:create-payload-app')
})
describe('Next.js app template files', () => {
it('should exist in dist', () => {
const distPath = path.resolve(dirname, '../../packages/create-payload-app/dist/app/(payload)')
expect(fs.existsSync(distPath)).toBe(true)
})
})
describe.each(Object.keys(nextCreateCommands))(`--init-next with %s`, (nextCmdKey) => {
const projectDir = tempy.directory()
beforeEach(async () => {
@@ -74,19 +63,53 @@ describe('create-payload-app', () => {
it('should install payload app in Next.js project', async () => {
expect(fs.existsSync(projectDir)).toBe(true)
const result = await initNext({
const firstResult = await initNext({
'--debug': true,
projectDir,
nextConfigPath: path.resolve(projectDir, 'next.config.mjs'),
dbType: 'mongodb',
useDistFiles: true, // create-payload-app/dist/app/(payload)
packageManager: 'pnpm',
})
expect(result.success).toBe(true)
// Will fail because we detect top-level layout.tsx file
expect(firstResult.success).toEqual(false)
const payloadFilesPath = path.resolve(result.userAppDir, '(payload)')
// Move all files from app to top-level directory named `(app)`
if (firstResult.success === false && 'nextAppDir' in firstResult) {
fs.mkdirSync(path.resolve(firstResult.nextAppDir, '(app)'))
fs.readdirSync(path.resolve(firstResult.nextAppDir)).forEach((file) => {
if (file === '(app)') return
fs.renameSync(
path.resolve(firstResult.nextAppDir, file),
path.resolve(firstResult.nextAppDir, '(app)', file),
)
})
}
// Rerun after moving files
const result = await initNext({
'--debug': true,
projectDir,
nextConfigPath: path.resolve(projectDir, 'next.config.mjs'),
dbType: 'mongodb',
useDistFiles: true, // create-payload-app/dist/app/(payload)
packageManager: 'pnpm',
})
expect(result.success).toEqual(true)
expect(result.nextAppDir).toEqual(
path.resolve(projectDir, result.isSrcDir ? 'src/app' : 'app'),
)
const payloadFilesPath = path.resolve(result.nextAppDir, '(payload)')
// shelljs.exec(`tree ${projectDir}`)
expect(fs.existsSync(payloadFilesPath)).toBe(true)
const payloadConfig = path.resolve(projectDir, 'payload.config.ts')
const payloadConfig = path.resolve(
projectDir,
result.isSrcDir ? 'src/payload.config.ts' : 'payload.config.ts',
)
expect(fs.existsSync(payloadConfig)).toBe(true)
const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')
@@ -95,7 +118,7 @@ describe('create-payload-app', () => {
compilerOptions?: CompilerOptions
}
expect(userTsConfig.compilerOptions.paths?.['@payload-config']).toStrictEqual([
'./payload.config.ts',
`./${result.isSrcDir ? 'src/' : ''}payload.config.ts`,
])
// TODO: Start the Next.js app and check if it runs

View File

@@ -149,7 +149,7 @@ describe('Live Preview', () => {
test('global - can edit fields', async () => {
await goToGlobalPreview(page, 'header')
const field = page.locator('input#field-navItems__0__link__newTab')
const field = page.locator('input#field-navItems__0__link____newTab')
await expect(field).toBeVisible()
await expect(field).toBeEnabled()
await field.check()

View File

@@ -2,7 +2,6 @@ import type { Page } from '@playwright/test'
import { expect, test } from '@playwright/test'
import path from 'path'
import payload from 'payload'
import { fileURLToPath } from 'url'
import type { Page as PayloadPage } from './payload-types.js'
@@ -11,6 +10,7 @@ import { initPageConsoleErrorCatch } from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import config from './config.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
@@ -22,22 +22,32 @@ let parentId: string
let draftChildId: string
let childId: string
async function createPage(data: Partial<PayloadPage>): Promise<PayloadPage> {
return payload.create({
collection: 'pages',
data,
}) as unknown as Promise<PayloadPage>
}
describe('Nested Docs Plugin', () => {
beforeAll(async ({ browser }) => {
const { serverURL } = await initPayloadE2E({ config, dirname })
const { serverURL, payload } = await initPayloadE2E({ config, dirname })
url = new AdminUrlUtil(serverURL, 'pages')
const context = await browser.newContext()
page = await context.newPage()
initPageConsoleErrorCatch(page)
async function createPage({
slug,
title = 'Title page',
parent,
_status = 'published',
}: Partial<PayloadPage>): Promise<PayloadPage> {
return payload.create({
collection: 'pages',
data: {
title,
slug,
_status,
parent,
},
}) as unknown as Promise<PayloadPage>
}
const parentPage = await createPage({ slug: 'parent-slug' })
parentId = parentPage.id
@@ -70,41 +80,58 @@ describe('Nested Docs Plugin', () => {
let slug = page.locator(slugClass).nth(0)
await expect(slug).toHaveValue('child-slug')
const parentSlugInChildClass = '#field-breadcrumbs__0__url'
// TODO: remove when error states are fixed
const apiTabButton = page.locator('text=API')
await apiTabButton.click()
const breadcrumbs = page.locator('text=/parent-slug').first()
await expect(breadcrumbs).toBeVisible()
const parentSlugInChild = page.locator(parentSlugInChildClass).nth(0)
await expect(parentSlugInChild).toHaveValue('/parent-slug')
// TODO: add back once error states are fixed
// const parentSlugInChildClass = '#field-breadcrumbs__0__url'
// const parentSlugInChild = page.locator(parentSlugInChildClass).nth(0)
// await expect(parentSlugInChild).toHaveValue('/parent-slug')
await page.goto(url.edit(parentId))
slug = page.locator(slugClass).nth(0)
await slug.fill('updated-parent-slug')
await expect(slug).toHaveValue('updated-parent-slug')
await page.locator(publishButtonClass).nth(0).click()
await page.waitForTimeout(1500)
await page.goto(url.edit(childId))
await expect(parentSlugInChild).toHaveValue('/updated-parent-slug')
// TODO: remove when error states are fixed
await apiTabButton.click()
const updatedBreadcrumbs = page.locator('text=/updated-parent-slug').first()
await expect(updatedBreadcrumbs).toBeVisible()
// TODO: add back once error states are fixed
// await expect(parentSlugInChild).toHaveValue('/updated-parent-slug')
})
test('Draft parent slug does not update child', async () => {
await page.goto(url.edit(draftChildId))
const parentSlugInChildClass = '#field-breadcrumbs__0__url'
// TODO: remove when error states are fixed
const apiTabButton = page.locator('text=API')
await apiTabButton.click()
const breadcrumbs = page.locator('text=/parent-slug-draft').first()
await expect(breadcrumbs).toBeVisible()
const parentSlugInChild = page.locator(parentSlugInChildClass).nth(0)
await expect(parentSlugInChild).toHaveValue('/parent-slug-draft')
// TODO: add back once error states are fixed
// const parentSlugInChildClass = '#field-breadcrumbs__0__url'
// const parentSlugInChild = page.locator(parentSlugInChildClass).nth(0)
// await expect(parentSlugInChild).toHaveValue('/parent-slug-draft')
await page.goto(url.edit(parentId))
await page.locator(slugClass).nth(0).fill('parent-updated-draft')
await page.locator(draftButtonClass).nth(0).click()
await page.waitForTimeout(1500)
await page.goto(url.edit(draftChildId))
await expect(parentSlugInChild).toHaveValue('/parent-slug-draft')
await apiTabButton.click()
const updatedBreadcrumbs = page.locator('text=/parent-slug-draft').first()
await expect(updatedBreadcrumbs).toBeVisible()
// TODO: add back when error states are fixed
// await expect(parentSlugInChild).toHaveValue('/parent-slug-draft')
})
})
})

View File

@@ -0,0 +1,9 @@
export interface Page {
id: string
parent?: string
slug: string
_status?: 'draft' | 'published'
title?: string
updatedAt: string
createdAt: string
}

View File

@@ -37,11 +37,10 @@ export default buildConfigWithDefaults({
plugins: [
seo({
collections: ['users'],
fields: [],
tabbedUI: true,
}),
seo({
collections: ['pages', 'posts'],
collections: ['pages'],
fieldOverrides: {
title: {
required: true,
@@ -58,7 +57,6 @@ export default buildConfigWithDefaults({
generateTitle: (data: any) => `Website.com — ${data?.doc?.title?.value}`,
generateURL: ({ doc, locale }: any) =>
`https://yoursite.com/${locale ? locale + '/' : ''}${doc?.slug?.value || ''}`,
globals: ['settings'],
tabbedUI: true,
uploadsCollection: 'media',
}),

View File

@@ -1,5 +1,4 @@
import type { Page } from '@playwright/test'
import type { Payload } from 'payload/types'
import { expect, test } from '@playwright/test'
import path from 'path'
@@ -11,20 +10,21 @@ import type { Page as PayloadPage } from './payload-types.js'
import { initPageConsoleErrorCatch } from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import config from '../uploads/config.js'
import config from './config.js'
import { mediaSlug } from './shared.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
const { beforeAll, describe } = test
let url: AdminUrlUtil
let page: Page
let id: string
let payload: Payload
describe('SEO Plugin', () => {
beforeAll(async ({ browser }) => {
const { serverURL } = await initPayloadE2E({ config, dirname })
const { serverURL, payload } = await initPayloadE2E({ config, dirname })
url = new AdminUrlUtil(serverURL, 'pages')
const context = await browser.newContext()
@@ -68,15 +68,17 @@ describe('SEO Plugin', () => {
test('Should auto-generate meta title when button is clicked in tabs', async () => {
const contentTabsClass = '.tabs-field__tabs .tabs-field__tab-button'
const autoGenerateButtonClass = '.group-field__wrap .render-fields div:nth-of-type(1) button'
const metaTitleClass = '#field-title'
const metaTitleClass = '#field-meta__title'
const secondTab = page.locator(contentTabsClass).nth(1)
await secondTab.click()
const metaTitle = page.locator(metaTitleClass).nth(0)
const metaTitle = page.locator(metaTitleClass)
await expect(metaTitle).toHaveValue('This is a test meta title')
const autoGenButton = page.locator(autoGenerateButtonClass).nth(0)
await expect(autoGenButton).toContainText('Auto-generate')
await autoGenButton.click()
await expect(metaTitle).toHaveValue('Website.com — Test Page')
@@ -108,17 +110,17 @@ describe('SEO Plugin', () => {
await page.goto(url.edit(id))
const contentTabsClass = '.tabs-field__tabs .tabs-field__tab-button'
const autoGenerateButtonClass = '.group-field__wrap .render-fields div:nth-of-type(1) button'
const metaDescriptionClass = '#field-description'
const metaDescriptionClass = '#field-meta__description'
const previewClass =
'#field-meta > div > div.render-fields.render-fields--margins-small > div:nth-child(6) > div:nth-child(3)'
'#field-meta > div > div.render-fields.render-fields--margins-small > div:nth-child(6)'
const secondTab = page.locator(contentTabsClass).nth(1)
await secondTab.click()
const metaDescription = page.locator(metaDescriptionClass).nth(0)
const metaDescription = page.locator(metaDescriptionClass)
await metaDescription.fill('My new amazing SEO description')
const preview = page.locator(previewClass).nth(0)
const preview = page.locator(previewClass)
await expect(preview).toContainText('https://yoursite.com/en/')
await expect(preview).toContainText('This is a test meta title')
await expect(preview).toContainText('My new amazing SEO description')
@@ -147,6 +149,7 @@ describe('SEO Plugin', () => {
// Change language to Spanish
await languageField.click()
await options.locator('text=Español').click()
await expect(languageField).toContainText('Español')
// Navigate back to the page
await page.goto(url.edit(id))