mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
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.
This commit is contained in:
38
apps/app/tests/utils/files/drag-drop.ts
Normal file
38
apps/app/tests/utils/files/drag-drop.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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 }
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user