Skip to content

Commit 6f5a1e3

Browse files
authored
test: adds custom pagination e2e tests (#10240)
There is currently no e2e test coverage for custom `admin.pagination.defaultLimit` or `admin.pagination.limits`.
1 parent c01b4bf commit 6f5a1e3

File tree

2 files changed

+57
-24
lines changed

2 files changed

+57
-24
lines changed

test/admin/collections/Posts.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export const Posts: CollectionConfig = {
5050
},
5151
],
5252
},
53+
pagination: {
54+
defaultLimit: 5,
55+
limits: [5, 10, 15],
56+
},
5357
meta: {
5458
description: 'This is a custom meta description for posts',
5559
openGraph: {

test/admin/e2e/list-view/e2e.spec.ts

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ describe('List View', () => {
424424
await deleteAllPosts()
425425

426426
await Promise.all(
427-
Array.from({ length: 12 }, async (_, i) => {
428-
if (i < 6) {
427+
Array.from({ length: 6 }, async (_, i) => {
428+
if (i < 3) {
429429
await createPost()
430430
} else {
431431
await createPost({ title: 'test' })
@@ -437,10 +437,10 @@ describe('List View', () => {
437437

438438
const tableItems = page.locator(tableRowLocator)
439439

440-
await expect(tableItems).toHaveCount(10)
441-
await expect(page.locator('.collection-list__page-info')).toHaveText('1-10 of 12')
442-
await expect(page.locator('.per-page')).toContainText('Per Page: 10')
443-
await page.goto(`${postsUrl.list}?limit=10&page=2`)
440+
await expect(tableItems).toHaveCount(5)
441+
await expect(page.locator('.collection-list__page-info')).toHaveText('1-5 of 6')
442+
await expect(page.locator('.per-page')).toContainText('Per Page: 5')
443+
await page.goto(`${postsUrl.list}?limit=5&page=2`)
444444
await openListFilters(page, {})
445445
await page.locator('.where-builder__add-first-filter').click()
446446
await page.locator('.condition__field .rs__control').click()
@@ -449,7 +449,8 @@ describe('List View', () => {
449449
await page.locator('.condition__operator .rs__control').click()
450450
await options.locator('text=equals').click()
451451
await page.locator('.condition__value input').fill('test')
452-
await expect(page.locator('.collection-list__page-info')).toHaveText('1-6 of 6')
452+
await page.waitForURL(new RegExp(`${postsUrl.list}\\?limit=5&page=1`))
453+
await expect(page.locator('.collection-list__page-info')).toHaveText('1-3 of 3')
453454
})
454455
})
455456

@@ -638,53 +639,81 @@ describe('List View', () => {
638639
})
639640

640641
describe('pagination', () => {
642+
test('should use custom admin.pagination.defaultLimit', async () => {
643+
await deleteAllPosts()
644+
645+
await mapAsync([...Array(6)], async () => {
646+
await createPost()
647+
})
648+
649+
await page.goto(postsUrl.list)
650+
await expect(page.locator('.per-page .per-page__base-button')).toContainText('Per Page: 5')
651+
await expect(page.locator(tableRowLocator)).toHaveCount(5)
652+
})
653+
654+
test('should use custom admin.pagination.limits', async () => {
655+
await deleteAllPosts()
656+
657+
await mapAsync([...Array(6)], async () => {
658+
await createPost()
659+
})
660+
661+
await page.goto(postsUrl.list)
662+
await page.locator('.per-page .popup-button').click()
663+
await page.locator('.per-page .popup-button').click()
664+
const options = await page.locator('.per-page button.per-page__button')
665+
await expect(options).toHaveCount(3)
666+
await expect(options.nth(0)).toContainText('5')
667+
await expect(options.nth(1)).toContainText('10')
668+
await expect(options.nth(2)).toContainText('15')
669+
})
670+
641671
test('should paginate', async () => {
642672
await deleteAllPosts()
643673

644-
await mapAsync([...Array(11)], async () => {
674+
await mapAsync([...Array(6)], async () => {
645675
await createPost()
646676
})
647677

648678
await page.reload()
649-
const tableItems = page.locator(tableRowLocator)
650-
await expect(tableItems).toHaveCount(10)
651-
await expect(page.locator('.collection-list__page-info')).toHaveText('1-10 of 11')
652-
await expect(page.locator('.per-page')).toContainText('Per Page: 10')
679+
await expect(page.locator(tableRowLocator)).toHaveCount(5)
680+
await expect(page.locator('.collection-list__page-info')).toHaveText('1-5 of 6')
681+
await expect(page.locator('.per-page')).toContainText('Per Page: 5')
653682
await page.locator('.paginator button').nth(1).click()
654683
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('page=2')
655-
await expect(tableItems).toHaveCount(1)
684+
await expect(page.locator(tableRowLocator)).toHaveCount(1)
656685
await page.locator('.paginator button').nth(0).click()
657686
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('page=1')
658-
await expect(tableItems).toHaveCount(10)
687+
await expect(page.locator(tableRowLocator)).toHaveCount(5)
659688
})
660689

661-
test('should paginate and maintain perPage', async () => {
690+
test('should paginate without resetting selected limit', async () => {
662691
await deleteAllPosts()
663692

664-
await mapAsync([...Array(26)], async () => {
693+
await mapAsync([...Array(16)], async () => {
665694
await createPost()
666695
})
667696

668697
await page.reload()
669698
const tableItems = page.locator(tableRowLocator)
670-
await expect(tableItems).toHaveCount(10)
671-
await expect(page.locator('.collection-list__page-info')).toHaveText('1-10 of 26')
672-
await expect(page.locator('.per-page')).toContainText('Per Page: 10')
699+
await expect(tableItems).toHaveCount(5)
700+
await expect(page.locator('.collection-list__page-info')).toHaveText('1-5 of 16')
701+
await expect(page.locator('.per-page')).toContainText('Per Page: 5')
673702
await page.locator('.per-page .popup-button').click()
674703

675704
await page
676705
.locator('.per-page button.per-page__button', {
677-
hasText: '25',
706+
hasText: '15',
678707
})
679708
.click()
680709

681-
await expect(tableItems).toHaveCount(25)
682-
await expect(page.locator('.per-page .per-page__base-button')).toContainText('Per Page: 25')
710+
await expect(tableItems).toHaveCount(15)
711+
await expect(page.locator('.per-page .per-page__base-button')).toContainText('Per Page: 15')
683712
await page.locator('.paginator button').nth(1).click()
684713
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('page=2')
685714
await expect(tableItems).toHaveCount(1)
686-
await expect(page.locator('.per-page')).toContainText('Per Page: 25')
687-
await expect(page.locator('.collection-list__page-info')).toHaveText('26-26 of 26')
715+
await expect(page.locator('.per-page')).toContainText('Per Page: 15') // ensure this hasn't changed
716+
await expect(page.locator('.collection-list__page-info')).toHaveText('16-16 of 16')
688717
})
689718
})
690719

0 commit comments

Comments
 (0)