mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
fix(core): svg blob syncing issue (#4886)
This commit is contained in:
35
tests/kit/utils/drop-file.ts
Normal file
35
tests/kit/utils/drop-file.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { Page } from '@playwright/test';
|
||||
|
||||
export const dropFile = async (
|
||||
page: Page,
|
||||
selector: string,
|
||||
fileContent: Buffer | string,
|
||||
fileName: string,
|
||||
fileType = ''
|
||||
) => {
|
||||
const buffer =
|
||||
typeof fileContent === 'string'
|
||||
? Buffer.from(fileContent, 'utf-8')
|
||||
: fileContent;
|
||||
|
||||
const dataTransfer = await page.evaluateHandle(
|
||||
async ({ bufferData, localFileName, localFileType }) => {
|
||||
const dt = new DataTransfer();
|
||||
|
||||
const blobData = await fetch(bufferData).then(res => res.blob());
|
||||
|
||||
const file = new File([blobData], localFileName, { type: localFileType });
|
||||
dt.items.add(file);
|
||||
return dt;
|
||||
},
|
||||
{
|
||||
bufferData: `data:application/octet-stream;base64,${buffer.toString(
|
||||
'base64'
|
||||
)}`,
|
||||
localFileName: fileName,
|
||||
localFileType: fileType,
|
||||
}
|
||||
);
|
||||
|
||||
await page.dispatchEvent(selector, 'drop', { dataTransfer });
|
||||
};
|
||||
Reference in New Issue
Block a user