Files
payload/test/helpers/assertToastErrors.ts
Jarrod Flesch 48115311e7 fix(ui): incorrect error states (#11574)
Fixes https://github.com/payloadcms/payload/issues/11568

### What? Out of sync errors states
- Collaspibles & Tabs were not reporting accurate child error counts
- Arrays could get into a state where they would not update their error
states
- Slight issue with toasts 

### Tabs & Collapsibles
The logic for determining matching field paths was not functioning as
intended. Fields were attempting to match with paths such as `_index-0`
which will not work.

### Arrays
The form state was not updating when the server sent back errorPaths.
This PR adds `errorPaths` to `serverPropsToAccept`.

### Toasts
Some toasts could report errors in the form of `my > > error`. This
ensures they will be `my > error`

### Misc
Removes 2 files that were not in use:
- `getFieldStateFromPaths.ts`
- `getNestedFieldState.ts`
2025-03-06 14:02:10 -05:00

28 lines
701 B
TypeScript

import type { Page } from '@playwright/test'
import { expect } from '@playwright/test'
export async function assertToastErrors({
page,
errors,
}: {
errors: string[]
page: Page
}): Promise<void> {
const message =
errors.length === 1
? 'The following field is invalid:'
: `The following fields are invalid (${errors.length}):`
await expect(
page.locator('.payload-toast-container li').filter({ hasText: message }),
).toBeVisible()
for (let i = 0; i < errors.length; i++) {
const error = errors[i]
if (error) {
await expect(
page.locator('.payload-toast-container [data-testid="field-errors"] li').nth(i),
).toHaveText(error)
}
}
}