Files
Stirling-PDF/frontend/src/core/tests/stubbed/pdf-text-search.spec.ts
T
2026-04-27 11:35:50 +01:00

57 lines
1.9 KiB
TypeScript

import { test, expect } from "@app/tests/helpers/stub-test-base";
import path from "path";
const SAMPLE_PDF = path.join(__dirname, "../test-fixtures/sample.pdf");
/**
* The reader/viewer exposes an in-PDF text search via CustomSearchLayer.
* No prior coverage; even a smoke assertion that the search input renders
* and accepts a query catches the most damaging regression (search bar
* disappears when reader refactors).
*/
test.describe("Reader — in-document text search", () => {
test("search input is reachable from the reader and accepts a query", async ({
page,
}) => {
await page.goto("/read");
await page.waitForLoadState("domcontentloaded");
// Upload a PDF first so the reader has content
await page.getByTestId("files-button").click();
await page.waitForSelector(".mantine-Modal-overlay", {
state: "visible",
timeout: 5_000,
});
await page.locator('[data-testid="file-input"]').setInputFiles(SAMPLE_PDF);
await page.waitForSelector(".mantine-Modal-overlay", {
state: "hidden",
timeout: 10_000,
});
// The viewer toolbar exposes a search button or the search input directly.
const searchTrigger = page
.getByRole("button", { name: /search|find/i })
.or(page.getByPlaceholder(/search|find in document/i))
.first();
if (
!(await searchTrigger.isVisible({ timeout: 5_000 }).catch(() => false))
) {
test.skip(true, "Reader toolbar search not visible on this build");
return;
}
// If it's a button, click it to open the input; if it's an input
// already, fill directly.
const tag = await searchTrigger.evaluate((el) => el.tagName);
if (tag === "BUTTON") {
await searchTrigger.click();
}
const input = page.getByPlaceholder(/search|find/i).first();
await expect(input).toBeVisible({ timeout: 5_000 });
await input.fill("page");
await expect(input).toHaveValue("page");
});
});