chore: creates uploads e2e testing suite
This commit is contained in:
@@ -89,10 +89,20 @@ export default buildConfig({
|
||||
|
||||
if (fs.existsSync(uploadsDir)) fs.readdirSync(uploadsDir).forEach((f) => fs.rmSync(`${uploadsDir}/${f}`));
|
||||
|
||||
const filePath = path.resolve(__dirname, './collections/Upload/payload.jpg');
|
||||
const file = await getFileByPath(filePath);
|
||||
const pngPath = path.resolve(__dirname, './uploads/payload.png');
|
||||
const pngFile = await getFileByPath(pngPath);
|
||||
const createdPNGDoc = await payload.create({ collection: 'uploads', data: {}, file: pngFile });
|
||||
|
||||
const createdUploadDoc = await payload.create({ collection: 'uploads', data: uploadsDoc, file });
|
||||
const jpgPath = path.resolve(__dirname, './collections/Upload/payload.jpg');
|
||||
const jpgFile = await getFileByPath(jpgPath);
|
||||
const createdJPGDoc = await payload.create({
|
||||
collection: 'uploads',
|
||||
data: {
|
||||
...uploadsDoc,
|
||||
media: createdPNGDoc.id,
|
||||
},
|
||||
file: jpgFile
|
||||
});
|
||||
|
||||
const richTextDocWithRelId = JSON.parse(JSON.stringify(richTextDoc).replace('{{ARRAY_DOC_ID}}', createdArrayDoc.id));
|
||||
const richTextDocWithRelationship = { ...richTextDocWithRelId };
|
||||
@@ -101,8 +111,8 @@ export default buildConfig({
|
||||
richTextDocWithRelationship.richText[richTextRelationshipIndex].value = { id: createdTextDoc.id };
|
||||
|
||||
const richTextUploadIndex = richTextDocWithRelationship.richText.findIndex(({ type }) => type === 'upload');
|
||||
richTextDocWithRelationship.richText[richTextUploadIndex].value = { id: createdUploadDoc.id };
|
||||
richTextDocWithRelationship.richTextReadOnly[richTextUploadIndex].value = { id: createdUploadDoc.id };
|
||||
richTextDocWithRelationship.richText[richTextUploadIndex].value = { id: createdJPGDoc.id };
|
||||
richTextDocWithRelationship.richTextReadOnly[richTextUploadIndex].value = { id: createdJPGDoc.id };
|
||||
|
||||
await payload.create({ collection: 'rich-text-fields', data: richTextBulletsDoc });
|
||||
await payload.create({ collection: 'rich-text-fields', data: richTextDocWithRelationship });
|
||||
|
||||
@@ -10,6 +10,7 @@ import { tabsSlug } from './collections/Tabs';
|
||||
import { collapsibleFieldsSlug } from './collections/Collapsible';
|
||||
import wait from '../../src/utilities/wait';
|
||||
import { jsonDoc } from './collections/JSON';
|
||||
import path from 'path';
|
||||
|
||||
const { beforeAll, describe } = test;
|
||||
|
||||
@@ -494,4 +495,48 @@ describe('fields', () => {
|
||||
await expect(page.locator('.Toastify')).toContainText('successfully');
|
||||
});
|
||||
});
|
||||
|
||||
describe('upload', () => {
|
||||
let url: AdminUrlUtil;
|
||||
beforeAll(() => {
|
||||
url = new AdminUrlUtil(serverURL, 'uploads');
|
||||
});
|
||||
|
||||
test('should upload files', async () => {
|
||||
await page.goto(url.create);
|
||||
|
||||
// create a jpg upload
|
||||
await page.locator('.file-field__upload input[type="file"]').setInputFiles(path.resolve(__dirname, './collections/Upload/payload.jpg'));
|
||||
await expect(page.locator('.file-field .file-field__filename')).toContainText('payload.jpg');
|
||||
await page.locator('#action-save').click();
|
||||
await wait(200);
|
||||
await expect(page.locator('.Toastify')).toContainText('successfully');
|
||||
});
|
||||
|
||||
// test that the image renders
|
||||
test('should render uploaded image', async () => {
|
||||
await expect(page.locator('.file-field .file-details img')).toHaveAttribute('src', '/uploads/payload-1.jpg');
|
||||
});
|
||||
|
||||
test('should upload using the document drawer', async () => {
|
||||
// Open the media drawer and create a png upload
|
||||
await page.locator('.field-type.upload .upload__toggler.doc-drawer__toggler').click();
|
||||
await page.locator('[id^=doc-drawer_uploads_1_] .file-field__upload input[type="file"]').setInputFiles(path.resolve(__dirname, './uploads/payload.png'));
|
||||
await page.locator('[id^=doc-drawer_uploads_1_] #action-save').click();
|
||||
await wait(200);
|
||||
await expect(page.locator('.Toastify')).toContainText('successfully');
|
||||
|
||||
// Assert that the media field has the png upload
|
||||
await expect(page.locator('.field-type.upload .file-details .file-meta__url a')).toHaveAttribute('href', '/uploads/payload-1.png');
|
||||
await expect(page.locator('.field-type.upload .file-details .file-meta__url a')).toContainText('payload-1.png');
|
||||
await expect(page.locator('.field-type.upload .file-details img')).toHaveAttribute('src', '/uploads/payload-1.png');
|
||||
await page.locator('#action-save').click();
|
||||
await wait(200);
|
||||
await expect(page.locator('.Toastify')).toContainText('successfully');
|
||||
});
|
||||
|
||||
test('should clear selected upload', async () => {
|
||||
await page.locator('.field-type.upload .file-details__remove').click();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 0 B After Width: | Height: | Size: 341 KiB |
Reference in New Issue
Block a user