mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
feat: upload source by ctrl+v and dropzone
This commit is contained in:
+33
-2
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user