test: fix flaky sorting test (#13303)

Ensures the browser uses fresh data after seeding by refreshing the
route and navigating when done.
This commit is contained in:
Jarrod Flesch
2025-07-28 23:25:09 -04:00
committed by GitHub
parent 4fde0f23ce
commit 72349245ca
2 changed files with 16 additions and 1 deletions

View File

@@ -1,12 +1,16 @@
/* eslint-disable no-console */
'use client'
import { useRouter } from 'next/navigation'
export const Seed = () => {
const router = useRouter()
return (
<button
onClick={async () => {
try {
await fetch('/api/seed', { method: 'POST' })
router.refresh()
} catch (error) {
console.error(error)
}

View File

@@ -47,8 +47,19 @@ describe('Sort functionality', () => {
// eslint-disable-next-line playwright/expect-expect
test('Orderable collection', async () => {
const url = new AdminUrlUtil(serverURL, orderableSlug)
await page.goto(`${url.list}?sort=-_order`)
await page.goto(url.list)
const joinFieldResolvePromise = page.waitForResponse(
(response) => response.url().includes('/api/orderable-join') && response.status() === 200,
)
const seedResponsePromise = page.waitForResponse(
(response) => response.url().includes('/api/seed') && response.status() === 200,
)
await page.locator('.collection-list button', { hasText: 'Seed' }).click()
await seedResponsePromise
await joinFieldResolvePromise
await page.goto(`${url.list}?sort=-_order`)
// SORT BY ORDER ASCENDING
await page.locator('.sort-header button').nth(0).click()
await assertRows(0, 'A', 'B', 'C', 'D')