test: fix tests that rely on remote urls (#13073)
This commit is contained in:
@@ -18,6 +18,7 @@ export const UploadCollection: CollectionConfig = {
|
||||
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',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -55,7 +55,9 @@ describe('Lexical Fully Featured', () => {
|
||||
await lexical.drawer.getByText('Paste URL').click()
|
||||
await lexical.drawer
|
||||
.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.save('drawer')
|
||||
await expect(lexical.decorator).toHaveCount(3)
|
||||
|
||||
@@ -11,7 +11,8 @@ export const AdminThumbnailFunction: CollectionConfig = {
|
||||
slug: adminThumbnailFunctionSlug,
|
||||
upload: {
|
||||
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: [],
|
||||
}
|
||||
|
||||
@@ -6,14 +6,18 @@ export const UploadControl = () => {
|
||||
const { setUploadControlFile, setUploadControlFileUrl } = useUploadControls()
|
||||
|
||||
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 file = new File([blob], 'universal-truth.jpg', { type: 'image/jpeg' })
|
||||
setUploadControlFile(file)
|
||||
}, [setUploadControlFile])
|
||||
|
||||
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])
|
||||
|
||||
return (
|
||||
|
||||
@@ -583,7 +583,7 @@ describe('Uploads', () => {
|
||||
const genericUploadImage = page.locator('tr.row-1 .thumbnail img')
|
||||
await expect(genericUploadImage).toHaveAttribute(
|
||||
'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')
|
||||
await expect(thumbnail).toHaveAttribute(
|
||||
'src',
|
||||
'https://payloadcms.com/images/universal-truth.jpg',
|
||||
'https://raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/universal-truth.jpg',
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user