Files
payloadcms/test/helpers/assertToastErrors.ts
Jarrod Flesch fcb8b5a066 feat(plugin-multi-tenant): improves tenant assignment flow (#13881)
### Improved tenant assignment flow
This PR improves the tenant assignment flow. I know a lot of users liked
the previous flow where the field was not injected into the document.
But the original flow, confused many of users because the tenant filter
(top left) was being used to set the tenant on the document _and_ filter
the list view.

This change shown below is aiming to solve both of those groups with a
slightly different approach. As always, feedback is welcome while we try
to really make this plugin work for everyone.


https://github.com/user-attachments/assets/ceee8b3a-c5f5-40e9-8648-f583e2412199

Added 2 new localization strings:

```
// shown in the 3 dot menu
'assign-tenant-button-label': 'Assign Tenant',

// shown when needing to assign a tenant to a NEW document
'assign-tenant-modal-title': 'Assign "{{title}}"',
```

Removed 2 localization strings:
```
'confirm-modal-tenant-switch--body',
'confirm-modal-tenant-switch--heading'
```
2025-09-24 13:19:33 -04:00

44 lines
1.2 KiB
TypeScript

import type { Page } from '@playwright/test'
import { expect } from '@playwright/test'
export async function assertToastErrors({
page,
errors,
dismissAfterAssertion,
}: {
dismissAfterAssertion?: boolean
errors: string[]
page: Page
}): Promise<void> {
const isSingleError = errors.length === 1
const message = isSingleError
? 'The following field is invalid: '
: `The following fields are invalid (${errors.length}):`
// Check the intro message text
await expect(page.locator('.payload-toast-container')).toContainText(message)
// Check single error
if (isSingleError) {
await expect(page.locator('.payload-toast-container [data-testid="field-error"]')).toHaveText(
errors[0]!,
)
} else {
// Check multiple errors
const errorItems = page.locator('.payload-toast-container [data-testid="field-errors"] li')
for (let i = 0; i < errors.length; i++) {
await expect(errorItems.nth(i)).toHaveText(errors[i]!)
}
}
if (dismissAfterAssertion) {
const closeButtons = page.locator('.payload-toast-container button.payload-toast-close-button')
const count = await closeButtons.count()
for (let i = 0; i < count; i++) {
await closeButtons.nth(i).click()
}
}
}