Skip to content

Commit 3258e78

Browse files
authored
test: group-by reset and navigation tests in trash view (#13401)
### What? Adds e2e tests that verify group-by functionality within the trash view of a collection. ### Why? To ensure group-by behaves correctly when viewing soft-deleted documents, including: - Clearing the group-by selection via the reset button. - Navigating from grouped rows to the trashed document's edit view. ### How? - Added `should properly clear group-by in trash view` to test the reset button behavior. - Added `should properly navigate to trashed doc edit view from group-by in trash view` to confirm correct linking and routing.
1 parent ad2564e commit 3258e78

File tree

1 file changed

+68
-31
lines changed

1 file changed

+68
-31
lines changed

test/group-by/e2e.spec.ts

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { reInitializeDB } from 'helpers/reInitializeDB.js'
1414
import * as path from 'path'
1515
import { fileURLToPath } from 'url'
1616

17-
import type { Config } from './payload-types.js'
17+
import type { Config, Post } from './payload-types.js'
1818

1919
import {
2020
ensureCompilationIsDone,
@@ -38,7 +38,6 @@ test.describe('Group By', () => {
3838
let serverURL: string
3939
let payload: PayloadTestSDK<Config>
4040
let user: any
41-
let category1Id: number | string
4241

4342
test.beforeAll(async ({ browser }, testInfo) => {
4443
testInfo.setTimeout(TEST_TIMEOUT_LONG)
@@ -695,42 +694,80 @@ test.describe('Group By', () => {
695694
).toHaveCount(0)
696695
})
697696

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)
700700

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
704704

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()
709709

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')
713713

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()
716716

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+
)
722722

723-
// Go to the trash view
724-
await page.locator('#trash-view-pill').click()
725-
await expect(page).toHaveURL(/\/posts\/trash(\?|$)/)
723+
// Go to the trash view
724+
await page.locator('#trash-view-pill').click()
725+
await expect(page).toHaveURL(/\/posts\/trash(\?|$)/)
726726

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)
730730

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(/\/posts\/trash\/\d+/)
761+
})
735762
})
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+
}
736773
})

0 commit comments

Comments
 (0)