Similar to the goals of #11026. Adds helper utilities to make interacting with the blocks field easier within e2e tests. This will also standardize common functionality across tests and reduce the overall lines of code for each, making them easier to navigate and digest. The following helpers are now available: - `openBlocksDrawer`: self-explanatory - `addBlock`: opens the blocks drawer and selects the given block - `reorderBlocks`: similar to `reorderColumn`, moves blocks using the drag handle - `removeAllBlocks`: iterates all rows of a given blocks field and removes them
26 lines
738 B
TypeScript
26 lines
738 B
TypeScript
import type { Page } from '@playwright/test'
|
|
|
|
import { expect } from '@playwright/test'
|
|
|
|
export const removeAllBlocks = async ({
|
|
page,
|
|
fieldName = 'blocks',
|
|
}: {
|
|
fieldName: string
|
|
page: Page
|
|
}) => {
|
|
const blocksField = page.locator(`#field-${fieldName}`)
|
|
|
|
const blocks = blocksField.locator(`[id^="${fieldName}-row-"]`)
|
|
const count = await blocks.count()
|
|
|
|
expect(count).toBeGreaterThan(0)
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
// delete in reverse order to avoid index issues
|
|
const block = blocksField.locator(`[id^="${fieldName}-row-${count - i - 1}"]`)
|
|
await block.locator('.array-actions__button').first().click()
|
|
await block.locator('.array-actions__action.array-actions__remove').first().click()
|
|
}
|
|
}
|