Files
payloadcms/test/helpers/e2e/fields/array/duplicateArrayRow.ts
Jacob Fletcher b8d7ccb4dc fix(ui): use consistent row ids when duplicating array and block rows (#13679)
Fixes #13653.

Duplicating array rows causes phantom rows to appear. This is because
when duplicate the row locally, we use inconsistent row IDs, e.g. the
`array.rows[0].id` does not match its `array.0.id` counterpart. This
causes form state to lose the reference to the existing row, which the
server interprets as new row as of #13551.

Before:


https://github.com/user-attachments/assets/9f7efc59-ebd9-4fbb-b643-c22d4d3140a3

After:


https://github.com/user-attachments/assets/188db823-4ee5-4757-8b89-751c8d978ad9

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211210023936585
2025-09-03 14:29:39 -04:00

33 lines
987 B
TypeScript

import type { Locator, Page } from 'playwright'
import { expect } from 'playwright/test'
import { openArrayRowActions } from './openArrayRowActions.js'
/**
* Duplicates the array row at the specified index.
*/
export const duplicateArrayRow = async (
page: Page,
{ fieldName, rowIndex = 0 }: Parameters<typeof openArrayRowActions>[1],
): Promise<{
popupContentLocator: Locator
rowActionsButtonLocator: Locator
}> => {
const rowLocator = page.locator(`#field-${fieldName} .array-field__row`)
const numberOfPrevRows = await rowLocator.count()
const { popupContentLocator, rowActionsButtonLocator } = await openArrayRowActions(page, {
fieldName,
rowIndex,
})
await popupContentLocator.locator('.array-actions__action.array-actions__duplicate').click()
expect(await rowLocator.count()).toBe(numberOfPrevRows + 1)
// TODO: test the array row's field input values have been duplicated as well
return { popupContentLocator, rowActionsButtonLocator }
}