2026-04-05 23:04:09 +08:00
|
|
|
import path from "node:path";
|
2026-06-28 18:57:53 +08:00
|
|
|
import type { Page } from "@playwright/test";
|
2026-04-05 23:04:09 +08:00
|
|
|
import { expect, test, waitForProcessing } from "./helpers";
|
|
|
|
|
|
2026-06-20 05:51:17 +08:00
|
|
|
const PDF_FIXTURE = path.join(
|
|
|
|
|
process.cwd(),
|
|
|
|
|
"tests",
|
|
|
|
|
"fixtures",
|
|
|
|
|
"document",
|
|
|
|
|
"valid",
|
|
|
|
|
"test-3page.pdf",
|
|
|
|
|
);
|
2026-04-05 23:04:09 +08:00
|
|
|
|
2026-06-28 18:57:53 +08:00
|
|
|
// The dropzone opens a native file chooser on click rather than exposing a
|
|
|
|
|
// persistent <input type="file">, so upload through the chooser event.
|
|
|
|
|
async function uploadPdf(page: Page): Promise<void> {
|
|
|
|
|
const fileChooserPromise = page.waitForEvent("filechooser");
|
|
|
|
|
await page
|
|
|
|
|
.getByRole("button", { name: /upload from computer/i })
|
|
|
|
|
.first()
|
|
|
|
|
.click();
|
|
|
|
|
const fileChooser = await fileChooserPromise;
|
|
|
|
|
await fileChooser.setFiles(PDF_FIXTURE);
|
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 23:04:09 +08:00
|
|
|
test.describe("PDF to Image tool", () => {
|
2026-04-13 13:43:07 +08:00
|
|
|
test("shows page thumbnails after uploading a PDF", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/pdf/pdf-to-image");
|
2026-06-28 18:57:53 +08:00
|
|
|
await uploadPdf(page);
|
2026-04-05 23:04:09 +08:00
|
|
|
|
2026-04-13 13:43:07 +08:00
|
|
|
// Wait for page count to appear
|
|
|
|
|
await expect(page.locator(".bg-muted").getByText("3 pages")).toBeVisible({ timeout: 15_000 });
|
2026-04-05 23:04:09 +08:00
|
|
|
|
2026-04-13 13:43:07 +08:00
|
|
|
// Wait for thumbnails to appear in the results panel
|
|
|
|
|
await expect(page.locator("text=3 of 3 pages selected")).toBeVisible({ timeout: 15_000 });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("converts a PDF page to an image and shows results", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/pdf/pdf-to-image");
|
2026-06-28 18:57:53 +08:00
|
|
|
await uploadPdf(page);
|
2026-04-13 13:43:07 +08:00
|
|
|
await expect(page.locator(".bg-muted").getByText("3 pages")).toBeVisible({ timeout: 15_000 });
|
|
|
|
|
|
|
|
|
|
// Set pages to just page 1
|
2026-04-05 23:04:09 +08:00
|
|
|
await page.fill("#pdf-pages", "1");
|
|
|
|
|
|
|
|
|
|
// Click convert
|
|
|
|
|
await page.getByTestId("pdf-to-image-submit").click();
|
|
|
|
|
|
|
|
|
|
// Wait for processing
|
|
|
|
|
await waitForProcessing(page);
|
|
|
|
|
|
|
|
|
|
// Verify download link appears
|
2026-04-13 13:43:07 +08:00
|
|
|
await expect(page.getByTestId("pdf-to-image-download")).toBeVisible({ timeout: 15_000 });
|
|
|
|
|
await expect(page.getByTestId("pdf-to-image-download")).toContainText("Download All");
|
|
|
|
|
|
|
|
|
|
// Verify results panel shows converted page
|
|
|
|
|
await expect(page.locator("text=1 page converted")).toBeVisible();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("can select and deselect pages via thumbnails", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/pdf/pdf-to-image");
|
2026-06-28 18:57:53 +08:00
|
|
|
await uploadPdf(page);
|
2026-04-13 13:43:07 +08:00
|
|
|
await expect(page.locator("text=3 of 3 pages selected")).toBeVisible({ timeout: 15_000 });
|
|
|
|
|
|
|
|
|
|
// Click "Deselect All"
|
|
|
|
|
await page.locator("text=Deselect All").click();
|
|
|
|
|
await expect(page.locator("text=0 of 3 pages selected")).toBeVisible();
|
|
|
|
|
|
|
|
|
|
// Click "Select All"
|
|
|
|
|
await page.locator("text=Select All").click();
|
|
|
|
|
await expect(page.locator("text=3 of 3 pages selected")).toBeVisible();
|
2026-04-05 23:04:09 +08:00
|
|
|
});
|
|
|
|
|
});
|
2026-07-24 18:53:19 +08:00
|
|
|
|
|
|
|
|
test.describe("PDF conversion preset pages", () => {
|
|
|
|
|
for (const toolId of ["pdf-to-png", "pdf-to-jpg"]) {
|
|
|
|
|
test(`${toolId} shows the ZIP download after synchronous conversion`, async ({
|
|
|
|
|
loggedInPage: page,
|
|
|
|
|
}) => {
|
|
|
|
|
await page.goto(`/pdf/${toolId}`);
|
|
|
|
|
await uploadPdf(page);
|
|
|
|
|
|
|
|
|
|
await page.getByTestId("preset-submit").click();
|
|
|
|
|
|
|
|
|
|
const download = page.getByTestId("preset-download");
|
|
|
|
|
await expect(download).toBeVisible({ timeout: 15_000 });
|
|
|
|
|
await expect(download).toHaveAttribute("href", /\/api\/v1\/download\/[^/]+\/pdf-pages\.zip$/);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|