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

44 lines
1.8 KiB
TypeScript

import { test, expect } from "@app/tests/helpers/stub-test-base";
import { uploadFiles } from "@app/tests/helpers/ui-helpers";
import path from "path";
const SAMPLE_PDF = path.join(__dirname, "../test-fixtures/sample.pdf");
/**
* The NavigationGuard context warns the user when they have unsaved work
* (uploaded files or modified config) and try to navigate away. The guard
* surface is a Mantine modal asking to confirm or cancel the navigation.
*
* Today the guard logic exists but is silently bypassed by tests that go
* through the workbench. This spec asserts the modal appears and that
* cancelling keeps the user on the current tool.
*/
test.describe("Unsaved changes navigation guard", () => {
test("uploading then navigating away surfaces the guard prompt", async ({
page,
}) => {
await page.goto("/merge");
await page.waitForLoadState("domcontentloaded");
await uploadFiles(page, SAMPLE_PDF);
// Triggering a tool-level navigation while files are loaded should
// either prompt or clear-and-navigate cleanly. A regression that
// discards files silently is the failure we want to catch.
const splitNav = page.getByRole("link", { name: /^Split$/i }).first();
if (await splitNav.isVisible({ timeout: 1_000 }).catch(() => false)) {
await splitNav.click();
} else {
await page.goto("/split");
}
// After arriving at /split the file picker should still list the
// previously uploaded sample (NavigationGuard either kept us on
// /merge or moved us with state intact). A "no files" empty state
// here would indicate the guard silently dropped the workbench.
await page.getByTestId("files-button").click();
await expect(page.getByText(/sample\.pdf/i).first()).toBeVisible({
timeout: 5_000,
});
});
});