Merge branch 'alpha' into temp38

This commit is contained in:
James Mikrut
2024-04-01 17:37:54 -04:00
committed by GitHub
28 changed files with 339 additions and 198 deletions

View File

@@ -2,7 +2,7 @@
import { useConfig } from '@payloadcms/ui/providers/Config'
import LinkImport from 'next/link.js'
import { useParams } from 'next/navigation'
import { useParams } from 'next/navigation.js'
import React from 'react'
const Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default

View File

@@ -1,9 +1,9 @@
import type { EditViewComponent } from 'payload/types'
import { SetStepNav } from '@payloadcms/ui/elements/StepNav'
import { notFound, redirect } from 'next/navigation.js'
import React, { Fragment } from 'react'
import type { EditViewComponent } from '../../../../../packages/payload/types.js'
export const CustomEditView: EditViewComponent = ({ initPageResult }) => {
if (!initPageResult) {
notFound()

View File

@@ -37,7 +37,6 @@ import {
} from './shared.js'
import {
customIdCollectionId,
customIdCollectionSlug,
customViews2CollectionSlug,
geoCollectionSlug,
globalSlug,

View File

@@ -21,6 +21,7 @@ export const customEditLabel = 'Custom Edit Label'
export const customTabLabel = 'Custom Tab Label'
export const customTabViewPath = '/custom-tab-component'
export const customTabViewTitle = 'Custom View With Tab Component'
export const customTabLabelViewTitle = 'Custom Tab Label View'

View File

@@ -12,5 +12,3 @@ export const AdminThumbnailCol: CollectionConfig = {
},
fields: [],
}
export default AdminThumbnailCol

View File

@@ -7,7 +7,7 @@ import { devUser } from '../credentials.js'
import removeFiles from '../helpers/removeFiles.js'
import { Uploads1 } from './collections/Upload1/index.js'
import Uploads2 from './collections/Upload2/index.js'
import AdminThumbnailCol from './collections/admin-thumbnail/index.js'
import { AdminThumbnailCol } from './collections/admin-thumbnail/index.js'
import {
audioSlug,
enlargeSlug,

View File

@@ -12,10 +12,8 @@ import { initPageConsoleErrorCatch, saveDocAndAssert } from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import { RESTClient } from '../helpers/rest.js'
import { adminThumbnailSrc } from './collections/admin-thumbnail/RegisterThumbnailFn.js'
import config from './config.js'
import { adminThumbnailSlug, audioSlug, mediaSlug, relationSlug } from './shared.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
@@ -73,13 +71,18 @@ describe('uploads', () => {
test('should see upload filename in relation list', async () => {
await page.goto(relationURL.list)
await wait(110)
const field = page.locator('.cell-image')
await expect(field).toContainText('image.png')
})
test('should see upload versioned filename in relation list', async () => {
await page.goto(relationURL.list)
const field = page.locator('.cell-versionedImage')
await expect(field).toContainText('image')
})
test('should show upload filename in upload collection list', async () => {
await page.goto(mediaURL.list)
const audioUpload = page.locator('tr.row-1 .cell-filename')
@@ -91,7 +94,6 @@ describe('uploads', () => {
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')
@@ -169,12 +171,11 @@ describe('uploads', () => {
test('should show draft uploads in the relation list', async () => {
await page.goto(relationURL.list)
// from the list edit the first document
await page.locator('.row-1 a').click()
// edit the versioned image
await page.locator('.field-versionedImage .icon--edit').click()
await page.locator('.field-type:nth-of-type(2) .icon--edit').click()
// fill the title with 'draft'
await page.locator('#field-title').fill('draft')
@@ -186,7 +187,7 @@ describe('uploads', () => {
await page.locator('.doc-drawer__header-close').click()
// remove the selected versioned image
await page.locator('.field-versionedImage .icon--x').click()
await page.locator('.field-type:nth-of-type(2) .icon--x').click()
// choose from existing
await page.locator('.list-drawer__toggler').click()
@@ -196,20 +197,12 @@ describe('uploads', () => {
test('should restrict mimetype based on filterOptions', async () => {
await page.goto(audioURL.edit(audioDoc.id))
await wait(200)
// remove the selection and open the list drawer
await page.locator('.file-details__remove').click()
await page.locator('.upload__toggler.list-drawer__toggler').click()
const listDrawer = page.locator('[id^=list-drawer_1_]')
await expect(listDrawer).toBeVisible()
await wait(200) // list is loading
// ensure the only card is the audio file
const rows = listDrawer.locator('table tbody tr')
expect(await rows.count()).toEqual(1)
const filename = rows.locator('.cell-filename')
await expect(filename).toHaveText('audio.mp3')
// upload an image and try to select it
await listDrawer.locator('button.list-drawer__create-new-button.doc-drawer__toggler').click()
@@ -218,30 +211,29 @@ describe('uploads', () => {
.locator('[id^=doc-drawer_media_2_] .file-field__upload input[type="file"]')
.setInputFiles(path.resolve(dirname, './image.png'))
await page.locator('[id^=doc-drawer_media_2_] button#action-save').click()
await wait(200)
await expect(page.locator('.Toastify')).toContainText('successfully')
// save the document and expect an error
await page.locator('button#action-save').click()
await wait(200)
await expect(page.locator('.Toastify')).toContainText('The following field is invalid: audio')
await expect(page.locator('.Toastify')).toContainText('Please correct invalid fields.')
})
test('Should execute adminThumbnail and provide thumbnail when set', async () => {
await page.goto(adminThumbnailURL.list)
await wait(200)
await page.waitForURL(adminThumbnailURL.list)
// Ensure sure false or null shows generic file svg
const genericUploadImage = page.locator('tr.row-1 .thumbnail svg')
const genericUploadImage = page.locator('tr.row-1 .thumbnail img')
await expect(genericUploadImage).toBeVisible()
// Ensure adminThumbnail fn returns correct value based on audio/mp3 mime
const audioUploadImage = page.locator('tr.row-2 .thumbnail img')
expect(await audioUploadImage.getAttribute('src')).toContain(adminThumbnailSrc)
const audioUploadImage = page.locator('tr.row-2 .thumbnail svg')
await expect(audioUploadImage).toBeVisible()
})
test('Should detect correct mimeType', async () => {
await page.goto(mediaURL.create)
await page.waitForURL(mediaURL.create)
await page.setInputFiles('input[type="file"]', path.resolve(dirname, './image.png'))
await saveDocAndAssert(page)
@@ -275,12 +267,14 @@ describe('uploads', () => {
const createFocalCrop = async (page: Page, position: 'bottom-right' | 'top-left') => {
const { dragX, dragY, focalX, focalY } = positions[position]
await page.goto(mediaURL.create)
await page.waitForURL(mediaURL.create)
// select and upload file
const fileChooserPromise = page.waitForEvent('filechooser')
await page.getByText('Select a file').click()
const fileChooser = await fileChooserPromise
await wait(1000)
await fileChooser.setFiles(path.join(dirname, 'test-image.jpg'))
await page.locator('.file-field__edit').click()
// set crop
@@ -300,18 +294,18 @@ describe('uploads', () => {
await expect(page.locator('.edit-upload__input input[name="X %"]')).toHaveValue(`${focalX}`)
await expect(page.locator('.edit-upload__input input[name="Y %"]')).toHaveValue(`${focalY}`)
// apply crop
await page.locator('button:has-text("Apply Changes")').click()
await page.waitForSelector('button#action-save')
await page.locator('button#action-save').click()
await expect(page.locator('.Toastify')).toContainText('successfully')
await wait(1000) // Wait for the save
}
await createFocalCrop(page, 'bottom-right') // green square
await wait(1000) // wait for edit view navigation (saving images)
// get the ID of the doc
const greenSquareMediaID = page.url().split('/').pop()
const greenSquareMediaID = page.url().split('/').pop() // get the ID of the doc
await createFocalCrop(page, 'top-left') // red square
await wait(1000) // wait for edit view navigation (saving images)
const redSquareMediaID = page.url().split('/').pop()
const redSquareMediaID = page.url().split('/').pop() // get the ID of the doc
const { doc: greenDoc } = await client.findByID({
id: greenSquareMediaID,