fix: corrects block duplicate action and add tests (#6589)
This commit is contained in:
committed by
GitHub
parent
be0462db56
commit
763a34f19b
@@ -247,7 +247,7 @@ export function fieldReducer(state: FormState, action: FieldAction): FormState {
|
|||||||
case 'DUPLICATE_ROW': {
|
case 'DUPLICATE_ROW': {
|
||||||
const { path, rowIndex } = action
|
const { path, rowIndex } = action
|
||||||
const { remainingFields, rows } = separateRows(path, state)
|
const { remainingFields, rows } = separateRows(path, state)
|
||||||
const rowsMetadata = state[path]?.rows || []
|
const rowsMetadata = [...(state[path].rows || [])]
|
||||||
|
|
||||||
const duplicateRowMetadata = deepCopyObject(rowsMetadata[rowIndex])
|
const duplicateRowMetadata = deepCopyObject(rowsMetadata[rowIndex])
|
||||||
if (duplicateRowMetadata.id) duplicateRowMetadata.id = new ObjectId().toHexString()
|
if (duplicateRowMetadata.id) duplicateRowMetadata.id = new ObjectId().toHexString()
|
||||||
@@ -264,13 +264,13 @@ export function fieldReducer(state: FormState, action: FieldAction): FormState {
|
|||||||
|
|
||||||
const newState = {
|
const newState = {
|
||||||
...remainingFields,
|
...remainingFields,
|
||||||
|
...flattenRows(path, rows),
|
||||||
[path]: {
|
[path]: {
|
||||||
...state[path],
|
...state[path],
|
||||||
disableFormData: true,
|
disableFormData: true,
|
||||||
rows: rowsMetadata,
|
rows: rowsMetadata,
|
||||||
value: rows.length,
|
value: rows.length,
|
||||||
},
|
},
|
||||||
...flattenRows(path, rows),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newState
|
return newState
|
||||||
|
|||||||
@@ -115,6 +115,21 @@ describe('Block fields', () => {
|
|||||||
await expect(addedRow.locator('.blocks-field__block-pill-content')).toContainText('Content') // went from `Number` to `Content`
|
await expect(addedRow.locator('.blocks-field__block-pill-content')).toContainText('Content') // went from `Number` to `Content`
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should duplicate block', async () => {
|
||||||
|
await page.goto(url.create)
|
||||||
|
const firstRow = page.locator('#field-blocks #blocks-row-0')
|
||||||
|
const rowActions = firstRow.locator('.collapsible__actions')
|
||||||
|
await expect(rowActions).toBeVisible()
|
||||||
|
|
||||||
|
await rowActions.locator('.array-actions__button').click()
|
||||||
|
const duplicateButton = rowActions.locator('.array-actions__action.array-actions__duplicate')
|
||||||
|
await expect(duplicateButton).toBeVisible()
|
||||||
|
await duplicateButton.click()
|
||||||
|
|
||||||
|
const blocks = page.locator('#field-blocks > .blocks-field__rows > div')
|
||||||
|
expect(await blocks.count()).toEqual(4)
|
||||||
|
})
|
||||||
|
|
||||||
test('should use i18n block labels', async () => {
|
test('should use i18n block labels', async () => {
|
||||||
await page.goto(url.create)
|
await page.goto(url.create)
|
||||||
await expect(page.locator('#field-i18nBlocks .blocks-field__header')).toContainText('Block en')
|
await expect(page.locator('#field-i18nBlocks .blocks-field__header')).toContainText('Block en')
|
||||||
|
|||||||
Reference in New Issue
Block a user