@@ -5,6 +5,7 @@ import { expect, test } from '@playwright/test'
5
5
import { assertToastErrors } from 'helpers/assertToastErrors.js'
6
6
import { copyPasteField } from 'helpers/e2e/copyPasteField.js'
7
7
import { addArrayRow , duplicateArrayRow , removeArrayRow } from 'helpers/e2e/fields/array/index.js'
8
+ import { scrollEntirePage } from 'helpers/e2e/scrollEntirePage.js'
8
9
import { toggleBlockOrArrayRow } from 'helpers/e2e/toggleCollapsible.js'
9
10
import path from 'path'
10
11
import { wait } from 'payload/shared'
@@ -191,76 +192,136 @@ describe('Array', () => {
191
192
} )
192
193
193
194
describe ( 'row manipulation' , ( ) => {
194
- test ( 'should add, remove and duplicate rows' , async ( ) => {
195
- const assertText0 = 'array row 1'
196
- const assertGroupText0 = 'text in group in row 1'
197
- const assertText1 = 'array row 2'
198
- const assertText3 = 'array row 3'
199
- const assertGroupText3 = 'text in group in row 3'
195
+ test ( 'should add rows' , async ( ) => {
196
+ const row1Text = 'Array row 1'
197
+ const row2Text = 'Array row 2'
198
+ const row3Text = 'Array row 3'
199
+
200
+ const row1GroupText = 'text in group in row 1'
201
+
200
202
await loadCreatePage ( )
201
- await page . mouse . wheel ( 0 , 1750 )
202
- await page . locator ( '#field-potentiallyEmptyArray' ) . scrollIntoViewIfNeeded ( )
203
- await wait ( 300 )
203
+ await scrollEntirePage ( page )
204
204
205
- // Add 3 rows
206
205
await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
207
206
await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
208
207
await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
209
208
210
- // Fill out row 1
211
- await page . locator ( '#field-potentiallyEmptyArray__0__text' ) . fill ( assertText0 )
209
+ await page . locator ( '#field-potentiallyEmptyArray__0__text' ) . fill ( row1Text )
210
+ await page . locator ( '#field-potentiallyEmptyArray__1__text' ) . fill ( row2Text )
211
+ await page . locator ( '#field-potentiallyEmptyArray__2__text' ) . fill ( row3Text )
212
212
213
- await page
214
- . locator ( '#field-potentiallyEmptyArray__0__groupInRow__textInGroupInRow' )
215
- . fill ( assertGroupText0 )
213
+ await page . locator ( '#field-potentiallyEmptyArray__0__group__text' ) . fill ( row1GroupText )
214
+
215
+ await saveDocAndAssert ( page )
216
+ await scrollEntirePage ( page )
216
217
217
- // Fill out row 2
218
- await page . locator ( '#field-potentiallyEmptyArray__1__text' ) . fill ( assertText1 )
218
+ await expect ( page . locator ( '#field-potentiallyEmptyArray__0__text' ) ) . toHaveValue ( row1Text )
219
+ await expect ( page . locator ( '#field-potentiallyEmptyArray__1__text' ) ) . toHaveValue ( row2Text )
220
+ await expect ( page . locator ( '#field-potentiallyEmptyArray__2__text' ) ) . toHaveValue ( row3Text )
219
221
220
- // Fill out row 3
221
- await page . locator ( '#field-potentiallyEmptyArray__2__text' ) . fill ( assertText3 )
222
+ const input = page . locator ( '#field-potentiallyEmptyArray__0__group__text' )
222
223
224
+ await expect ( input ) . toHaveValue ( row1GroupText )
225
+ } )
226
+
227
+ test ( 'should duplicate rows' , async ( ) => {
228
+ const row1Text = 'Array row 1'
229
+ const row2Text = 'Array row 2'
230
+ const row3Text = 'Array row 3'
231
+
232
+ await loadCreatePage ( )
233
+ await scrollEntirePage ( page )
234
+
235
+ await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
236
+ await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
237
+ await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
238
+
239
+ await page . locator ( '#field-potentiallyEmptyArray__0__text' ) . fill ( row1Text )
240
+ await page . locator ( '#field-potentiallyEmptyArray__1__text' ) . fill ( row2Text )
241
+ await page . locator ( '#field-potentiallyEmptyArray__2__text' ) . fill ( row3Text )
242
+
243
+ await page . locator ( '#field-potentiallyEmptyArray__0__text' ) . fill ( row1Text )
244
+
245
+ // Mark the first row with some unique values to assert against later
223
246
await page
224
- . locator ( '#field-potentiallyEmptyArray__2__groupInRow__textInGroupInRow ' )
225
- . fill ( assertGroupText3 )
247
+ . locator ( '#field-potentiallyEmptyArray__0__group__text ' )
248
+ . fill ( ` ${ row1Text } duplicate` )
226
249
227
- await removeArrayRow ( page , { fieldName : 'potentiallyEmptyArray' , rowIndex : 1 } )
228
- await removeArrayRow ( page , { fieldName : 'potentiallyEmptyArray' , rowIndex : 0 } )
250
+ await duplicateArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
229
251
230
- // Save document
231
252
await saveDocAndAssert ( page )
253
+ await scrollEntirePage ( page )
254
+
255
+ await page . locator ( '#field-potentiallyEmptyArray__0__text' ) . fill ( row1Text )
256
+ await page . locator ( '#field-potentiallyEmptyArray__1__text' ) . fill ( row1Text )
257
+ await page . locator ( '#field-potentiallyEmptyArray__2__text' ) . fill ( row2Text )
258
+ await page . locator ( '#field-potentiallyEmptyArray__3__text' ) . fill ( row3Text )
259
+
260
+ await expect ( page . locator ( '#field-potentiallyEmptyArray__1__group__text' ) ) . toHaveValue (
261
+ `${ row1Text } duplicate` ,
262
+ )
263
+ } )
264
+
265
+ test ( 'should duplicate rows with nested arrays' , async ( ) => {
266
+ await loadCreatePage ( )
267
+ await scrollEntirePage ( page )
268
+
269
+ await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
270
+ await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray__0__array' } )
271
+
272
+ await page . locator ( '#field-potentiallyEmptyArray__0__array__0__text' ) . fill ( 'Row 1' )
232
273
233
- // Scroll to array row (fields are not rendered in DOM until on screen)
234
- await page . locator ( '#field-potentiallyEmptyArray__0__groupInRow' ) . scrollIntoViewIfNeeded ( )
274
+ // There should be 2 fields in the nested array row: the text field and the row id
275
+ const fieldsInRow = page
276
+ . locator ( '#field-potentiallyEmptyArray__0__array' )
277
+ . locator ( '.render-fields' )
278
+ . first ( )
235
279
236
- // Expect the remaining row to be the third row
237
- const input = page . locator ( '#field-potentiallyEmptyArray__0__groupInRow__textInGroupInRow' )
238
- await expect ( input ) . toHaveValue ( assertGroupText3 )
280
+ await expect ( fieldsInRow . locator ( '> *' ) ) . toHaveCount ( 2 )
239
281
240
282
await duplicateArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
241
283
242
- // Update duplicated row group field text
243
- await page
244
- . locator ( '#field-potentiallyEmptyArray__1__groupInRow__textInGroupInRow' )
245
- . fill ( `${ assertGroupText3 } duplicate` )
284
+ // There should still only be 2 fields in the duplicated row
285
+ const fieldsInDuplicatedRow = page
286
+ . locator ( '#field-potentiallyEmptyArray__1__array' )
287
+ . locator ( '.render-fields' )
288
+ . first ( )
246
289
247
- // Save document
248
- await saveDocAndAssert ( page )
290
+ await expect ( fieldsInDuplicatedRow . locator ( '> *' ) ) . toHaveCount ( 2 )
291
+ } )
249
292
250
- // Expect the second row to be a duplicate of the remaining row
251
- await expect (
252
- page . locator ( '#field-potentiallyEmptyArray__1__groupInRow__textInGroupInRow' ) ,
253
- ) . toHaveValue ( ` ${ assertGroupText3 } duplicate` )
293
+ test ( 'should remove rows' , async ( ) => {
294
+ const row1Text = 'Array row 1'
295
+ const row2Text = 'Array row 2'
296
+ const row3Text = 'Array row 3'
254
297
298
+ const assertGroupText3 = 'text in group in row 3'
299
+
300
+ await loadCreatePage ( )
301
+ await scrollEntirePage ( page )
302
+
303
+ await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
304
+ await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
305
+ await addArrayRow ( page , { fieldName : 'potentiallyEmptyArray' } )
306
+
307
+ await page . locator ( '#field-potentiallyEmptyArray__0__text' ) . fill ( row1Text )
308
+ await page . locator ( '#field-potentiallyEmptyArray__1__text' ) . fill ( row2Text )
309
+ await page . locator ( '#field-potentiallyEmptyArray__2__text' ) . fill ( row3Text )
310
+
311
+ // Mark the third row with some unique values to assert against later
312
+ await page . locator ( '#field-potentiallyEmptyArray__2__group__text' ) . fill ( assertGroupText3 )
313
+
314
+ // Remove all rows one by one, except the last one
315
+ await removeArrayRow ( page , { fieldName : 'potentiallyEmptyArray' , rowIndex : 1 } )
255
316
await removeArrayRow ( page , { fieldName : 'potentiallyEmptyArray' , rowIndex : 0 } )
256
317
257
- // Save document
258
318
await saveDocAndAssert ( page )
319
+ await scrollEntirePage ( page )
259
320
260
- // Expect the remaining row to be the copy of the duplicate row
261
- await expect (
262
- page . locator ( '#field-potentiallyEmptyArray__0__groupInRow__textInGroupInRow' ) ,
263
- ) . toHaveValue ( ` ${ assertGroupText3 } duplicate` )
321
+ // Expect the remaining row to be the third row, now first
322
+ await expect ( page . locator ( '#field-potentiallyEmptyArray__0__group__text' ) ) . toHaveValue (
323
+ assertGroupText3 ,
324
+ )
264
325
} )
265
326
} )
266
327
0 commit comments