import path from "node:path"; import { expect, test, waitForProcessing } from "./helpers"; // --------------------------------------------------------------------------- // Helper: resolve fixture image paths // --------------------------------------------------------------------------- function getFixturePath(name: string): string { return path.join(process.cwd(), "tests", "fixtures", name); } const FIXTURE_JPG = getFixturePath("test-100x100.jpg"); const FIXTURE_PNG = getFixturePath("test-200x150.png"); const FIXTURE_WEBP = getFixturePath("test-50x50.webp"); const FIXTURE_HEIC = getFixturePath("test-200x150.heic"); const FIXTURE_PORTRAIT_JPG = getFixturePath("test-portrait.jpg"); // --------------------------------------------------------------------------- // Multi-file upload tests // --------------------------------------------------------------------------- test.describe("Multi-file upload", () => { test("upload 2 files via file chooser and both appear in Files section", async ({ loggedInPage: page, }) => { await page.goto("/resize"); const fileChooserPromise = page.waitForEvent("filechooser"); const dropzone = page.locator("[class*='border-dashed']").first(); await dropzone.click(); const fileChooser = await fileChooserPromise; await fileChooser.setFiles([FIXTURE_JPG, FIXTURE_PNG]); await page.waitForTimeout(1000); // Both files should be registered await expect(page.getByText("Files (2)")).toBeVisible(); }); test("upload 3+ files and all are listed with filenames and sizes", async ({ loggedInPage: page, }) => { await page.goto("/resize"); const fileChooserPromise = page.waitForEvent("filechooser"); const dropzone = page.locator("[class*='border-dashed']").first(); await dropzone.click(); const fileChooser = await fileChooserPromise; await fileChooser.setFiles([FIXTURE_JPG, FIXTURE_PNG, FIXTURE_WEBP]); await page.waitForTimeout(1000); // All 3 files should be registered await expect(page.getByText("Files (3)")).toBeVisible(); // The currently selected file info should show a filename and size await expect(page.getByText(/test-/i).first()).toBeVisible(); await expect(page.getByText(/KB|B/i).first()).toBeVisible(); }); test("'+ Add more' adds files to existing set", async ({ loggedInPage: page }) => { await page.goto("/resize"); // Upload initial file const fileChooserPromise = page.waitForEvent("filechooser"); const dropzone = page.locator("[class*='border-dashed']").first(); await dropzone.click(); const fileChooser = await fileChooserPromise; await fileChooser.setFiles([FIXTURE_JPG]); await page.waitForTimeout(500); await expect(page.getByText("Files (1)")).toBeVisible(); // Click "+ Add more" which triggers a programmatic file input const addMorePromise = page.waitForEvent("filechooser"); await page.getByText("+ Add more").click(); const addMoreChooser = await addMorePromise; await addMoreChooser.setFiles([FIXTURE_PNG, FIXTURE_WEBP]); await page.waitForTimeout(500); // Now should show 3 files await expect(page.getByText("Files (3)")).toBeVisible(); }); test("'Clear all' removes all files and returns to dropzone", async ({ loggedInPage: page }) => { await page.goto("/resize"); // Upload files const fileChooserPromise = page.waitForEvent("filechooser"); const dropzone = page.locator("[class*='border-dashed']").first(); await dropzone.click(); const fileChooser = await fileChooserPromise; await fileChooser.setFiles([FIXTURE_JPG, FIXTURE_PNG]); await page.waitForTimeout(500); await expect(page.getByText("Files (2)")).toBeVisible(); // Clear all files await page.getByText("Clear all").click(); // Dropzone should reappear await expect(page.getByText("Upload from computer")).toBeVisible(); }); test("ThumbnailStrip shows at bottom with clickable thumbnails", async ({ loggedInPage: page, }) => { await page.goto("/resize"); const fileChooserPromise = page.waitForEvent("filechooser"); const dropzone = page.locator("[class*='border-dashed']").first(); await dropzone.click(); const fileChooser = await fileChooserPromise; await fileChooser.setFiles([FIXTURE_JPG, FIXTURE_PNG, FIXTURE_WEBP]); await page.waitForTimeout(1000); // ThumbnailStrip renders when entries.length > 1 // Each thumbnail is a