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

@@ -18,6 +18,7 @@ export const UploadCollection: CollectionConfig = {
height: 100, height: 100,
}, },
], ],
adminThumbnail: () => 'https://payloadcms.com/images/universal-truth.jpg', adminThumbnail: () =>
'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/universal-truth.jpg',
}, },
} }

View File

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

View File

@@ -82,8 +82,6 @@ describe('Upload', () => {
}) })
test('should upload files from remote URL', async () => { test('should upload files from remote URL', async () => {
await uploadImage()
await page.goto(url.create) await page.goto(url.create)
const pasteURLButton = page.locator('.file-field__upload button', { const pasteURLButton = page.locator('.file-field__upload button', {
@@ -91,7 +89,8 @@ describe('Upload', () => {
}) })
await pasteURLButton.click() 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') const inputField = page.locator('.file-field__upload .file-field__remote-file')
await inputField.fill(remoteImage) await inputField.fill(remoteImage)
@@ -117,14 +116,15 @@ describe('Upload', () => {
}) })
await pasteURLButton.click() 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') const inputField = page.locator('.file-field__upload .file-field__remote-file')
await inputField.fill(remoteImage) await inputField.fill(remoteImage)
// Intercept the upload request // Intercept the upload request
await page.route( 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 (route) => setTimeout(() => route.continue(), 2000), // Artificial 2-second delay
) )
@@ -135,7 +135,9 @@ describe('Upload', () => {
await expect(submitButton).toBeDisabled() await expect(submitButton).toBeDisabled()
// Wait for the upload to complete // 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 // Assert the submit button is re-enabled after upload
await expect(submitButton).toBeEnabled() await expect(submitButton).toBeEnabled()

View File

@@ -55,7 +55,9 @@ describe('Lexical Fully Featured', () => {
await lexical.drawer.getByText('Paste URL').click() await lexical.drawer.getByText('Paste URL').click()
await lexical.drawer await lexical.drawer
.locator('.file-field__remote-file') .locator('.file-field__remote-file')
.fill('https://payloadcms.com/images/universal-truth.jpg') .fill(
'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/universal-truth.jpg',
)
await lexical.drawer.getByText('Add file').click() await lexical.drawer.getByText('Add file').click()
await lexical.save('drawer') await lexical.save('drawer')
await expect(lexical.decorator).toHaveCount(3) await expect(lexical.decorator).toHaveCount(3)

View File

@@ -11,7 +11,8 @@ export const AdminThumbnailFunction: CollectionConfig = {
slug: adminThumbnailFunctionSlug, slug: adminThumbnailFunctionSlug,
upload: { upload: {
staticDir: path.resolve(dirname, 'test/uploads/media'), staticDir: path.resolve(dirname, 'test/uploads/media'),
adminThumbnail: () => 'https://payloadcms.com/images/universal-truth.jpg', adminThumbnail: () =>
'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/universal-truth.jpg',
}, },
fields: [], fields: [],
} }

View File

@@ -6,14 +6,18 @@ export const UploadControl = () => {
const { setUploadControlFile, setUploadControlFileUrl } = useUploadControls() const { setUploadControlFile, setUploadControlFileUrl } = useUploadControls()
const loadFromFile = useCallback(async () => { const loadFromFile = useCallback(async () => {
const response = await fetch('https://payloadcms.com/images/universal-truth.jpg') const response = await fetch(
'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/universal-truth.jpg',
)
const blob = await response.blob() const blob = await response.blob()
const file = new File([blob], 'universal-truth.jpg', { type: 'image/jpeg' }) const file = new File([blob], 'universal-truth.jpg', { type: 'image/jpeg' })
setUploadControlFile(file) setUploadControlFile(file)
}, [setUploadControlFile]) }, [setUploadControlFile])
const loadFromUrl = useCallback(() => { const loadFromUrl = useCallback(() => {
setUploadControlFileUrl('https://payloadcms.com/images/universal-truth.jpg') setUploadControlFileUrl(
'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/universal-truth.jpg',
)
}, [setUploadControlFileUrl]) }, [setUploadControlFileUrl])
return ( return (

View File

@@ -583,7 +583,7 @@ describe('Uploads', () => {
const genericUploadImage = page.locator('tr.row-1 .thumbnail img') const genericUploadImage = page.locator('tr.row-1 .thumbnail img')
await expect(genericUploadImage).toHaveAttribute( await expect(genericUploadImage).toHaveAttribute(
'src', 'src',
'https://payloadcms.com/images/universal-truth.jpg', 'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/universal-truth.jpg',
) )
}) })
@@ -1510,7 +1510,7 @@ describe('Uploads', () => {
const thumbnail = page.locator('#field-withAdminThumbnail div.thumbnail > img') const thumbnail = page.locator('#field-withAdminThumbnail div.thumbnail > img')
await expect(thumbnail).toHaveAttribute( await expect(thumbnail).toHaveAttribute(
'src', 'src',
'https://payloadcms.com/images/universal-truth.jpg', 'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/universal-truth.jpg',
) )
}) })