Files
automaker/apps/app/tests/utils/files/drag-drop.ts
Kacper 0b1123e3ce refactor: restructure test utilities and enhance context view tests
- Refactored test utilities by consolidating and organizing helper functions into dedicated modules for better maintainability and clarity.
- Introduced new utility functions for interactions, waiting, and element retrieval, improving the readability of test cases.
- Updated context view tests to utilize the new utility functions, enhancing test reliability and reducing code duplication.
- Removed deprecated utility functions and ensured all tests are aligned with the new structure.
2025-12-15 02:40:09 +01:00

39 lines
1011 B
TypeScript

import { Page } from "@playwright/test";
/**
* Simulate drag and drop of a file onto an element
*/
export async function simulateFileDrop(
page: Page,
targetSelector: string,
fileName: string,
fileContent: string,
mimeType: string = "text/plain"
): Promise<void> {
await page.evaluate(
({ selector, content, name, mime }) => {
const target = document.querySelector(selector);
if (!target) throw new Error(`Element not found: ${selector}`);
const file = new File([content], name, { type: mime });
const dataTransfer = new DataTransfer();
dataTransfer.items.add(file);
// Dispatch drag events
target.dispatchEvent(
new DragEvent("dragover", {
dataTransfer,
bubbles: true,
})
);
target.dispatchEvent(
new DragEvent("drop", {
dataTransfer,
bubbles: true,
})
);
},
{ selector: targetSelector, content: fileContent, name: fileName, mime: mimeType }
);
}