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[1], ): Promise<{ popupContentLocator: Locator rowActionsButtonLocator: Locator }> => { const rowLocator = page.locator(`#field-${fieldName} > .array-field__draggable-rows > *`) 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 } }