test: add plugin-cloud-storage e2e
This commit is contained in:
1
.github/workflows/main.yml
vendored
1
.github/workflows/main.yml
vendored
@@ -246,6 +246,7 @@ jobs:
|
|||||||
- fields__collections__Lexical
|
- fields__collections__Lexical
|
||||||
- live-preview
|
- live-preview
|
||||||
- localization
|
- localization
|
||||||
|
- plugin-cloud-storage
|
||||||
- plugin-form-builder
|
- plugin-form-builder
|
||||||
- plugin-nested-docs
|
- plugin-nested-docs
|
||||||
- plugin-seo
|
- plugin-seo
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { azureBlobStorageAdapter } from '@payloadcms/plugin-cloud-storage/azure'
|
|||||||
import { gcsAdapter } from '@payloadcms/plugin-cloud-storage/gcs'
|
import { gcsAdapter } from '@payloadcms/plugin-cloud-storage/gcs'
|
||||||
import { s3Adapter } from '@payloadcms/plugin-cloud-storage/s3'
|
import { s3Adapter } from '@payloadcms/plugin-cloud-storage/s3'
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
|
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
|
||||||
@@ -14,13 +15,15 @@ import { MediaWithPrefix } from './collections/MediaWithPrefix.js'
|
|||||||
import { Users } from './collections/Users.js'
|
import { Users } from './collections/Users.js'
|
||||||
import { mediaSlug, mediaWithPrefixSlug, prefix } from './shared.js'
|
import { mediaSlug, mediaWithPrefixSlug, prefix } from './shared.js'
|
||||||
import { createTestBucket } from './utils.js'
|
import { createTestBucket } from './utils.js'
|
||||||
|
const filename = fileURLToPath(import.meta.url)
|
||||||
|
const dirname = path.dirname(filename)
|
||||||
|
|
||||||
let adapter: Adapter
|
let adapter: Adapter
|
||||||
let uploadOptions
|
let uploadOptions
|
||||||
|
|
||||||
// Load config to work with emulated services
|
// Load config to work with emulated services
|
||||||
dotenv.config({
|
dotenv.config({
|
||||||
path: path.resolve(process.cwd(), './test/plugin-cloud-storage/.env.emulated'),
|
path: path.resolve(dirname, './.env.emulated'),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'azure') {
|
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'azure') {
|
||||||
|
|||||||
54
test/plugin-cloud-storage/e2e.spec.ts
Normal file
54
test/plugin-cloud-storage/e2e.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import type { Page } from '@playwright/test'
|
||||||
|
|
||||||
|
import { expect, test } from '@playwright/test'
|
||||||
|
import * as path from 'path'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
|
import { saveDocAndAssert } from '../helpers.js'
|
||||||
|
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
|
||||||
|
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
|
||||||
|
import { mediaSlug } from './shared.js'
|
||||||
|
|
||||||
|
const filename = fileURLToPath(import.meta.url)
|
||||||
|
const dirname = path.dirname(filename)
|
||||||
|
|
||||||
|
test.describe('Admin Panel', () => {
|
||||||
|
let page: Page
|
||||||
|
let mediaURL: AdminUrlUtil
|
||||||
|
|
||||||
|
test.beforeAll(async ({ browser }) => {
|
||||||
|
const { serverURL } = await initPayloadE2ENoConfig({ dirname })
|
||||||
|
mediaURL = new AdminUrlUtil(serverURL, mediaSlug)
|
||||||
|
|
||||||
|
const context = await browser.newContext()
|
||||||
|
page = await context.newPage()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('should create file upload', async () => {
|
||||||
|
await page.goto(mediaURL.create)
|
||||||
|
await page.setInputFiles('input[type="file"]', path.resolve(dirname, './image.png'))
|
||||||
|
|
||||||
|
const filename = page.locator('.file-field__filename')
|
||||||
|
|
||||||
|
await expect(filename).toHaveValue('image.png')
|
||||||
|
|
||||||
|
await saveDocAndAssert(page)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('should update an existing upload', async () => {
|
||||||
|
await page.goto(mediaURL.create)
|
||||||
|
await page.setInputFiles('input[type="file"]', path.resolve(dirname, './image.png'))
|
||||||
|
|
||||||
|
const filename = page.locator('.file-field__filename')
|
||||||
|
|
||||||
|
await expect(filename).toHaveValue('image.png')
|
||||||
|
|
||||||
|
await saveDocAndAssert(page)
|
||||||
|
|
||||||
|
// Update alt text
|
||||||
|
await page.locator('#field-alt').fill('updated text')
|
||||||
|
|
||||||
|
// Save again
|
||||||
|
await saveDocAndAssert(page)
|
||||||
|
})
|
||||||
|
})
|
||||||
BIN
test/plugin-cloud-storage/image.png
Normal file
BIN
test/plugin-cloud-storage/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
Reference in New Issue
Block a user