test: fix tests that rely on remote urls (#13073)

This commit is contained in:
Jarrod Flesch
2025-07-07 14:02:55 -04:00
committed by GitHub
parent 2650eb7d44
commit 34920a7ec0
7 changed files with 29 additions and 16 deletions

View File

@@ -380,9 +380,12 @@ describe('Block fields', () => {
// Important: do _not_ poll here, use `textContent()` instead of `toHaveText()`
// This will prevent Playwright from polling for the change to the DOM
expect(
await page.locator('#field-blocks #blocks-row-1 .blocks-field__block-header').textContent(),
).toMatch(/^Custom Block Label: Content/)
await expect(async () => {
const text = await page
.locator('#field-blocks #blocks-row-1 .blocks-field__block-header')
.textContent()
expect(text).toMatch(/^Custom Block Label: Content/)
}).toPass()
})
describe('react hooks', () => {

View File

@@ -82,8 +82,6 @@ describe('Upload', () => {
})
test('should upload files from remote URL', async () => {
await uploadImage()
await page.goto(url.create)
const pasteURLButton = page.locator('.file-field__upload button', {
@@ -91,7 +89,8 @@ describe('Upload', () => {
})
await pasteURLButton.click()
const remoteImage = 'https://payloadcms.com/images/og-image.jpg'
const remoteImage =
'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/og-image.jpg'
const inputField = page.locator('.file-field__upload .file-field__remote-file')
await inputField.fill(remoteImage)
@@ -117,14 +116,15 @@ describe('Upload', () => {
})
await pasteURLButton.click()
const remoteImage = 'https://payloadcms.com/images/og-image.jpg'
const remoteImage =
'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/og-image.jpg'
const inputField = page.locator('.file-field__upload .file-field__remote-file')
await inputField.fill(remoteImage)
// Intercept the upload request
await page.route(
'https://payloadcms.com/images/og-image.jpg',
'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/og-image.jpg',
(route) => setTimeout(() => route.continue(), 2000), // Artificial 2-second delay
)
@@ -135,7 +135,9 @@ describe('Upload', () => {
await expect(submitButton).toBeDisabled()
// Wait for the upload to complete
await page.waitForResponse('https://payloadcms.com/images/og-image.jpg')
await page.waitForResponse(
'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/og-image.jpg',
)
// Assert the submit button is re-enabled after upload
await expect(submitButton).toBeEnabled()