fix: block row removal w/ db-postgres adapter (#3951)

This commit is contained in:
Jarrod Flesch
2023-11-01 08:32:02 -04:00
committed by GitHub
parent 386fe0741d
commit 5ea88bb47d
11 changed files with 107 additions and 81 deletions

View File

@@ -1,7 +1,6 @@
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
import { ArrayRowLabel } from './LabelComponent'
import { AddCustomBlocks } from './components/AddCustomBlocks'
export const arrayDefaultValue = [{ text: 'row one' }, { text: 'row two' }]
@@ -127,39 +126,6 @@ const ArrayFields: CollectionConfig = {
},
},
},
{
name: 'customBlocks',
type: 'blocks',
blocks: [
{
slug: 'block-1',
fields: [
{
name: 'block1Title',
type: 'text',
},
],
},
{
slug: 'block-2',
fields: [
{
name: 'block2Title',
type: 'text',
},
],
},
],
},
{
type: 'ui',
name: 'ui',
admin: {
components: {
Field: AddCustomBlocks,
},
},
},
],
}

View File

@@ -1,6 +1,8 @@
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
import type { BlockField } from '../../../../packages/payload/src/fields/config/types'
import { AddCustomBlocks } from './components/AddCustomBlocks'
export const getBlocksFieldSeedData = (prefix?: string): any => [
{
blockName: 'First block',
@@ -210,7 +212,7 @@ const BlockFields: CollectionConfig = {
name: 'blocksWithSimilarConfigs',
blocks: [
{
slug: 'block-1',
slug: 'block-a',
fields: [
{
type: 'array',
@@ -226,7 +228,7 @@ const BlockFields: CollectionConfig = {
],
},
{
slug: 'block-2',
slug: 'block-b',
fields: [
{
type: 'array',
@@ -243,6 +245,39 @@ const BlockFields: CollectionConfig = {
},
],
},
{
name: 'customBlocks',
type: 'blocks',
blocks: [
{
slug: 'block-1',
fields: [
{
name: 'block1Title',
type: 'text',
},
],
},
{
slug: 'block-2',
fields: [
{
name: 'block2Title',
type: 'text',
},
],
},
],
},
{
type: 'ui',
name: 'ui',
admin: {
components: {
Field: AddCustomBlocks,
},
},
},
],
}

View File

@@ -1,4 +1,5 @@
import type { Page } from '@playwright/test'
import { expect, test } from '@playwright/test'
import path from 'path'
@@ -480,7 +481,7 @@ describe('fields', () => {
test('should add different blocks with similar field configs', async () => {
await page.goto(url.create)
async function addBlock(name: 'Block 1' | 'Block 2') {
async function addBlock(name: 'Block A' | 'Block B') {
await page
.locator('#field-blocksWithSimilarConfigs')
.getByRole('button', { name: 'Add Blocks With Similar Config' })
@@ -488,7 +489,7 @@ describe('fields', () => {
await page.getByRole('button', { name }).click()
}
await addBlock('Block 1')
await addBlock('Block A')
await page
.locator('#blocksWithSimilarConfigs-row-0')
@@ -502,7 +503,7 @@ describe('fields', () => {
page.locator('input[name="blocksWithSimilarConfigs.0.items.0.title"]'),
).toHaveValue('items>0>title')
await addBlock('Block 2')
await addBlock('Block B')
await page
.locator('#blocksWithSimilarConfigs-row-1')
@@ -516,6 +517,38 @@ describe('fields', () => {
page.locator('input[name="blocksWithSimilarConfigs.1.items.0.title2"]'),
).toHaveValue('items>1>title')
})
describe('row manipulation', () => {
describe('react hooks', () => {
test('should add 2 new block rows', async () => {
await page.goto(url.create)
await page
.locator('.custom-blocks-field-management')
.getByRole('button', { name: 'Add Block 1' })
.click()
await expect(
page.locator('#field-customBlocks input[name="customBlocks.0.block1Title"]'),
).toHaveValue('Block 1: Prefilled Title')
await page
.locator('.custom-blocks-field-management')
.getByRole('button', { name: 'Add Block 2' })
.click()
await expect(
page.locator('#field-customBlocks input[name="customBlocks.1.block2Title"]'),
).toHaveValue('Block 2: Prefilled Title')
await page
.locator('.custom-blocks-field-management')
.getByRole('button', { name: 'Replace Block 2' })
.click()
await expect(
page.locator('#field-customBlocks input[name="customBlocks.1.block1Title"]'),
).toHaveValue('REPLACED BLOCK')
})
})
})
})
describe('array', () => {
@@ -643,36 +676,6 @@ describe('fields', () => {
page.locator('#field-potentiallyEmptyArray__0__groupInRow__textInGroupInRow'),
).toHaveValue(`${assertGroupText3} duplicate`)
})
describe('react hooks', () => {
test('should add 2 new block rows', async () => {
await page.goto(url.create)
await page
.locator('.custom-blocks-field-management')
.getByRole('button', { name: 'Add Block 1' })
.click()
await expect(
page.locator('#field-customBlocks input[name="customBlocks.0.block1Title"]'),
).toHaveValue('Block 1: Prefilled Title')
await page
.locator('.custom-blocks-field-management')
.getByRole('button', { name: 'Add Block 2' })
.click()
await expect(
page.locator('#field-customBlocks input[name="customBlocks.1.block2Title"]'),
).toHaveValue('Block 2: Prefilled Title')
await page
.locator('.custom-blocks-field-management')
.getByRole('button', { name: 'Replace Block 2' })
.click()
await expect(
page.locator('#field-customBlocks input[name="customBlocks.1.block1Title"]'),
).toHaveValue('REPLACED BLOCK')
})
})
})
})