test: optimistic form state rows (#12055)

Adds tests for #11961.
This commit is contained in:
Jacob Fletcher
2025-04-08 22:56:24 -04:00
committed by GitHub
parent 97e2e77ff4
commit bd557a97d5
5 changed files with 156 additions and 7 deletions

View File

@@ -0,0 +1,26 @@
import type { Page } from 'playwright'
export async function assertElementStaysVisible(
page: Page,
selector: string,
durationMs: number = 3000,
pollIntervalMs: number = 250,
): Promise<void> {
const start = Date.now()
// Ensure it appears at least once first
await page.waitForSelector(selector, { state: 'visible' })
// Start polling to confirm it stays visible
while (Date.now() - start < durationMs) {
const isVisible = await page.isVisible(selector)
if (!isVisible) {
throw new Error(`Element "${selector}" disappeared during the visibility duration.`)
}
await new Promise((res) => setTimeout(res, pollIntervalMs))
}
console.log(`Element "${selector}" remained visible for ${durationMs}ms.`)
}

View File

@@ -21,7 +21,7 @@ import { expect } from '@playwright/test'
export const assertRequestBody = async <T>(
page: Page,
options: {
action: Promise<void> | void
action: () => Promise<void> | void
expect?: (requestBody: T) => boolean | Promise<boolean>
requestMethod?: string
url: string
@@ -34,7 +34,7 @@ export const assertRequestBody = async <T>(
(request.method() === options.requestMethod || 'POST'),
),
),
await options.action,
await options.action(),
])
const requestBody = request.postData()