diff --git a/test/helpers.ts b/test/helpers.ts index 830c7e8c6b..10cb70565a 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -1,4 +1,4 @@ -import type { Locator, Page } from '@playwright/test' +import type { BrowserContext, Locator, Page } from '@playwright/test' import { expect } from '@playwright/test' import { wait } from 'payload/utilities' @@ -16,6 +16,43 @@ type LoginArgs = { serverURL: string } +const networkConditions = { + 'Slow 3G': { + download: ((500 * 1000) / 8) * 0.8, + upload: ((500 * 1000) / 8) * 0.8, + latency: 400 * 5, + }, + 'Fast 3G': { + download: ((1.6 * 1000 * 1000) / 8) * 0.9, + upload: ((750 * 1000) / 8) * 0.9, + latency: 150 * 3.75, + }, + 'Slow 4G': { + download: ((4 * 1000 * 1000) / 8) * 0.8, + upload: ((3 * 1000 * 1000) / 8) * 0.8, + latency: 20 * 3.75, + }, +} + +export async function delayNetwork({ + context, + page, + delay, +}: { + context: BrowserContext + delay: 'Fast 3G' | 'Slow 3G' | 'Slow 4G' + page: Page +}): Promise { + const cdpSession = await context.newCDPSession(page) + + await cdpSession.send('Network.emulateNetworkConditions', { + downloadThroughput: networkConditions[delay].download, + uploadThroughput: networkConditions[delay].upload, + latency: networkConditions[delay].latency, + offline: false, + }) +} + export async function firstRegister(args: FirstRegisterArgs): Promise { const { page, serverURL } = args @@ -109,7 +146,7 @@ export const checkBreadcrumb = async (page: Page, text: string) => export const selectTableRow = async (page: Page, title: string): Promise => { const selector = `tbody tr:has-text("${title}") .select-row__checkbox input[type=checkbox]` await page.locator(selector).check() - expect(await page.locator(selector).isChecked()).toBe(true) + await expect(page.locator(selector)).toBeChecked() } export const findTableCell = (page: Page, fieldName: string, rowTitle?: string): Locator => {