@@ -14,7 +14,7 @@ import { reInitializeDB } from 'helpers/reInitializeDB.js'
14
14
import * as path from 'path'
15
15
import { fileURLToPath } from 'url'
16
16
17
- import type { Config } from './payload-types.js'
17
+ import type { Config , Post } from './payload-types.js'
18
18
19
19
import {
20
20
ensureCompilationIsDone ,
@@ -38,7 +38,6 @@ test.describe('Group By', () => {
38
38
let serverURL : string
39
39
let payload : PayloadTestSDK < Config >
40
40
let user : any
41
- let category1Id : number | string
42
41
43
42
test . beforeAll ( async ( { browser } , testInfo ) => {
44
43
testInfo . setTimeout ( TEST_TIMEOUT_LONG )
@@ -695,42 +694,80 @@ test.describe('Group By', () => {
695
694
) . toHaveCount ( 0 )
696
695
} )
697
696
698
- test ( 'should show trashed docs in trash view when group-by is active' , async ( ) => {
699
- await page . goto ( url . list )
697
+ test . describe ( 'Trash' , ( ) => {
698
+ test ( 'should show trashed docs in trash view when group-by is active' , async ( ) => {
699
+ await page . goto ( url . list )
700
700
701
- // Enable group-by on Category
702
- await addGroupBy ( page , { fieldLabel : 'Category' , fieldPath : 'category' } )
703
- await expect ( page . locator ( '.table-wrap' ) ) . toHaveCount ( 2 ) // We expect 2 groups initially
701
+ // Enable group-by on Category
702
+ await addGroupBy ( page , { fieldLabel : 'Category' , fieldPath : 'category' } )
703
+ await expect ( page . locator ( '.table-wrap' ) ) . toHaveCount ( 2 ) // We expect 2 groups initially
704
704
705
- // Trash the first document in the first group
706
- const firstTable = page . locator ( '.table-wrap' ) . first ( )
707
- await firstTable . locator ( '.row-1 .cell-_select input' ) . check ( )
708
- await firstTable . locator ( '.list-selection__button[aria-label="Delete"]' ) . click ( )
705
+ // Trash the first document in the first group
706
+ const firstTable = page . locator ( '.table-wrap' ) . first ( )
707
+ await firstTable . locator ( '.row-1 .cell-_select input' ) . check ( )
708
+ await firstTable . locator ( '.list-selection__button[aria-label="Delete"]' ) . click ( )
709
709
710
- const firstGroupID = await firstTable
711
- . locator ( '.group-by-header__heading' )
712
- . getAttribute ( 'data-group-id' )
710
+ const firstGroupID = await firstTable
711
+ . locator ( '.group-by-header__heading' )
712
+ . getAttribute ( 'data-group-id' )
713
713
714
- const modalId = `[id^="${ firstGroupID } -confirm-delete-many-docs"]`
715
- await expect ( page . locator ( modalId ) ) . toBeVisible ( )
714
+ const modalId = `[id^="${ firstGroupID } -confirm-delete-many-docs"]`
715
+ await expect ( page . locator ( modalId ) ) . toBeVisible ( )
716
716
717
- // Confirm trash (skip permanent delete)
718
- await page . locator ( `${ modalId } #confirm-action` ) . click ( )
719
- await expect ( page . locator ( '.payload-toast-container .toast-success' ) ) . toHaveText (
720
- '1 Post moved to trash.' ,
721
- )
717
+ // Confirm trash (skip permanent delete)
718
+ await page . locator ( `${ modalId } #confirm-action` ) . click ( )
719
+ await expect ( page . locator ( '.payload-toast-container .toast-success' ) ) . toHaveText (
720
+ '1 Post moved to trash.' ,
721
+ )
722
722
723
- // Go to the trash view
724
- await page . locator ( '#trash-view-pill' ) . click ( )
725
- await expect ( page ) . toHaveURL ( / \/ p o s t s \/ t r a s h ( \? | $ ) / )
723
+ // Go to the trash view
724
+ await page . locator ( '#trash-view-pill' ) . click ( )
725
+ await expect ( page ) . toHaveURL ( / \/ p o s t s \/ t r a s h ( \? | $ ) / )
726
726
727
- // Re-enable group-by on Category in trash view
728
- await addGroupBy ( page , { fieldLabel : 'Category' , fieldPath : 'category' } )
729
- await expect ( page . locator ( '.table-wrap' ) ) . toHaveCount ( 1 ) // Should only have Category 1 (or the trashed doc's category)
727
+ // Re-enable group-by on Category in trash view
728
+ await addGroupBy ( page , { fieldLabel : 'Category' , fieldPath : 'category' } )
729
+ await expect ( page . locator ( '.table-wrap' ) ) . toHaveCount ( 1 ) // Should only have Category 1 (or the trashed doc's category)
730
730
731
- // Ensure the trashed doc is visible
732
- await expect (
733
- page . locator ( '.table-wrap tbody tr td.cell-title' , { hasText : 'Find me' } ) ,
734
- ) . toBeVisible ( )
731
+ // Ensure the trashed doc is visible
732
+ await expect (
733
+ page . locator ( '.table-wrap tbody tr td.cell-title' , { hasText : 'Find me' } ) ,
734
+ ) . toBeVisible ( )
735
+ } )
736
+
737
+ test ( 'should properly clear group-by in trash view' , async ( ) => {
738
+ await createTrashedPostDoc ( { title : 'Trashed Post 1' } )
739
+ await page . goto ( url . trash )
740
+
741
+ // Enable group-by on Title
742
+ await addGroupBy ( page , { fieldLabel : 'Title' , fieldPath : 'title' } )
743
+ await expect ( page . locator ( '.table-wrap' ) ) . toHaveCount ( 1 )
744
+ await expect ( page . locator ( '.group-by-header' ) ) . toHaveText ( 'Trashed Post 1' )
745
+
746
+ await page . locator ( '#group-by--reset' ) . click ( )
747
+ await expect ( page . locator ( '.group-by-header' ) ) . toBeHidden ( )
748
+ } )
749
+
750
+ test ( 'should properly navigate to trashed doc edit view from group-by in trash view' , async ( ) => {
751
+ await createTrashedPostDoc ( { title : 'Trashed Post 1' } )
752
+ await page . goto ( url . trash )
753
+
754
+ // Enable group-by on Title
755
+ await addGroupBy ( page , { fieldLabel : 'Title' , fieldPath : 'title' } )
756
+ await expect ( page . locator ( '.table-wrap' ) ) . toHaveCount ( 1 )
757
+ await expect ( page . locator ( '.group-by-header' ) ) . toHaveText ( 'Trashed Post 1' )
758
+
759
+ await page . locator ( '.table-wrap tbody tr td.cell-title a' ) . click ( )
760
+ await expect ( page ) . toHaveURL ( / \/ p o s t s \/ t r a s h \/ \d + / )
761
+ } )
735
762
} )
763
+
764
+ async function createTrashedPostDoc ( data : Partial < Post > ) : Promise < Post > {
765
+ return payload . create ( {
766
+ collection : postsSlug ,
767
+ data : {
768
+ ...data ,
769
+ deletedAt : new Date ( ) . toISOString ( ) , // Set the post as trashed
770
+ } ,
771
+ } ) as unknown as Promise < Post >
772
+ }
736
773
} )
0 commit comments