Files
payloadcms/test/helpers/e2e/fields/array/addArrayRow.ts
Jacob Fletcher adb83b1e06 test: add array field helpers (#13493)
Adds various helpers to make it easier and more standard to manage array
fields within e2e tests. Retrofits existing tests to ensure consistent
interactions across the board, and also organizes existing blocks and
relationship field helpers in the same way.

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211094073049046
2025-08-19 19:44:59 +00:00

48 lines
1.4 KiB
TypeScript

import type { Locator, Page } from 'playwright'
import { wait } from 'payload/shared'
import { openArrayRowActions } from './openArrayRowActions.js'
/**
* Does not wait after adding the row for the row to appear and fully load in. Simply clicks the primary "Add Row" button and moves on.
*/
export const addArrayRowAsync = async (page: Page, fieldName: string) => {
await page.locator(`#field-${fieldName} > .array-field__add-row`).first().click()
}
/**
* Adds an array row to the end of the array using the primary "Add Row" button.
*/
export const addArrayRow = async (
page: Page,
{ fieldName }: Omit<Parameters<typeof openArrayRowActions>[1], 'rowIndex'>,
) => {
await addArrayRowAsync(page, fieldName)
// TODO: test the array row has appeared
await wait(300)
}
/**
* Like `addArrayRow`, but inserts the row at the specified index using the row actions menu.
*/
export const addArrayRowBelow = async (
page: Page,
{ fieldName, rowIndex = 0 }: Parameters<typeof openArrayRowActions>[1],
): Promise<{ popupContentLocator: Locator; rowActionsButtonLocator: Locator }> => {
const { popupContentLocator, rowActionsButtonLocator } = await openArrayRowActions(page, {
fieldName,
rowIndex,
})
const addBelowButton = popupContentLocator.locator('.array-actions__action.array-actions__add')
await addBelowButton.click()
// TODO: test the array row has appeared
await wait(300)
return { popupContentLocator, rowActionsButtonLocator }
}