# Breaking Changes
### New file import locations
Exports from the `payload` package have been _significantly_ cleaned up.
Now, just about everything is able to be imported from `payload`
directly, rather than an assortment of subpath exports. This means that
things like `import { buildConfig } from 'payload/config'` are now just
imported via `import { buildConfig } from 'payload'`. The mental model
is significantly simpler for developers, but you might need to update
some of your imports.
Payload now exposes only three exports:
1. `payload` - all types and server-only Payload code
2. `payload/shared` - utilities that can be used in either the browser
or in Node environments
3. `payload/node` - heavy utilities that should only be imported in Node
scripts and never be imported into bundled code like Next.js
### UI library pre-bundling
With this release, we've dramatically sped up the compile time for
Payload by pre-bundling our entire UI package for use inside of the
Payload admin itself. There are new exports that should be used within
Payload custom components:
1. `@payloadcms/ui/client` - all client components
2. `@payloadcms/ui/server` - all server components
For all of your custom Payload admin UI components, you should be
importing from one of these two pre-compiled barrel files rather than
importing from the more deeply nested exports directly. That will keep
compile times nice and speedy, and will also make sure that the bundled
JS for your admin UI is kept small.
For example, whereas before, if you imported the Payload `Button`, you
would have imported it like this:
```ts
import { Button } from '@payloadcms/ui/elements/Button'
```
Now, you would import it like this:
```ts
import { Button } from '@payloadcms/ui/client'
```
This is a significant DX / performance optimization that we're pretty
pumped about.
However, if you are importing or re-using Payload UI components
_outside_ of the Payload admin UI, for example in your own frontend
apps, you can import from the individual component exports which will
make sure that the bundled JS is kept to a minimum in your frontend
apps. So in your own frontend, you can continue to import directly to
the components that you want to consume rather than importing from the
pre-compiled barrel files.
Individual component exports will now come with their corresponding CSS
and everything will work perfectly as-expected.
### Specific exports have changed
- `'@payloadcms/ui/templates/Default'` and
`'@payloadcms/ui/templates/Minimal`' are now exported from
`'@payloadcms/next/templates'`
- Old: `import { LogOut } from '@payloadcms/ui/icons/LogOut'` new:
`import { LogOutIcon } from '@payloadcms/ui/icons/LogOut'`
## Background info
In effort to make local dev as fast as possible, we need to import as
few files as possible so that the compiler has less to process. One way
we've achieved this in the Admin Panel was to _remove_ all .scss imports
from all components in the `@payloadcms/ui` module using a build
process. This stripped all `import './index.scss'` statements out of
each component before injecting them into `dist`. Instead, it bundles
all of the CSS into a single `main.css` file, and we import _that_ at
the root of the app.
While this concept is _still_ the right solution to the problem, this
particular approach is not viable when using these components outside
the Admin Panel, where not only does this root stylesheet not exist, but
where it would also bloat your app with unused styles. Instead, we need
to _keep_ these .scss imports in place so they are imported directly
alongside your components, as expected. Then, we need create a _new_
build step that _separately_ compiles the components _without_ their
stylesheets—this way your app can consume either as needed from the new
`client` and `server` barrel files within `@payloadcms/ui`, i.e. from
within `@payloadcms/next` and all other admin-specific packages and
plugins.
This way, all other applications will simply import using the direct
file paths, just as they did before. Except now they come with
stylesheets.
And we've gotten a pretty awesome initial compilation performance boost.
---------
Co-authored-by: James <james@trbl.design>
Co-authored-by: Alessio Gravili <alessio@gravili.de>
476 lines
16 KiB
TypeScript
476 lines
16 KiB
TypeScript
import type { Page } from '@playwright/test'
|
|
|
|
import { expect, test } from '@playwright/test'
|
|
import path from 'path'
|
|
import { wait } from 'payload/shared'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
import type { PayloadTestSDK } from '../helpers/sdk/index.js'
|
|
import type { Config } from './payload-types.js'
|
|
|
|
import {
|
|
ensureAutoLoginAndCompilationIsDone,
|
|
initPageConsoleErrorCatch,
|
|
saveDocAndAssert,
|
|
} from '../helpers.js'
|
|
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
|
|
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
|
|
import { reInitializeDB } from '../helpers/reInitializeDB.js'
|
|
import { RESTClient } from '../helpers/rest.js'
|
|
import { POLL_TOPASS_TIMEOUT, TEST_TIMEOUT_LONG } from '../playwright.config.js'
|
|
import { jsonDoc } from './collections/JSON/shared.js'
|
|
import {
|
|
arrayFieldsSlug,
|
|
blockFieldsSlug,
|
|
collapsibleFieldsSlug,
|
|
tabsFields2Slug,
|
|
} from './slugs.js'
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
|
|
const { beforeAll, beforeEach, describe } = test
|
|
|
|
let payload: PayloadTestSDK<Config>
|
|
let client: RESTClient
|
|
let page: Page
|
|
let serverURL: string
|
|
// If we want to make this run in parallel: test.describe.configure({ mode: 'parallel' })
|
|
|
|
describe('fields', () => {
|
|
beforeAll(async ({ browser }, testInfo) => {
|
|
testInfo.setTimeout(TEST_TIMEOUT_LONG)
|
|
process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit
|
|
;({ payload, serverURL } = await initPayloadE2ENoConfig({
|
|
dirname,
|
|
// prebuild,
|
|
}))
|
|
|
|
const context = await browser.newContext()
|
|
page = await context.newPage()
|
|
initPageConsoleErrorCatch(page)
|
|
await reInitializeDB({
|
|
serverURL,
|
|
snapshotKey: 'fieldsTest',
|
|
uploadsDir: path.resolve(dirname, './collections/Upload/uploads'),
|
|
})
|
|
await ensureAutoLoginAndCompilationIsDone({ page, serverURL })
|
|
})
|
|
beforeEach(async () => {
|
|
await reInitializeDB({
|
|
serverURL,
|
|
snapshotKey: 'fieldsTest',
|
|
uploadsDir: path.resolve(dirname, './collections/Upload/uploads'),
|
|
})
|
|
|
|
if (client) {
|
|
await client.logout()
|
|
}
|
|
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
|
|
await client.login()
|
|
|
|
await ensureAutoLoginAndCompilationIsDone({ page, serverURL })
|
|
})
|
|
|
|
describe('indexed', () => {
|
|
let url: AdminUrlUtil
|
|
beforeEach(() => {
|
|
url = new AdminUrlUtil(serverURL, 'indexed-fields')
|
|
})
|
|
|
|
// TODO - This test is flaky. Rarely, but sometimes it randomly fails.
|
|
test('should display unique constraint error in ui', async () => {
|
|
const uniqueText = 'uniqueText'
|
|
await payload.create({
|
|
collection: 'indexed-fields',
|
|
data: {
|
|
group: {
|
|
unique: uniqueText,
|
|
},
|
|
text: 'text',
|
|
uniqueRequiredText: 'text',
|
|
uniqueText,
|
|
},
|
|
})
|
|
|
|
await page.goto(url.create)
|
|
await page.waitForURL(url.create)
|
|
|
|
await page.locator('#field-text').fill('test')
|
|
await page.locator('#field-uniqueText').fill(uniqueText)
|
|
await page.locator('#field-localizedUniqueRequiredText').fill('localizedUniqueRequired2')
|
|
|
|
await wait(500)
|
|
|
|
// attempt to save
|
|
await page.click('#action-save', { delay: 200 })
|
|
|
|
// toast error
|
|
await expect(page.locator('.payload-toast-container')).toContainText(
|
|
'The following field is invalid: uniqueText',
|
|
)
|
|
|
|
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('create')
|
|
|
|
// field specific error
|
|
await expect(page.locator('.field-type.text.error #field-uniqueText')).toBeVisible()
|
|
|
|
// reset first unique field
|
|
await page.locator('#field-uniqueText').clear()
|
|
|
|
// nested in a group error
|
|
await page.locator('#field-group__unique').fill(uniqueText)
|
|
|
|
await wait(1000)
|
|
|
|
// attempt to save
|
|
await page.locator('#action-save').click()
|
|
|
|
// toast error
|
|
await expect(page.locator('.payload-toast-container')).toContainText(
|
|
'The following field is invalid: group.unique',
|
|
)
|
|
|
|
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('create')
|
|
|
|
// field specific error inside group
|
|
await expect(page.locator('.field-type.text.error #field-group__unique')).toBeVisible()
|
|
})
|
|
})
|
|
|
|
describe('json', () => {
|
|
let url: AdminUrlUtil
|
|
beforeAll(() => {
|
|
url = new AdminUrlUtil(serverURL, 'json-fields')
|
|
})
|
|
|
|
test('should display field in list view', async () => {
|
|
await page.goto(url.list)
|
|
const jsonCell = page.locator('.row-1 .cell-json')
|
|
await expect(jsonCell).toHaveText(JSON.stringify(jsonDoc.json))
|
|
})
|
|
|
|
test('should create', async () => {
|
|
const input = '{"foo": "bar"}'
|
|
await page.goto(url.create)
|
|
await page.waitForURL(url.create)
|
|
await expect(() => expect(page.locator('.json-field .code-editor')).toBeVisible()).toPass({
|
|
timeout: POLL_TOPASS_TIMEOUT,
|
|
})
|
|
await page.locator('.json-field .inputarea').fill(input)
|
|
await saveDocAndAssert(page)
|
|
await expect(page.locator('.json-field')).toContainText('"foo": "bar"')
|
|
})
|
|
})
|
|
|
|
describe('radio', () => {
|
|
let url: AdminUrlUtil
|
|
beforeAll(() => {
|
|
url = new AdminUrlUtil(serverURL, 'radio-fields')
|
|
})
|
|
|
|
test('should show i18n label in list', async () => {
|
|
await page.goto(url.list)
|
|
await expect(page.locator('.cell-radio')).toHaveText('Value One')
|
|
})
|
|
|
|
test('should show i18n label while editing', async () => {
|
|
await page.goto(url.create)
|
|
await expect(page.locator('label[for="field-radio"]')).toHaveText('Radio en')
|
|
})
|
|
|
|
test('should show i18n radio labels', async () => {
|
|
await page.goto(url.create)
|
|
await expect(page.locator('label[for="field-radio-one"] .radio-input__label')).toHaveText(
|
|
'Value One',
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('select', () => {
|
|
let url: AdminUrlUtil
|
|
beforeAll(() => {
|
|
url = new AdminUrlUtil(serverURL, 'select-fields')
|
|
})
|
|
|
|
test('should use i18n option labels', async () => {
|
|
await page.goto(url.create)
|
|
|
|
const field = page.locator('#field-selectI18n')
|
|
await field.click({ delay: 100 })
|
|
const options = page.locator('.rs__option')
|
|
// Select an option
|
|
await options.locator('text=One').click()
|
|
|
|
await saveDocAndAssert(page)
|
|
await expect(field.locator('.rs__value-container')).toContainText('One')
|
|
})
|
|
})
|
|
|
|
describe('collapsible', () => {
|
|
let url: AdminUrlUtil
|
|
beforeAll(() => {
|
|
url = new AdminUrlUtil(serverURL, collapsibleFieldsSlug)
|
|
})
|
|
|
|
test('should render collapsible as collapsed if initCollapsed is true', async () => {
|
|
await page.goto(url.create)
|
|
const collapsedCollapsible = page.locator(
|
|
'#field-collapsible-1 .collapsible__toggle--collapsed',
|
|
)
|
|
await expect(collapsedCollapsible).toBeVisible()
|
|
})
|
|
|
|
test('should render CollapsibleLabel using a function', async () => {
|
|
const label = 'custom row label'
|
|
await page.goto(url.create)
|
|
await page.locator('#field-collapsible-3__1 #field-nestedTitle').fill(label)
|
|
await wait(100)
|
|
const customCollapsibleLabel = page.locator(
|
|
`#field-collapsible-3__1 .collapsible-field__row-label-wrap :text("${label}")`,
|
|
)
|
|
await expect(customCollapsibleLabel).toContainText(label)
|
|
})
|
|
|
|
test('should render CollapsibleLabel using a component', async () => {
|
|
const label = 'custom row label as component'
|
|
await page.goto(url.create)
|
|
await page.locator('#field-arrayWithCollapsibles').scrollIntoViewIfNeeded()
|
|
|
|
const arrayWithCollapsibles = page.locator('#field-arrayWithCollapsibles')
|
|
await expect(arrayWithCollapsibles).toBeVisible()
|
|
|
|
await page.locator('#field-arrayWithCollapsibles >> .array-field__add-row').click()
|
|
|
|
await page
|
|
.locator(
|
|
'#arrayWithCollapsibles-row-0 #field-collapsible-4__0-arrayWithCollapsibles__0 #field-arrayWithCollapsibles__0__innerCollapsible',
|
|
)
|
|
.fill(label)
|
|
await wait(100)
|
|
const customCollapsibleLabel = page.locator(
|
|
`#field-arrayWithCollapsibles >> #arrayWithCollapsibles-row-0 >> .collapsible-field__row-label-wrap :text("${label}")`,
|
|
)
|
|
await expect(customCollapsibleLabel).toHaveCSS('text-transform', 'uppercase')
|
|
})
|
|
})
|
|
|
|
describe('sortable arrays', () => {
|
|
let url: AdminUrlUtil
|
|
beforeAll(() => {
|
|
url = new AdminUrlUtil(serverURL, arrayFieldsSlug)
|
|
})
|
|
|
|
test('should have disabled admin sorting', async () => {
|
|
await page.goto(url.create)
|
|
const field = page.locator('#field-disableSort > div > div > .array-actions__action-chevron')
|
|
expect(await field.count()).toEqual(0)
|
|
})
|
|
|
|
test('the drag handle should be hidden', async () => {
|
|
await page.goto(url.create)
|
|
const field = page.locator(
|
|
'#field-disableSort > .blocks-field__rows > div > div > .collapsible__drag',
|
|
)
|
|
expect(await field.count()).toEqual(0)
|
|
})
|
|
})
|
|
|
|
describe('sortable blocks', () => {
|
|
let url: AdminUrlUtil
|
|
beforeAll(() => {
|
|
url = new AdminUrlUtil(serverURL, blockFieldsSlug)
|
|
})
|
|
|
|
test('should have disabled admin sorting', async () => {
|
|
await page.goto(url.create)
|
|
const field = page.locator('#field-disableSort > div > div > .array-actions__action-chevron')
|
|
expect(await field.count()).toEqual(0)
|
|
})
|
|
|
|
test('the drag handle should be hidden', async () => {
|
|
await page.goto(url.create)
|
|
const field = page.locator(
|
|
'#field-disableSort > .blocks-field__rows > div > div > .collapsible__drag',
|
|
)
|
|
expect(await field.count()).toEqual(0)
|
|
})
|
|
})
|
|
|
|
describe('row', () => {
|
|
let url: AdminUrlUtil
|
|
beforeAll(() => {
|
|
url = new AdminUrlUtil(serverURL, 'row-fields')
|
|
})
|
|
|
|
test('should show row fields as table columns', async () => {
|
|
await page.goto(url.create)
|
|
|
|
// fill the required fields, including the row field
|
|
const idInput = page.locator('input#field-id')
|
|
await idInput.fill('123')
|
|
const titleInput = page.locator('input#field-title')
|
|
await titleInput.fill('Row 123')
|
|
await page.locator('#action-save').click()
|
|
await wait(200)
|
|
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
|
|
|
|
// ensure the 'title' field is visible in the table header
|
|
await page.goto(url.list)
|
|
const titleHeading = page.locator('th#heading-title')
|
|
await expect(titleHeading).toBeVisible()
|
|
|
|
// ensure the 'title' field shows the correct value in the table cell
|
|
const titleCell = page.locator('.row-1 td.cell-title')
|
|
await expect(titleCell).toBeVisible()
|
|
await expect(titleCell).toContainText('Row 123')
|
|
})
|
|
|
|
test('should not show duplicative ID field', async () => {
|
|
await page.goto(url.create)
|
|
// fill the required fields, including the custom ID field
|
|
const idInput = page.locator('input#field-id')
|
|
await idInput.fill('456')
|
|
const titleInput = page.locator('input#field-title')
|
|
await titleInput.fill('Row 456')
|
|
await page.locator('#action-save').click()
|
|
await wait(200)
|
|
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
|
|
|
|
// ensure there are not two ID fields in the table header
|
|
await page.goto(url.list)
|
|
const idHeadings = page.locator('th#heading-id')
|
|
await expect(idHeadings).toBeVisible()
|
|
await expect(idHeadings).toHaveCount(1)
|
|
})
|
|
|
|
test('should render row fields inline and with explicit widths', async () => {
|
|
await page.goto(url.create)
|
|
const fieldA = page.locator('input#field-field_with_width_a')
|
|
await expect(fieldA).toBeVisible()
|
|
const fieldB = page.locator('input#field-field_with_width_b')
|
|
await expect(fieldB).toBeVisible()
|
|
const fieldABox = await fieldA.boundingBox()
|
|
const fieldBBox = await fieldB.boundingBox()
|
|
|
|
// Check that the top value of the fields are the same
|
|
// Give it some wiggle room of like 2px to account for differences in rendering
|
|
const tolerance = 2
|
|
expect(fieldABox.y).toBeLessThanOrEqual(fieldBBox.y + tolerance)
|
|
|
|
// Check that the widths of the fields are the same
|
|
const difference = Math.abs(fieldABox.width - fieldBBox.width)
|
|
expect(difference).toBeLessThanOrEqual(tolerance)
|
|
})
|
|
|
|
test('should render nested row fields in the correct position', async () => {
|
|
await page.goto(url.create)
|
|
|
|
// These fields are not given explicit `width` values
|
|
await page.goto(url.create)
|
|
const fieldA = page.locator('input#field-field_within_collapsible_a')
|
|
await expect(fieldA).toBeVisible()
|
|
const fieldB = page.locator('input#field-field_within_collapsible_b')
|
|
await expect(fieldB).toBeVisible()
|
|
const fieldABox = await fieldA.boundingBox()
|
|
const fieldBBox = await fieldB.boundingBox()
|
|
|
|
// Check that the top value of the fields are the same
|
|
// Give it some wiggle room of like 2px to account for differences in rendering
|
|
const tolerance = 2
|
|
expect(fieldABox.y).toBeLessThanOrEqual(fieldBBox.y + tolerance)
|
|
|
|
// Check that the widths of the fields are the same
|
|
const collapsibleDifference = Math.abs(fieldABox.width - fieldBBox.width)
|
|
|
|
expect(collapsibleDifference).toBeLessThanOrEqual(tolerance)
|
|
})
|
|
})
|
|
|
|
describe('ui', () => {
|
|
let url: AdminUrlUtil
|
|
beforeAll(() => {
|
|
url = new AdminUrlUtil(serverURL, 'ui-fields')
|
|
})
|
|
|
|
test('should show custom: client configuration', async () => {
|
|
await page.goto(url.create)
|
|
|
|
const uiField = page.locator('#uiCustomClient')
|
|
|
|
await expect(uiField).toBeVisible()
|
|
await expect(uiField).toContainText('client-side-configuration')
|
|
})
|
|
})
|
|
|
|
describe('conditional logic', () => {
|
|
let url: AdminUrlUtil
|
|
beforeAll(() => {
|
|
url = new AdminUrlUtil(serverURL, 'conditional-logic')
|
|
})
|
|
|
|
test('should toggle conditional field when data changes', async () => {
|
|
await page.goto(url.create)
|
|
const toggleField = page.locator('label[for=field-toggleField]')
|
|
await toggleField.click()
|
|
|
|
const fieldToToggle = page.locator('input#field-fieldToToggle')
|
|
|
|
await expect(fieldToToggle).toBeVisible()
|
|
})
|
|
|
|
test('should show conditional field based on user data', async () => {
|
|
await page.goto(url.create)
|
|
const userConditional = page.locator('input#field-userConditional')
|
|
await expect(userConditional).toBeVisible()
|
|
})
|
|
|
|
test('should show conditional field based on fields nested within data', async () => {
|
|
await page.goto(url.create)
|
|
|
|
const parentGroupFields = page.locator(
|
|
'div#field-parentGroup > .group-field__wrap > .render-fields',
|
|
)
|
|
await expect(parentGroupFields).toHaveCount(1)
|
|
|
|
const toggle = page.locator('label[for=field-parentGroup__enableParentGroupFields]')
|
|
await toggle.click()
|
|
|
|
const toggledField = page.locator('input#field-parentGroup__siblingField')
|
|
|
|
await expect(toggledField).toBeVisible()
|
|
})
|
|
|
|
test('should show conditional field based on fields nested within siblingData', async () => {
|
|
await page.goto(url.create)
|
|
|
|
const toggle = page.locator('label[for=field-parentGroup__enableParentGroupFields]')
|
|
await toggle.click()
|
|
|
|
const fieldRelyingOnSiblingData = page.locator('input#field-reliesOnParentGroup')
|
|
await expect(fieldRelyingOnSiblingData).toBeVisible()
|
|
})
|
|
})
|
|
|
|
describe('tabs', () => {
|
|
let url: AdminUrlUtil
|
|
beforeAll(() => {
|
|
url = new AdminUrlUtil(serverURL, tabsFields2Slug)
|
|
})
|
|
|
|
test('should correctly save nested unnamed and named tabs', async () => {
|
|
await page.goto(url.create)
|
|
|
|
await page.locator('#field-tabsInArray .array-field__add-row').click()
|
|
await page.locator('#field-tabsInArray__0__text').fill('tab 1 text')
|
|
await page.locator('.tabs-field__tabs button:nth-child(2)').click()
|
|
await page.locator('#field-tabsInArray__0__tab2__text2').fill('tab 2 text')
|
|
|
|
await saveDocAndAssert(page)
|
|
|
|
await expect(page.locator('#field-tabsInArray__0__text')).toHaveValue('tab 1 text')
|
|
await page.locator('.tabs-field__tabs button:nth-child(2)').click()
|
|
await expect(page.locator('#field-tabsInArray__0__tab2__text2')).toHaveValue('tab 2 text')
|
|
})
|
|
})
|
|
})
|