feat: upload source by ctrl+v and dropzone

This commit is contained in:
2026-10-04 22:30:21 +05:00
parent 91150a14bf
commit 864f9cdc9f
10 changed files with 137 additions and 19 deletions
+33 -2
View File
@@ -76,8 +76,10 @@ export async function renderText(page: Page, value: string): Promise<void> {
}
export async function uploadImage(page: Page, file: SourceFile): Promise<void> {
const input = page.locator('input[type="file"]');
await expect(input).toHaveCount(1);
// На странице может быть два input[type=file]: дропзона + кнопка Open image;
// канонический — первый (кнопка в шапке панели).
const input = page.locator('input[type="file"]').first();
await expect(input).toBeAttached();
await input.setInputFiles({
name: file.name,
mimeType: file.mimeType,
@@ -85,6 +87,35 @@ export async function uploadImage(page: Page, file: SourceFile): Promise<void> {
});
}
export async function uploadViaDrop(
page: Page,
file: SourceFile,
): Promise<void> {
const dataTransfer = await page.evaluateHandle(
({
bytes,
name,
mimeType,
}: {
bytes: number[];
name: string;
mimeType: string;
}) => {
const dt = new DataTransfer();
dt.items.add(new File([new Uint8Array(bytes)], name, { type: mimeType }));
return dt;
},
{
bytes: Array.from(file.buffer),
name: file.name,
mimeType: file.mimeType,
},
);
await page
.getByRole("button", { name: /drop a png/i })
.dispatchEvent("drop", { dataTransfer });
}
export async function downloadResultFile(page: Page): Promise<Download> {
const button = page.getByRole("button", { name: "Download result" });
await expect(button).toBeVisible();