@@ -43,6 +43,7 @@ import type { PayloadTestSDK } from '../../../helpers/sdk/index.js'
43
43
import { reorderColumns } from '../../../helpers/e2e/reorderColumns.js'
44
44
import { reInitializeDB } from '../../../helpers/reInitializeDB.js'
45
45
import { POLL_TOPASS_TIMEOUT , TEST_TIMEOUT_LONG } from '../../../playwright.config.js'
46
+ import { addListFilter } from 'helpers/e2e/addListFilter.js'
46
47
const filename = fileURLToPath ( import . meta. url )
47
48
const currentFolder = path . dirname ( filename )
48
49
const dirname = path . resolve ( currentFolder , '../../' )
@@ -311,27 +312,12 @@ describe('List View', () => {
311
312
312
313
await expect ( page . locator ( tableRowLocator ) ) . toHaveCount ( 2 )
313
314
314
- await openListFilters ( page , { } )
315
-
316
- await page . locator ( '.where-builder__add-first-filter' ) . click ( )
317
-
318
- const conditionField = page . locator ( '.condition__field' )
319
- await conditionField . click ( )
320
- const dropdownFieldOption = conditionField . locator ( '.rs__option' , {
321
- hasText : exactText ( 'ID' ) ,
315
+ await addListFilter ( {
316
+ page,
317
+ fieldLabel : 'ID' ,
318
+ operatorLabel : 'equals' ,
319
+ value : id ,
322
320
} )
323
- await dropdownFieldOption . click ( )
324
- await expect ( page . locator ( '.condition__field' ) ) . toContainText ( 'ID' )
325
-
326
- const operatorField = page . locator ( '.condition__operator' )
327
- const valueField = page . locator ( '.condition__value input' )
328
-
329
- await operatorField . click ( )
330
-
331
- const dropdownOptions = operatorField . locator ( '.rs__option' )
332
- await dropdownOptions . locator ( 'text=equals' ) . click ( )
333
-
334
- await valueField . fill ( id )
335
321
336
322
const tableRows = page . locator ( tableRowLocator )
337
323
@@ -347,20 +333,12 @@ describe('List View', () => {
347
333
test ( 'should reset filter value and operator on field update' , async ( ) => {
348
334
const id = ( await page . locator ( '.cell-id' ) . first ( ) . innerText ( ) ) . replace ( 'ID: ' , '' )
349
335
350
- // open the column controls
351
- await page . locator ( '.list-controls__toggle-columns' ) . click ( )
352
- await openListFilters ( page , { } )
353
- await page . locator ( '.where-builder__add-first-filter' ) . click ( )
354
-
355
- const operatorField = page . locator ( '.condition__operator' )
356
- await operatorField . click ( )
357
-
358
- const dropdownOperatorOptions = operatorField . locator ( '.rs__option' )
359
- await dropdownOperatorOptions . locator ( 'text=equals' ) . click ( )
360
-
361
- // execute filter (where ID equals id value)
362
- const valueField = page . locator ( '.condition__value > input' )
363
- await valueField . fill ( id )
336
+ await addListFilter ( {
337
+ page,
338
+ fieldLabel : 'ID' ,
339
+ operatorLabel : 'equals' ,
340
+ value : id ,
341
+ } )
364
342
365
343
const filterField = page . locator ( '.condition__field' )
366
344
await filterField . click ( )
@@ -373,6 +351,7 @@ describe('List View', () => {
373
351
await expect ( filterField ) . toContainText ( 'Status' )
374
352
375
353
// expect operator & value field to reset (be empty)
354
+ const operatorField = page . locator ( '.condition__operator' )
376
355
await expect ( operatorField . locator ( '.rs__placeholder' ) ) . toContainText ( 'Select a value' )
377
356
await expect ( page . locator ( '.condition__value input' ) ) . toHaveValue ( '' )
378
357
} )
@@ -490,21 +469,22 @@ describe('List View', () => {
490
469
await expect ( page . locator ( '.collection-list__page-info' ) ) . toHaveText ( '1-5 of 6' )
491
470
await expect ( page . locator ( '.per-page' ) ) . toContainText ( 'Per Page: 5' )
492
471
await page . goto ( `${ postsUrl . list } ?limit=5&page=2` )
493
- await openListFilters ( page , { } )
494
- await page . locator ( '.where-builder__add-first-filter' ) . click ( )
495
- await page . locator ( '.condition__field .rs__control' ) . click ( )
496
- const options = page . locator ( '.rs__option' )
497
- await options . locator ( 'text=Tab 1 > Title' ) . click ( )
498
- await page . locator ( '.condition__operator .rs__control' ) . click ( )
499
- await options . locator ( 'text=equals' ) . click ( )
500
- await page . locator ( '.condition__value input' ) . fill ( 'test' )
472
+
473
+ await addListFilter ( {
474
+ page ,
475
+ fieldLabel : 'Tab 1 > Title' ,
476
+ operatorLabel : 'equals' ,
477
+ value : 'test' ,
478
+ } )
479
+
501
480
await page . waitForURL ( new RegExp ( `${ postsUrl . list } \\?limit=5&page=1` ) )
502
481
await expect ( page . locator ( '.collection-list__page-info' ) ) . toHaveText ( '1-3 of 3' )
503
482
} )
504
483
505
484
test ( 'should reset filter values for every additional filters' , async ( ) => {
506
485
await page . goto ( postsUrl . list )
507
486
await openListFilters ( page , { } )
487
+
508
488
await page . locator ( '.where-builder__add-first-filter' ) . click ( )
509
489
const firstConditionField = page . locator ( '.condition__field' )
510
490
const firstOperatorField = page . locator ( '.condition__operator' )
@@ -536,48 +516,36 @@ describe('List View', () => {
536
516
537
517
test ( 'should not re-render page upon typing in a value in the filter value field' , async ( ) => {
538
518
await page . goto ( postsUrl . list )
539
- await openListFilters ( page , { } )
540
- await page . locator ( '.where-builder__add-first-filter' ) . click ( )
541
- const firstConditionField = page . locator ( '.condition__field' )
542
- const firstOperatorField = page . locator ( '.condition__operator' )
543
- const firstValueField = page . locator ( '.condition__value >> input' )
544
519
545
- await firstConditionField . click ( )
546
- await firstConditionField
547
- . locator ( '.rs__option' , { hasText : exactText ( 'Tab 1 > Title' ) } )
548
- . click ( )
549
- await expect ( firstConditionField . locator ( '.rs__single-value' ) ) . toContainText ( 'Tab 1 > Title' )
520
+ await addListFilter ( {
521
+ page,
522
+ fieldLabel : 'Tab 1 > Title' ,
523
+ operatorLabel : 'equals' ,
524
+ skipValueInput : true ,
525
+ } )
550
526
551
- await firstOperatorField . click ( )
552
- await firstOperatorField . locator ( '.rs__option' ) . locator ( 'text=equals' ) . click ( )
527
+ const valueInput = page . locator ( '.condition__value >> input' )
553
528
554
529
// Type into the input field instead of filling it
555
- await firstValueField . click ( )
556
- await firstValueField . type ( 'Test' , { delay : 100 } ) // Add a delay to simulate typing speed
530
+ await valueInput . click ( )
531
+ await valueInput . type ( 'Test' , { delay : 100 } ) // Add a delay to simulate typing speed
557
532
558
533
// Wait for a short period to see if the input loses focus
559
534
await page . waitForTimeout ( 500 )
560
535
561
536
// Check if the input still has the correct value
562
- await expect ( firstValueField ) . toHaveValue ( 'Test' )
537
+ await expect ( valueInput ) . toHaveValue ( 'Test' )
563
538
} )
564
539
565
540
test ( 'should still show second filter if two filters exist and first filter is removed' , async ( ) => {
566
541
await page . goto ( postsUrl . list )
567
- await openListFilters ( page , { } )
568
- await page . locator ( '.where-builder__add-first-filter' ) . click ( )
569
- const firstConditionField = page . locator ( '.condition__field' )
570
- const firstOperatorField = page . locator ( '.condition__operator' )
571
- const firstValueField = page . locator ( '.condition__value >> input' )
572
- await firstConditionField . click ( )
573
- await firstConditionField
574
- . locator ( '.rs__option' , { hasText : exactText ( 'Tab 1 > Title' ) } )
575
- . click ( )
576
- await expect ( firstConditionField . locator ( '.rs__single-value' ) ) . toContainText ( 'Tab 1 > Title' )
577
- await firstOperatorField . click ( )
578
- await firstOperatorField . locator ( '.rs__option' ) . locator ( 'text=equals' ) . click ( )
579
- await firstValueField . fill ( 'Test 1' )
580
- await expect ( firstValueField ) . toHaveValue ( 'Test 1' )
542
+
543
+ await addListFilter ( {
544
+ page,
545
+ fieldLabel : 'Tab 1 > Title' ,
546
+ operatorLabel : 'equals' ,
547
+ value : 'Test 1' ,
548
+ } )
581
549
582
550
await wait ( 500 )
583
551
@@ -609,6 +577,7 @@ describe('List View', () => {
609
577
await removeButton . click ( )
610
578
const filterListItems = page . locator ( '.where-builder__and-filters li' )
611
579
await expect ( filterListItems ) . toHaveCount ( 1 )
580
+ const firstValueField = page . locator ( '.condition__value >> input' )
612
581
await expect ( firstValueField ) . toHaveValue ( 'Test 2' )
613
582
} )
614
583
@@ -647,8 +616,6 @@ describe('List View', () => {
647
616
) } `,
648
617
)
649
618
650
- console . log ( 'URL' , page . url ( ) )
651
-
652
619
await openListFilters ( page , { } )
653
620
654
621
const condition = page . locator ( '.condition__field' )
@@ -1150,23 +1117,22 @@ describe('List View', () => {
1150
1117
test ( 'should display translated field titles' , async ( ) => {
1151
1118
await createPost ( )
1152
1119
1153
- // column controls
1154
1120
await page . locator ( '.list-controls__toggle-columns' ) . click ( )
1121
+
1155
1122
await expect (
1156
1123
page . locator ( '.column-selector__column' , {
1157
1124
hasText : exactText ( 'Title' ) ,
1158
1125
} ) ,
1159
1126
) . toHaveText ( 'Title' )
1160
1127
1161
- // filters
1162
1128
await openListFilters ( page , { } )
1129
+
1163
1130
await page . locator ( '.where-builder__add-first-filter' ) . click ( )
1164
1131
await page . locator ( '.condition__field .rs__control' ) . click ( )
1165
1132
const options = page . locator ( '.rs__option' )
1166
1133
1167
1134
await expect ( options . locator ( 'text=Tab 1 > Title' ) ) . toHaveText ( 'Tab 1 > Title' )
1168
1135
1169
- // list columns
1170
1136
await expect ( page . locator ( '#heading-title .sort-column__label' ) ) . toHaveText ( 'Title' )
1171
1137
await expect ( page . locator ( '.search-filter input' ) ) . toHaveAttribute ( 'placeholder' , / ( T i t l e ) / )
1172
1138
} )
0 commit comments